diff --git a/tools/vitrage.bash_completion b/tools/vitrage.bash_completion index 211d490..53977fc 100755 --- a/tools/vitrage.bash_completion +++ b/tools/vitrage.bash_completion @@ -20,7 +20,9 @@ _vitrage() cmds_resource='list show' cmds_resource_list='-h --help -f --format -c --column --max-width --print-empty --noindent --quote --type --all-tenants' cmds_resource_show='-h --help -f --format -c --column --max-width --print-empty --noindent --variable --prefix' - cmds_template='list show validate' + cmds_template='list show validate add delete' + cmds_template_add='-h --help --path --type' + cmds_template_delete='-h --help' cmds_template_list='-h --help -f --format -c --column --max-width --print-empty --noindent --quote' cmds_template_show='-h --help -f --format -c --column --max-width --print-empty --noindent --variable --prefix' cmds_template_validate='-h --help -f --format -c --column --max-width --print-empty --noindent --variable --prefix --path' diff --git a/vitrageclient/shell.py b/vitrageclient/shell.py index f2ac799..0d2d15e 100755 --- a/vitrageclient/shell.py +++ b/vitrageclient/shell.py @@ -58,6 +58,8 @@ class VitrageCommandManager(commandmanager.CommandManager): 'template validate': template.TemplateValidate, 'template list': template.TemplateList, 'template show': template.TemplateShow, + 'template add': template.TemplateAdd, + 'template delete': template.TemplateDelete, 'event post': event.EventPost, 'healthcheck': healthcheck.HealthCheck, 'webhook delete': webhook.WebhookDelete, diff --git a/vitrageclient/v1/cli/template.py b/vitrageclient/v1/cli/template.py index b14c71d..fea5f52 100644 --- a/vitrageclient/v1/cli/template.py +++ b/vitrageclient/v1/cli/template.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from cliff import command from cliff import lister from cliff import show @@ -50,11 +51,15 @@ class TemplateList(lister.Lister): def take_action(self, parsed_args): templates = utils.get_client(self).template.list() - return utils.list2cols(('uuid', - 'name', - 'status', - 'status details', - 'date'), templates) + # TODO(ikinory): add type to the table. + return utils.list2cols_with_rename( + ( + ('UUID', 'uuid'), + ('Name', 'name'), + ('Status', 'status'), + ('Status details', 'status details'), + ('Date', 'date'), + ), templates) class TemplateShow(show.ShowOne): @@ -73,3 +78,55 @@ class TemplateShow(show.ShowOne): uuid = parsed_args.uuid template = utils.get_client(self).template.show(uuid=uuid) return self.dict2columns(template) + + +class TemplateAdd(lister.Lister): + """Template add + + support 3 types of templates: + standard, definition, equivalence + """ + + def get_parser(self, prog_name): + parser = super(TemplateAdd, self).get_parser(prog_name) + parser.add_argument('--path', + required=True, + help='full path for template file or templates dir' + ) + parser.add_argument('--type', + choices=['standard', 'definition', 'equivalence'], + help='Template type. Valid types:' + '[standard, definition, equivalence]') + return parser + + def take_action(self, parsed_args): + path = parsed_args.path + template_type = parsed_args.type + templates = utils.get_client(self).template.add( + path=path, template_type=template_type) + return utils.list2cols_with_rename( + ( + ('UUID', 'uuid'), + ('Name', 'name'), + ('Status', 'status'), + ('Status details', 'status details'), + ('Date', 'date'), + ('Type', 'type'), + ), templates) + + +class TemplateDelete(command.Command): + """Template delete""" + + def get_parser(self, prog_name): + parser = super(TemplateDelete, self).get_parser(prog_name) + parser.add_argument('uuid', help='ID of a template') + return parser + + @property + def formatter_default(self): + return 'json' + + def take_action(self, parsed_args): + uuid = parsed_args.uuid + utils.get_client(self).template.delete(uuid=uuid) diff --git a/vitrageclient/v1/template.py b/vitrageclient/v1/template.py index f978c2e..9914ebc 100644 --- a/vitrageclient/v1/template.py +++ b/vitrageclient/v1/template.py @@ -35,6 +35,17 @@ class Template(object): url = self.url + uuid return self.api.get(url).json() + def add(self, path, template_type): + """Add a new template""" + + params = dict(path=path, template_type=template_type) + return self.api.put(self.url, json=params).json() + + def delete(self, uuid): + """Delete existing""" + params = dict(uuid=uuid) + return self.api.delete(self.url, json=params).json() + def validate(self, path=None): """Template validation