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
This commit is contained in:
parent
df8023553e
commit
a4bcd82eb9
@ -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
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
::
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Added support to show and delete template by name.
|
@ -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='<ID or Name> 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)
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user