
* rename the file from exc to exceptions * move CommandException to exceptions and change it to CommandError * use argparse required=True instead of checking in the code Change-Id: I67450ff0acb317fa1ab3996a094e871023f5383f
76 lines
2.3 KiB
Python
76 lines
2.3 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 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()
|
|
return utils.list2cols(('uuid',
|
|
'name',
|
|
'status',
|
|
'status details',
|
|
'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)
|