Skip to content

Commit bbf662f

Browse files
authored
Merge pull request #35 from laincloud/fix
enhance params check
2 parents a7a8c55 + 8910c9a commit bbf662f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lain_admin_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = '2.1.1'
3+
__version__ = '2.1.2'

lain_admin_cli/node.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,34 @@ def change_labels(self, nodes, change_type="", labels=[], playbooks=""):
297297
diff_labels = ['{}={}'.format(k, v)
298298
for k, v in normlized_labels.items()]
299299

300+
node_infos = {}
300301
try:
301302
for node in nodes:
302303
node_info = NodeInfo(node)
304+
if node_info.ip in node_infos:
305+
error('duplicate node {}:{}'.
306+
format(node_info.name, node_info.ip))
307+
sys.exit(1)
308+
309+
node_infos[node_info.ip] = node_info
310+
except Exception as e:
311+
error("Exception: {}.".format(e))
312+
sys.exit(1)
313+
314+
try:
315+
for _, node_info in node_infos.items():
303316
key = "{}:{}:{}".format(node_info.name, node_info.ip,
304317
node_info.ssh_port)
305318
check_output(['etcdctl', 'set',
306-
'/lain/nodes/changing_labels/{}'.format(key),
319+
'/lain/nodes/changing-labels/{}'.format(key),
307320
node_info.ip], stderr=STDOUT)
308321
run_change_labels_ansible(playbooks, change_type, diff_labels)
309322
except Exception as e:
310323
error("Exception: {}.".format(e))
311324
sys.exit(1)
312325
finally:
313-
for node in nodes:
314-
node_info = NodeInfo(node)
315-
key = "{}:{}:{}".format(node_info.name, node_info.ip,
316-
node_info.ssh_port)
317-
check_output(['etcdctl', 'rm',
318-
'/lain/nodes/changing_labels/{}'.format(key)],
319-
stderr=STDOUT)
326+
check_output(['etcdctl', 'rm', '--recursive',
327+
'/lain/nodes/changing-labels'], stderr=STDOUT)
320328

321329

322330
def run_addnode_ansible(args):

0 commit comments

Comments
 (0)