Add overwrite option to host-label-assign
Add an overwrite option to host-label-assign. The behavior will be consistent with kubectl label --overwrite. If a label key exists for the host and no overwrite option is given the operation will be rejected. With the overwrite option provided any existing keys will be updated to the new value. Change-Id: If32dfe191f002f991d8357c05ca4ed0ca4308fb6 Closes-Bug: 1850168 Signed-off-by: David Sullivan <david.sullivan@windriver.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#
|
||||
|
||||
from cgtsclient.common import base
|
||||
from cgtsclient.v1 import options
|
||||
|
||||
|
||||
class KubernetesLabel(base.Resource):
|
||||
@@ -34,8 +35,8 @@ class KubernetesLabelManager(base.Manager):
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def assign(self, host_uuid, label):
|
||||
return self._create(self._path(host_uuid), label)
|
||||
def assign(self, host_uuid, label, parameters=None):
|
||||
return self._create(options.build_url(self._path(host_uuid), q=None, params=parameters), label)
|
||||
|
||||
def remove(self, uuid):
|
||||
return self._delete(self._path(uuid))
|
||||
|
||||
@@ -43,11 +43,15 @@ def do_host_label_list(cc, args):
|
||||
action='append',
|
||||
default=[],
|
||||
help="List of Kubernetes labels")
|
||||
@utils.arg('--overwrite',
|
||||
action='store_true',
|
||||
help="Allow labels to be overwritten")
|
||||
def do_host_label_assign(cc, args):
|
||||
"""Update the Kubernetes labels on a host."""
|
||||
attributes = utils.extract_keypairs(args)
|
||||
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
|
||||
new_labels = cc.label.assign(ihost.uuid, attributes)
|
||||
parameters = ["overwrite=" + str(args.overwrite)]
|
||||
new_labels = cc.label.assign(ihost.uuid, attributes, parameters)
|
||||
for p in new_labels.labels:
|
||||
uuid = p['uuid']
|
||||
if uuid is not None:
|
||||
|
||||
Reference in New Issue
Block a user