Support bond created 61/35861/2
authorliyuenan <liyuenan@huawei.com>
Tue, 14 Mar 2017 07:55:08 +0000 (15:55 +0800)
committerJustin chi <chigang@huawei.com>
Wed, 9 Aug 2017 06:49:11 +0000 (06:49 +0000)
JIRA: -

You can add bond according to deploy/conf/network_cfg.yaml.

Change-Id: I70f2f03581cf763dbaf7a8a47bdbd46b66620fcb
Signed-off-by: liyuenan <liyuenan@huawei.com>
(cherry picked from commit 2932812260b57e7f67cef655ee2e043bf66b4887)

deploy/adapters/cobbler/snippets/kickstart_post_install_network_config
deploy/adapters/cobbler/snippets/preseed_post_install_network_config
deploy/adapters/cobbler/snippets/preseed_software_ansible
deploy/bonding.py [new file with mode: 0644]
deploy/conf/network_cfg.yaml
deploy/deploy_host.sh

index 2c089f9..1a5a7f6 100644 (file)
@@ -426,9 +426,12 @@ declare -A used_logical_interfaces
 
 used_logical_interfaces[$iname]=$iname
 
-    #if $iface_type in ("slave","bond_slave","bridge_slave","bonded_bridge_slave")
+    #if $iface_type in ("slave","bridge_slave","bonded_bridge_slave")
         #set $static = 1
     #end if
+    #if $ip == ""
+        #set $static = ""
+    #end if
 echo "DEVICE=$iname" > $devfile
 echo "ONBOOT=yes" >> $devfile
 
@@ -514,7 +517,7 @@ echo "GATEWAY=$if_gateway" >> $devfile
 echo "NETMASK=$netmask" >> $devfile
         #end if
     #else
-echo "BOOTPROTO=dhcp" >> $devfile
+echo "BOOTPROTO=manual" >> $devfile
         #if $len($name_servers) > 0
 echo "PEERDNS=no" >> $devfile
         #end if
index cb79c55..7d4dcb9 100644 (file)
@@ -441,15 +441,18 @@ echo "" >> /etc/network/interfaces
 
 used_logical_interface_$iname=$iname
 
-    #if $iface_type in ("slave","bond_slave","bridge_slave","bonded_bridge_slave")
+    #if $iface_type in ("slave","bridge_slave","bonded_bridge_slave")
         #set $static = 1
     #end if
+    #if $ip == ""
+        #set $static = ""
+    #end if
 echo "auto $iname" >> /etc/network/interfaces
 
     #if $static
 echo "iface $iname inet static" >> /etc/network/interfaces
     #else
-echo "iface $iname inet dhcp" >> /etc/network/interfaces
+echo "iface $iname inet manual" >> /etc/network/interfaces
     #end if
 
     #if $iface_type not in ("master","bond","bridge","bonded_bridge_slave")
index cde7935..5516c89 100644 (file)
@@ -1 +1 @@
-d-i pkgsel/include string ntp ssh openssh-server wget vim
+d-i pkgsel/include string ntp ssh openssh-server wget vim ifenslave
diff --git a/deploy/bonding.py b/deploy/bonding.py
new file mode 100644 (file)
index 0000000..27e76da
--- /dev/null
@@ -0,0 +1,41 @@
+import os
+import sys
+import yaml
+
+
+def exec_cmd(cmd):
+    print cmd
+    os.system(cmd)
+
+
+def create_bonding(network_info, rsa_file, compass_ip):
+    for bond in network_info['bond_mappings']:
+        bond_name = bond['name']
+        host_name = bond.get('host')
+        interfaces = bond.get('bond-slaves')
+        bond_mode = bond['bond-mode']
+        bond_miimon = bond['bond-miimon']
+        lacp_rate = bond['bond-lacp_rate']
+        xmit_hash_policy = bond['bond-xmit_hash_policy']
+        bond_mtu = bond['mtu']
+        if interfaces:
+            for host in host_name:
+                for interface in interfaces:
+                    exec_cmd("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
+                              -i %s root@%s \
+                              'cobbler system edit --name=%s --interface=%s --interface-type=bond_slave --interface-master=%s'"   # noqa
+                             % (rsa_file, compass_ip, host, interface, bond_name))   # noqa
+
+                exec_cmd("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
+                          -i %s root@%s \
+                          'cobbler system edit --name=%s --interface=%s --interface-type=bond --bonding-opts=\"miimon=%s mode=%s lacp_rate=%s xmit_hash_policy=%s mtu=%s\"'"   # noqa
+                          % (rsa_file, compass_ip, host, bond_name, bond_miimon, bond_mode, lacp_rate, xmit_hash_policy, bond_mtu))   # noqa
+
+if __name__ == "__main__":
+    assert(len(sys.argv) == 4)
+    create_bonding(
+        yaml.load(
+            open(
+                sys.argv[1])),
+        sys.argv[2],
+        sys.argv[3])
index 28224b6..5e704e8 100644 (file)
@@ -9,7 +9,23 @@
 
 ---
 nic_mappings: []
-bond_mappings: []
+
+bond_mappings:
+  - name: bond1
+    host:
+      - host1
+      - host2
+      - host3
+      - host4
+      - host5
+    bond-slaves:
+      - eth1
+      - eth2
+    bond-mode: 802.3ad
+    bond-miimon: 100
+    bond-lacp_rate: fast
+    bond-xmit_hash_policy: layer2
+    mtu: 9000
 
 provider_net_mappings:
   - name: br-prv
index 6454a4b..4f75641 100755 (executable)
@@ -13,6 +13,10 @@ function rename_nics(){
     python $COMPASS_DIR/deploy/rename_nics.py $DHA $rsa_file $MGMT_IP $OS_VERSION
 }
 
+function add_bonding(){
+    python $COMPASS_DIR/deploy/bonding.py $NETWORK $rsa_file $MGMT_IP
+}
+
 function deploy_host(){
     export AYNC_TIMEOUT=20
     ssh $ssh_args root@${MGMT_IP} mkdir -p /opt/compass/bin/ansible_callbacks
@@ -22,7 +26,7 @@ function deploy_host(){
     scp $ssh_args -r ${COMPASS_DIR}/deploy/adapters/ansible/ansible_modules/* root@${MGMT_IP}:/opt/ansible-modules
 
     # avoid nodes reboot to fast, cobbler can not give response
-    (sleep $AYNC_TIMEOUT; rename_nics; reboot_hosts) &
+    (sleep $AYNC_TIMEOUT; add_bonding; rename_nics; reboot_hosts) &
     if [[ "$REDEPLOY_HOST" == true ]]; then
         deploy_flag="redeploy"
     else