bugfix: rename nic based on mac 79/8779/2
authorcarey.xu <carey.xuhan@huawei.com>
Sat, 30 Jan 2016 10:43:30 +0000 (18:43 +0800)
committerJustin chi <chigang@huawei.com>
Sun, 31 Jan 2016 00:39:00 +0000 (00:39 +0000)
Change-Id: I2771a87a41ab884dbda1fcffa8ab0833489fb5ef
Signed-off-by: carey.xu <carey.xuhan@huawei.com>
deploy/conf/hardware_environment/huawei-us-deploy-bare-1/os-nosdn-nofeature-ha.yml
deploy/deploy_host.sh
deploy/rename_nics.py [new file with mode: 0644]

index 4b812df..18b9f07 100644 (file)
@@ -9,6 +9,8 @@ ipmiVer: '2.0'
 hosts:
   - name: host1
     mac: 'F8:4A:BF:55:A2:8D'
+    interfaces:
+       eth1: 'F8:4A:BF:55:A2:8E'
     ipmiIp: 172.16.130.26
     ipmiPass: Huawei@123
     roles:
@@ -17,6 +19,8 @@ hosts:
 
   - name: host2
     mac: 'D8:49:0B:DA:5A:B7'
+    interfaces:
+      eth1: 'D8:49:0B:DA:5A:B8'
     ipmiIp: 172.16.130.27
     ipmiPass: huawei@123
     roles:
@@ -25,6 +29,8 @@ hosts:
 
   - name: host3
     mac: 'D8:49:0B:DA:2A:28'
+    interfaces:
+      eth1: 'D8:49:0B:DA:2A:29'
     ipmiIp: 172.16.130.29
     ipmiPass: Huawei@123
     roles:
@@ -33,6 +39,8 @@ hosts:
 
   - name: host4
     mac: 'D8:49:0B:DA:5B:5D'
+    interfaces:
+      eth1: 'D8:49:0B:DA:5B:5E'
     ipmiIp: 172.16.130.30
     ipmiPass: Huawei@123
     roles:
@@ -40,6 +48,8 @@ hosts:
 
   - name: host5
     mac: 'D8:49:0B:DA:56:85'
+    interfaces:
+      eth1: 'D8:49:0B:DA:56:86'
     ipmiIp: 172.16.130.31
     ipmiPass: Huawei@123
     roles:
index 1b03f04..9617b24 100755 (executable)
@@ -8,14 +8,18 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 rsa_file=$compass_vm_dir/boot.rsa
+
+function rename_nics(){
+    python $COMPASS_DIR/deploy/rename_nics.py $DHA $rsa_file $MGMT_IP
+}
+
 function deploy_host(){
 
     ssh $ssh_args root@${MGMT_IP} mkdir -p /opt/compass/bin/ansible_callbacks
     scp $ssh_args -r ${COMPASS_DIR}/deploy/status_callback.py root@${MGMT_IP}:/opt/compass/bin/ansible_callbacks/status_callback.py
 
     # avoid nodes reboot to fast, cobbler can not give response
-    (sleep 20;reboot_hosts) &
-
+    (sleep 20; rename_nics; reboot_hosts) &
     if [[ "$REDEPLOY_HOST" == true ]]; then
         deploy_flag="redeploy"
     else
diff --git a/deploy/rename_nics.py b/deploy/rename_nics.py
new file mode 100644 (file)
index 0000000..ef52d63
--- /dev/null
@@ -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])