support template add and delete

support for template add and template delete
not in use until vitrage backend support the changes.

Change-Id: I07741ed100b9eb70b303567706b659d10a34b156
Implements: blueprint crud-templates
This commit is contained in:
idan kinory 2017-12-28 15:49:12 +00:00
parent 0c398e3704
commit 91c90350d1
4 changed files with 78 additions and 6 deletions

View File

@ -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'

View File

@ -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,

View File

@ -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)

View File

@ -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