From a4bcd82eb99431d414774c5509ee07fdf36d7563 Mon Sep 17 00:00:00 2001 From: Eyal Date: Sun, 26 May 2019 16:10:57 +0300 Subject: [PATCH] Support using name in show and delete templates Vitrage can show and delete templates by name So remove the constraints on using only uuid in CLI for deleting templates renamed the parameters also to be more clear Change-Id: Iaf68f994bdceee4a01ca445bde935ca42077f541 --- doc/source/contributor/cli.rst | 4 +++ ...show_and_add_by_name-19f6ec71d2d5b14c.yaml | 3 ++ vitrageclient/v1/cli/template.py | 29 +++++-------------- vitrageclient/v1/template.py | 8 ++--- 4 files changed, 19 insertions(+), 25 deletions(-) create mode 100644 releasenotes/notes/support_template_show_and_add_by_name-19f6ec71d2d5b14c.yaml diff --git a/doc/source/contributor/cli.rst b/doc/source/contributor/cli.rst index 29b4ff6..0165a02 100644 --- a/doc/source/contributor/cli.rst +++ b/doc/source/contributor/cli.rst @@ -944,6 +944,8 @@ template show vitrage template show 72f47086-366f-44d1-b88f-e420a8bc8ff0 returns a loaded template as json + Note: You can use template name instead of id + template add ^^^^^^^^^^^^ :: @@ -971,6 +973,8 @@ template delete For deleting multiple templates: vitrage template delete ae3c0752-1df9-408c-89d5-8b32b86f403f f254edb0-53cb-4552-969b-bdad24a14a03 + Note: You can use template name instead of id + Templates with parameters ^^^^^^^^^^^^^^^^^^^^^^^^^ :: diff --git a/releasenotes/notes/support_template_show_and_add_by_name-19f6ec71d2d5b14c.yaml b/releasenotes/notes/support_template_show_and_add_by_name-19f6ec71d2d5b14c.yaml new file mode 100644 index 0000000..fadbae8 --- /dev/null +++ b/releasenotes/notes/support_template_show_and_add_by_name-19f6ec71d2d5b14c.yaml @@ -0,0 +1,3 @@ +--- +features: + - Added support to show and delete template by name. \ No newline at end of file diff --git a/vitrageclient/v1/cli/template.py b/vitrageclient/v1/cli/template.py index 8c8b52a..44eb3a9 100644 --- a/vitrageclient/v1/cli/template.py +++ b/vitrageclient/v1/cli/template.py @@ -11,9 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import re -import argparse from cliff import command from cliff import lister from cliff import show @@ -94,7 +92,7 @@ class TemplateShow(show.ShowOne): def get_parser(self, prog_name): parser = super(TemplateShow, self).get_parser(prog_name) - parser.add_argument('uuid', help='Template UUID') + parser.add_argument('id', help='Template UUID or Name') return parser @property @@ -102,8 +100,8 @@ class TemplateShow(show.ShowOne): return 'json' def take_action(self, parsed_args): - uuid = parsed_args.uuid - template = utils.get_client(self).template.show(uuid=uuid) + _id = parsed_args.id + template = utils.get_client(self).template.show(_id=_id) return self.dict2columns(template) @@ -157,10 +155,9 @@ class TemplateDelete(command.Command): def get_parser(self, prog_name): parser = super(TemplateDelete, self).get_parser(prog_name) - parser.add_argument('uuid', - help='ID of a template', - nargs='+', - type=TemplateDelete.vaild_uuid) + parser.add_argument('id', + help=' of a template', + nargs='+') return parser @property @@ -168,15 +165,5 @@ class TemplateDelete(command.Command): return 'json' def take_action(self, parsed_args): - uuid = parsed_args.uuid - utils.get_client(self).template.delete(uuid=uuid) - - @staticmethod - def vaild_uuid(uuids): - rege = '^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$' - if type(uuids) != list: - uuids = [uuids] - for uuid in uuids: - if not re.match(rege, uuid): - raise argparse.ArgumentTypeError("Not a uuid format") - return uuids + _id = parsed_args.id + utils.get_client(self).template.delete(_id=_id) diff --git a/vitrageclient/v1/template.py b/vitrageclient/v1/template.py index e317ddf..35cc88b 100644 --- a/vitrageclient/v1/template.py +++ b/vitrageclient/v1/template.py @@ -29,10 +29,10 @@ class Template(object): """Get templates list""" return self.api.get(self.url).json() - def show(self, uuid): + def show(self, _id): """Show template content""" - url = self.url + uuid + url = self.url + _id return self.api.get(url).json() def add(self, path=None, template_type=None, @@ -56,9 +56,9 @@ class Template(object): params=params) return self.api.put(self.url, json=api_params).json() - def delete(self, uuid): + def delete(self, _id): """Delete existing""" - params = dict(uuid=uuid) + params = dict(id=_id) return self.api.delete(self.url, json=params).json() def validate(self, path=None, template_type=None,