-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
table output module for NetworkPolicy
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
from omg.utils.dget import dget | ||
|
||
|
||
def _col_pod_selector(res): | ||
selectors = [] | ||
# matchExpressions | ||
me = dget(res, ["res", "spec", "podSelector", "matchExpressions"], []) | ||
for exp in me: | ||
selectors.append( | ||
"{} {} ({})".format( | ||
dget(exp, ["key"]), | ||
dget(exp, ["operator"]).lower(), | ||
",".join(dget(exp, ["values"], [])) | ||
) | ||
) | ||
# matchLabels | ||
ml = dget(res, ["res", "spec", "podSelector", "matchLabels"], {}) | ||
for k, v in ml.items(): | ||
selectors.append("{}={}".format(k, v)) | ||
|
||
if selectors: | ||
return ",".join(selectors) | ||
else: | ||
return "<none>" | ||
|
||
|
||
# Default columns (without -o wide) | ||
# NAME and AGE cols, if present, with None value, | ||
# will be handled by build_table function that will | ||
# fill them with the common name/age column functions | ||
DEFAULT_COLUMNS = { | ||
"NAME": None, | ||
"POD-SELECTOR": _col_pod_selector, | ||
"AGE": None | ||
} | ||
|
||
# Wide columns (with -o wide) | ||
# In addition to the default columns | ||
WIDE_COLUMNS = { | ||
} |