Skip to content

Commit

Permalink
[resotocore][feat] Support tagging by key only (#735)
Browse files Browse the repository at this point in the history
* [feat][resotocore] Support tagging by key only
  • Loading branch information
meln1k authored Mar 28, 2022
1 parent eb3f02d commit a5263b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions resotocore/resotocore/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2435,12 +2435,13 @@ def timeout(self) -> timedelta:
class TagCommand(SendWorkerTaskCommand):
"""
```
tag update [--nowait] [tag_name new_value]
tag delete [--nowait] [tag_name]
tag update [--nowait] <tag_name> [new_value]
tag delete [--nowait] <tag_name>
```
This command can be used to update or delete a specific tag.
Tags have a name and value - both name and value are strings.
Tags have a name and value - both name and value are strings. In some cases cloud providers may
not support values in tags, and only allow names. In that case the value can be omitted.
When this command is issued, the change is done on the cloud resource via the cloud specific provider.
The change in the graph data itself is reflected with this operation.
Expand All @@ -2465,7 +2466,8 @@ class TagCommand(SendWorkerTaskCommand):
## Parameters
- `tag_name` [mandatory]: the name of the tag to change
- `tag_value` [mandatory]: in case of update: the new value of the tag_name.
- `tag_value` [optional, default: null]: in case of update: the new value of the tag_name.
If the cloud provider does not support tag values, it can be omitted.
The tag_value can use format templates (`help format`) to define the value with backreferences from the object.
Example: test_{name}_{kind} -> test_pvc-123_disk
Expand Down Expand Up @@ -2563,6 +2565,12 @@ def parse(self, arg: Optional[str] = None, ctx: CLIContext = EmptyContext, **kwa
self.carz_from_node(item),
{"update": {tag: formatter(item)}, "node": item},
)
elif arg_tokens[0] == "update" and len(rest) == 2:
fn = lambda item: ( # noqa: E731
WorkerTaskName.tag,
self.carz_from_node(item),
{"update": {rest[1]: None}, "node": item},
)
else:
raise AttributeError("Expect update tag_key tag_value or delete tag_key")

Expand Down
3 changes: 3 additions & 0 deletions resotocore/tests/resotocore/cli/command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ def nr_of_performed() -> int:
res2 = await cli.execute_cli_command('search is("foo") | tag update foo bla', stream.list)
assert nr_of_performed() == 11
assert len(res2[0]) == 11
res2_tag_no_val = await cli.execute_cli_command('search is("foo") | tag update foobar', stream.list)
assert nr_of_performed() == 11
assert len(res2_tag_no_val[0]) == 11
res3 = await cli.execute_cli_command('search is("foo") | tag delete foo', stream.list)
assert nr_of_performed() == 11
assert len(res3[0]) == 11
Expand Down

0 comments on commit a5263b3

Please sign in to comment.