Files
python-vitrageclient/vitrageclient/v1/cli/template.py
idan kinory 91c90350d1 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
2018-01-11 10:20:14 +00:00

133 lines
4.0 KiB
Python

# Copyright 2016 - Nokia Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from cliff import command
from cliff import lister
from cliff import show
from vitrageclient.common import utils
# noinspection PyAbstractClass
class TemplateValidate(show.ShowOne):
def get_parser(self, prog_name):
parser = super(TemplateValidate, self).get_parser(prog_name)
parser.add_argument('--path',
required=True,
help='full path for template file or templates dir'
)
return parser
@property
def formatter_default(self):
return 'json'
def take_action(self, parsed_args):
result = utils.get_client(self).template.validate(
path=parsed_args.path)
return self.dict2columns(result)
class TemplateList(lister.Lister):
"""Template list"""
def get_parser(self, prog_name):
parser = super(TemplateList, self).get_parser(prog_name)
return parser
def take_action(self, parsed_args):
templates = utils.get_client(self).template.list()
# 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):
"""Template show"""
def get_parser(self, prog_name):
parser = super(TemplateShow, self).get_parser(prog_name)
parser.add_argument('uuid', help='Template UUID')
return parser
@property
def formatter_default(self):
return 'json'
def take_action(self, parsed_args):
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)