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
|
vitrage template show 72f47086-366f-44d1-b88f-e420a8bc8ff0
|
||||||
returns a loaded template as json
|
returns a loaded template as json
|
||||||
|
|
||||||
|
Note: You can use template name instead of id
|
||||||
|
|
||||||
template add
|
template add
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
::
|
::
|
||||||
|
@ -971,6 +973,8 @@ template delete
|
||||||
For deleting multiple templates:
|
For deleting multiple templates:
|
||||||
vitrage template delete ae3c0752-1df9-408c-89d5-8b32b86f403f f254edb0-53cb-4552-969b-bdad24a14a03
|
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
|
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
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import re
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
@ -94,7 +92,7 @@ class TemplateShow(show.ShowOne):
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(TemplateShow, self).get_parser(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
|
return parser
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -102,8 +100,8 @@ class TemplateShow(show.ShowOne):
|
||||||
return 'json'
|
return 'json'
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
uuid = parsed_args.uuid
|
_id = parsed_args.id
|
||||||
template = utils.get_client(self).template.show(uuid=uuid)
|
template = utils.get_client(self).template.show(_id=_id)
|
||||||
return self.dict2columns(template)
|
return self.dict2columns(template)
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,10 +155,9 @@ class TemplateDelete(command.Command):
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(TemplateDelete, self).get_parser(prog_name)
|
parser = super(TemplateDelete, self).get_parser(prog_name)
|
||||||
parser.add_argument('uuid',
|
parser.add_argument('id',
|
||||||
help='ID of a template',
|
help='<ID or Name> of a template',
|
||||||
nargs='+',
|
nargs='+')
|
||||||
type=TemplateDelete.vaild_uuid)
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -168,15 +165,5 @@ class TemplateDelete(command.Command):
|
||||||
return 'json'
|
return 'json'
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
uuid = parsed_args.uuid
|
_id = parsed_args.id
|
||||||
utils.get_client(self).template.delete(uuid=uuid)
|
utils.get_client(self).template.delete(_id=_id)
|
||||||
|
|
||||||
@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
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ class Template(object):
|
||||||
"""Get templates list"""
|
"""Get templates list"""
|
||||||
return self.api.get(self.url).json()
|
return self.api.get(self.url).json()
|
||||||
|
|
||||||
def show(self, uuid):
|
def show(self, _id):
|
||||||
"""Show template content"""
|
"""Show template content"""
|
||||||
|
|
||||||
url = self.url + uuid
|
url = self.url + _id
|
||||||
return self.api.get(url).json()
|
return self.api.get(url).json()
|
||||||
|
|
||||||
def add(self, path=None, template_type=None,
|
def add(self, path=None, template_type=None,
|
||||||
|
@ -56,9 +56,9 @@ class Template(object):
|
||||||
params=params)
|
params=params)
|
||||||
return self.api.put(self.url, json=api_params).json()
|
return self.api.put(self.url, json=api_params).json()
|
||||||
|
|
||||||
def delete(self, uuid):
|
def delete(self, _id):
|
||||||
"""Delete existing"""
|
"""Delete existing"""
|
||||||
params = dict(uuid=uuid)
|
params = dict(id=_id)
|
||||||
return self.api.delete(self.url, json=params).json()
|
return self.api.delete(self.url, json=params).json()
|
||||||
|
|
||||||
def validate(self, path=None, template_type=None,
|
def validate(self, path=None, template_type=None,
|
||||||
|
|
Loading…
Reference in New Issue