Support for 'node-all' option in label command
Explicitly manage all nodes in label commands To prevent messing up user's environment label management commands must require --nodes-all parameter when they want to apply actions to labels on all nodes. Change-Id: I6f11e9311cc7987286eb03c1e3318115f8c76797 Closes-Bug: #1477642
This commit is contained in:
@@ -192,17 +192,23 @@ class NodeLabelSet(NodeMixIn, base.BaseCommand):
|
||||
nargs='+',
|
||||
help='List of labels for create or update')
|
||||
|
||||
parser.add_argument(
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument(
|
||||
'-n',
|
||||
'--nodes',
|
||||
nargs='+',
|
||||
help='Create or update labels only for specific nodes')
|
||||
group.add_argument(
|
||||
'--nodes-all',
|
||||
action='store_true',
|
||||
help='Create or update labels for all nodes')
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
nodes_ids = None if parsed_args.nodes_all else parsed_args.nodes
|
||||
data = self.client.set_labels_for_nodes(
|
||||
labels=parsed_args.labels, node_ids=parsed_args.nodes)
|
||||
labels=parsed_args.labels, node_ids=nodes_ids)
|
||||
msg = "Labels have been updated on nodes: {0} \n".format(
|
||||
','.join(data))
|
||||
self.app.stdout.write(msg)
|
||||
@@ -219,17 +225,23 @@ class NodeLabelDelete(NodeMixIn, base.BaseCommand):
|
||||
nargs='+',
|
||||
help='List of labels keys for delete')
|
||||
|
||||
parser.add_argument(
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument(
|
||||
'-n',
|
||||
'--nodes',
|
||||
nargs='+',
|
||||
help='Delete labels only for specific nodes')
|
||||
group.add_argument(
|
||||
'--nodes-all',
|
||||
action='store_true',
|
||||
help='Create or update labels for all nodes')
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
nodes_ids = None if parsed_args.nodes_all else parsed_args.nodes
|
||||
data = self.client.delete_labels_for_nodes(
|
||||
labels_keys=parsed_args.labels_keys, node_ids=parsed_args.nodes)
|
||||
labels_keys=parsed_args.labels_keys, node_ids=nodes_ids)
|
||||
msg = "Labels have been deleted on nodes: {0} \n".format(
|
||||
','.join(data))
|
||||
self.app.stdout.write(msg)
|
||||
|
||||
@@ -146,7 +146,7 @@ class TestNodeCommand(test_engine.BaseCLITest):
|
||||
|
||||
def test_node_label_set_for_all_nodes(self):
|
||||
labels = ['key_1=val_1', 'key_2=val_2']
|
||||
args = 'node label set {labels}'.format(
|
||||
args = 'node label set {labels} --nodes-all'.format(
|
||||
labels=' '.join(labels))
|
||||
|
||||
self.exec_command(args)
|
||||
@@ -169,7 +169,7 @@ class TestNodeCommand(test_engine.BaseCLITest):
|
||||
|
||||
def test_node_label_delete_for_all_nodes(self):
|
||||
labels_keys = ['key_1', 'key_2']
|
||||
args = 'node label delete {labels_keys}'.format(
|
||||
args = 'node label delete {labels_keys} --nodes-all'.format(
|
||||
labels_keys=' '.join(labels_keys))
|
||||
|
||||
self.exec_command(args)
|
||||
|
||||
Reference in New Issue
Block a user