Skip to content

Commit

Permalink
Merge pull request #620 from cvaroqui/b2.1
Browse files Browse the repository at this point in the history
collector tag commandset
  • Loading branch information
cvaroqui committed Jun 9, 2023
2 parents bc67768 + 89c7975 commit 35969d0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 44 deletions.
34 changes: 21 additions & 13 deletions opensvc/commands/node/parser.py
Expand Up @@ -290,13 +290,17 @@
":cmd:`om node pushasset --sync` before a compliance run makes sure "
"the pushed data has hit the collector database before the "
"rulesets are contextualized."),
"tag": Option(
"--tag", default=None,
action="store", dest="tag",
"tag_name": Option(
"--name", default=None,
action="store", dest="name",
help="The tag name, as shown by :cmd:`om node collector list tags`."),
"tag_data": Option(
"--data", default=None,
action="store", dest="data",
help="The data stored with the tag. Typed tags, like <name>::<type> expect a particular data structure."),
"tag_attach_data": Option(
"--tag-attach-data", default=None,
action="store", dest="tag_attach_data",
"--attach-data", default=None,
action="store", dest="attach_data",
help="The data stored with the tag attachment. Typed tags, like <name>::<type> expect a particular data structure."),
"target": Option(
"--target", default=None, action="store", dest="target",
Expand Down Expand Up @@ -985,32 +989,36 @@
"each node ip, complete with network information from the "
"IPAM database.",
},
"collector_tag": {
"collector_tag_attach": {
"msg": "Set a node tag (pointed by --tag).",
"options": [
OPT.tag,
OPT.tag_name,
OPT.tag_attach_data,
],
},
"collector_untag": {
"collector_tag_detach": {
"msg": "Unset a node tag (pointed by --tag).",
"options": [
OPT.tag,
OPT.tag_name,
],
},
"collector_show_tags": {
"collector_tag_show": {
"msg": "list all node tags",
"options": [
OPT.verbose,
],
},
"collector_list_tags": {
"collector_tag_list": {
"msg": "List all available tags. Use :opt:`--like` to filter the output.",
"options": [
OPT.like,
],
},
"collector_create_tag": {
"collector_tag_create": {
"msg": "Create a new tag with name specified by :opt:`--tag`.",
"options": [
OPT.tag,
OPT.tag_name,
OPT.tag_data,
],
},
"collector_search": {
Expand Down
45 changes: 26 additions & 19 deletions opensvc/commands/svc/parser.py
Expand Up @@ -91,10 +91,18 @@
":cmd:`push resinfo --sync` before a compliance run makes sure "
"the pushed data has hit the collector database before the "
"rulesets are contextualized."),
"tag": Option(
"--tag", default=None,
action="store", dest="tag",
"tag_name": Option(
"--name", default=None,
action="store", dest="name",
help="The tag name, as shown by :cmd:`collector list tags`."),
"tag_data": Option(
"--data", default=None,
action="store", dest="data",
help="The data stored with the tag. Typed tags, like <name>::<type> expect a particular data structure."),
"tag_attach_data": Option(
"--attach-data", default=None,
action="store", dest="attach_data",
help="The data stored with the tag attachment. Typed tags, like <name>::<type> expect a particular data structure."),
"to": Option(
"--to", default=None,
action="store", dest="to",
Expand Down Expand Up @@ -797,37 +805,36 @@
OPT.format,
],
},
"collector_tag": {
"msg": "Set a service tag (pointed by --tag).",
"collector_tag_attach": {
"msg": "Set a node tag (pointed by --tag).",
"options": [
OPT.tag,
OPT.tag_name,
OPT.tag_attach_data,
],
},
"collector_untag": {
"msg": "Unset a service tag (pointed by --tag).",
"collector_tag_detach": {
"msg": "Unset a node tag (pointed by --tag).",
"options": [
OPT.tag,
OPT.tag_name,
],
},
"collector_show_tags": {
"msg": "List all service tags.",
"collector_tag_show": {
"msg": "list all node tags",
"options": [
OPT.filter,
OPT.format,
OPT.verbose,
],
},
"collector_list_tags": {
"collector_tag_list": {
"msg": "List all available tags. Use :opt:`--like` to filter the output.",
"options": [
OPT.filter,
OPT.format,
OPT.like,
],
},
"collector_create_tag": {
"msg": "Create a new tag.",
"collector_tag_create": {
"msg": "Create a new tag with name specified by :opt:`--tag`.",
"options": [
OPT.tag,
OPT.tag_name,
OPT.tag_data,
],
},
},
Expand Down
29 changes: 18 additions & 11 deletions opensvc/core/collector/actions.py
Expand Up @@ -215,9 +215,9 @@ def collector_show_actions(self):

return d['data']

def collector_untag(self):
def collector_tag_detach(self):
opts = {}
opts['tag_name'] = self.options.tag
opts['tag_name'] = self.options.name
if self.path:
opts['svcname'] = self.path
d = self.collector.call('collector_untag', opts)
Expand All @@ -228,10 +228,10 @@ def collector_untag(self):
elif d.get("msg"):
print(d.get("msg"))

def collector_tag(self):
def collector_tag_attach(self):
opts = {}
opts['tag_name'] = self.options.tag
opts['tag_attach_data'] = self.options.tag_attach_data
opts['tag_name'] = self.options.name
opts['tag_attach_data'] = self.options.attach_data
if self.path:
opts['svcname'] = self.path
d = self.collector.call('collector_tag', opts)
Expand All @@ -242,26 +242,30 @@ def collector_tag(self):
elif d.get("msg"):
print(d.get("msg"))

def collector_create_tag(self):
def collector_tag_create(self):
opts = {}
opts['tag_name'] = self.options.tag
opts['tag_name'] = self.options.name
if opts['tag_name'] is None:
print("missing parameter: --tag", file=sys.stderr)
return 1
opts['tag_data'] = self.options.data
opts['tag_exclude'] = self.options.exclude
if self.path:
opts['svcname'] = self.path
d = self.collector.call('collector_create_tag', opts)
if d is None:
raise ex.Error("xmlrpc unknown failure")
if d['ret'] != 0:
raise ex.Error(d['msg'])
elif d.get("msg"):
print(d.get("msg"))

def collector_list_tags(self):
d = self._collector_list_tags()
def collector_tag_list(self):
d = self._collector_tag_list()
for tag in d:
print(tag)

def _collector_list_tags(self):
def _collector_tag_list(self):
opts = {'pattern': self.options.like}
if self.path:
opts['svcname'] = self.path
Expand All @@ -272,10 +276,13 @@ def _collector_list_tags(self):
raise ex.Error(d['msg'])
return d['data']

def collector_show_tags(self):
def collector_tag_show(self):
opts = {}
if self.path:
opts['svcname'] = self.path
if self.options.verbose:
opts['full'] = True

d = self.collector.call('collector_show_tags', opts)
if d is None:
raise ex.Error("xmlrpc unknown failure")
Expand Down
2 changes: 1 addition & 1 deletion opensvc/utilities/render/table/__init__.py
Expand Up @@ -141,7 +141,7 @@ def print_table_default(data):
for j, d in enumerate(data):
print("-")
for i, label in enumerate(labels):
val = '\n'.join(wrap(convert(d[i]),
val = '\n'.join(wrap(convert(d[i] or ""),
initial_indent = "",
subsequent_indent = subsequent_indent,
width=78
Expand Down

0 comments on commit 35969d0

Please sign in to comment.