aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/rename_nics.py
diff options
context:
space:
mode:
authorcarey.xu <carey.xuhan@huawei.com>2016-01-30 18:43:30 +0800
committerJustin chi <chigang@huawei.com>2016-01-31 00:37:35 +0000
commit104a2934a54d7113cf4c3eb76b29377c4b3a8425 (patch)
treeefbe7e83af182e4333b60853e4cc7d275568c7c2 /deploy/rename_nics.py
parent5c31226684c85448f69ece611ffefbf9a3bacf23 (diff)
bugfix: rename nic based on mac
Change-Id: I2771a87a41ab884dbda1fcffa8ab0833489fb5ef Signed-off-by: carey.xu <carey.xuhan@huawei.com>
Diffstat (limited to 'deploy/rename_nics.py')
-rw-r--r--deploy/rename_nics.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/deploy/rename_nics.py b/deploy/rename_nics.py
new file mode 100644
index 00000000..ef52d63a
--- /dev/null
+++ b/deploy/rename_nics.py
@@ -0,0 +1,29 @@
+import os
+import sys
+import yaml
+
+def exec_cmd(cmd):
+ print cmd
+ os.system(cmd)
+
+def rename_nics(dha_info, rsa_file, compass_ip):
+ for host in dha_info['hosts']:
+ host_name = host['name']
+ interfaces = host.get('interfaces')
+ if interfaces:
+ for interface in interfaces:
+ nic_name = interfaces.keys()[0]
+ mac = interfaces.values()[0]
+
+ exec_cmd("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
+ -i %s root@%s \
+ 'cobbler system edit --name=%s --interface=%s --mac=%s'" \
+ % (rsa_file, compass_ip, host_name, nic_name, mac))
+
+ exec_cmd("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
+ -i %s root@%s \
+ 'cobbler sync'" % (rsa_file, compass_ip))
+
+if __name__ == "__main__":
+ assert(len(sys.argv) == 4)
+ rename_nics(yaml.load(open(sys.argv[1])), sys.argv[2], sys.argv[3])