Merge "Add an optional parameter --append"

This commit is contained in:
Zuul
2022-02-17 18:51:52 +00:00
committed by Gerrit Code Review
3 changed files with 35 additions and 8 deletions
+7 -4
View File
@@ -490,9 +490,8 @@ class TagController(object):
"""Create the list of tags.
:param namespace: Name of a namespace to which the Tags belong.
:param kwargs: list of tags.
:param kwargs: list of tags, optional parameter append.
"""
tag_names = kwargs.pop('tags', [])
md_tag_list = []
@@ -502,11 +501,15 @@ class TagController(object):
except (warlock.InvalidOperation) as e:
raise TypeError(encodeutils.exception_to_unicode(e))
tags = {'tags': md_tag_list}
headers = {}
url = '/v2/metadefs/namespaces/%(namespace)s/tags' % {
'namespace': namespace}
'namespace': namespace}
resp, body = self.http_client.post(url, data=tags)
append = kwargs.pop('append', False)
if append:
headers['X-Openstack-Append'] = True
resp, body = self.http_client.post(url, headers=headers, data=tags)
body.pop('self', None)
for tag in body['tags']:
yield self.model(tag), resp
+4 -2
View File
@@ -1396,10 +1396,12 @@ def do_md_tag_create(gc, args):
@utils.arg('--delim', metavar='<DELIM>', required=False,
help=_('The delimiter used to separate the names'
' (if none is provided then the default is a comma).'))
@utils.arg('--append', default=False, action='store_true', required=False,
help=_('Append the new tags to the existing ones instead of'
'overwriting them'))
def do_md_tag_create_multiple(gc, args):
"""Create new metadata definitions tags inside a namespace."""
delim = args.delim or ','
tags = []
names_list = args.names.split(delim)
for name in names_list:
@@ -1411,7 +1413,7 @@ def do_md_tag_create_multiple(gc, args):
utils.exit('Please supply at least one tag name. For example: '
'--names Tag1')
fields = {'tags': tags}
fields = {'tags': tags, 'append': args.append}
new_tags = gc.metadefs_tag.create_multiple(args.namespace, **fields)
columns = ['name']
column_settings = {