support for non 22 ssh and compute node mgt bridge

Change-Id: I3eca34de01238c4a29906ffa9db1f3e37a661141
diff --git a/build.gradle b/build.gradle
index 3ab4704..86c0888 100644
--- a/build.gradle
+++ b/build.gradle
@@ -96,51 +96,22 @@
     commandLine "$dockerPath/docker", 'push', "$targetReg/cord-provisioner:$targetTag"
 }
 
-// Automation Images
+// Automation Image
 
 task buildAutomationImage(type: Exec) {
     commandLine "$dockerPath/docker", 'build', '-t', "cord-maas-automation", "-f", "./automation/Dockerfile", "./automation"
 }
 
-task buildAutomationImageAnsible(type: Exec) {
-    commandLine "$dockerPath/docker", 'build', '-t', "cord-maas-automation:ansible", "-f", "./automation/Dockerfile.ansible", "./automation"
-}
-
-task buildAutomationImages {
-    dependsOn buildAutomationImage
-    dependsOn buildAutomationImageAnsible
-}
-
 task tagAutomationImage(type: Exec) {
     dependsOn buildAutomationImage
     commandLine "$dockerPath/docker", 'tag', 'cord-maas-automation', "$targetReg/cord-maas-automation:$targetTag"
 }
 
-task tagAutomationImageAnsible(type: Exec) {
-    dependsOn buildAutomationImageAnsible
-    commandLine "$dockerPath/docker", 'tag', 'cord-maas-automation:ansible', "$targetReg/cord-maas-automation:$targetTag-ansible"
-}
-
-task tagAutomationImages {
-    dependsOn tagAutomationImage
-    dependsOn tagAutomationImageAnsible
-}
-
 task publishAutomationImage(type: Exec) {
     dependsOn tagAutomationImage
     commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-automation:$targetTag"
 }
 
-task publishAutomationImageAnsible(type: Exec) {
-    dependsOn tagAutomationImageAnsible
-    commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-automation:$targetTag-ansible"
-}
-
-task publishAutomationImages {
-    dependsOn publishAutomationImage
-    dependsOn publishAutomationImageAnsible
-}
-
 // DHCP Harvester Images
 
 task buildHarvesterImage(type: Exec) {
@@ -172,7 +143,7 @@
 task buildImages {
     dependsOn buildBootstrapImage
     dependsOn buildHarvesterImage
-    dependsOn buildAutomationImages
+    dependsOn buildAutomationImage
     dependsOn buildAllocationImage
     dependsOn buildProvisionerImage
     dependsOn buildSwitchqImage
@@ -181,7 +152,7 @@
 task tagImages {
     dependsOn tagBootstrapImage
     dependsOn tagHarvesterImage
-    dependsOn tagAutomationImages
+    dependsOn tagAutomationImage
     dependsOn tagAllocationImage
     dependsOn tagProvisionerImage
     dependsOn tagSwitchqImage
@@ -190,7 +161,7 @@
 task publish {
     dependsOn publishBootstrapImage
     dependsOn publishHarvesterImage
-    dependsOn publishAutomationImages
+    dependsOn publishAutomationImage
     dependsOn publishAllocationImage
     dependsOn publishProvisionerImage
     dependsOn publishSwitchqImage
@@ -258,6 +229,10 @@
             .p(config.seedServer.domain, "domain")
     }
 
+    if (config.seedServer.port) {
+        extraVars = extraVars.p(config.seedServer.port, "ansible_ssh_port")
+    }
+
     if (vboxUser != "") {
         extraVars = extraVars.p(vboxUser, "power_helper_user")
     }
@@ -311,6 +286,10 @@
 	    .p(config.seedServer.power_helper_host, "power_helper_host")
     }
 
+    if (config.seedServer.port) {
+        extraVars = extraVars.p(config.seedServer.port, "ansible_ssh_port")
+    }
+
     if (vboxUser != "") {
         extraVars = extraVars.p(vboxUser, "power_helper_user")
     }
diff --git a/roles/compute-node/files/rename_ifaces.sh b/roles/compute-node/files/rename_ifaces.sh
index 0f9b5b4..89b49aa 100755
--- a/roles/compute-node/files/rename_ifaces.sh
+++ b/roles/compute-node/files/rename_ifaces.sh
@@ -55,8 +55,11 @@
         i40e)
             RESULT="I40G"
             ;;
-        igb|e1000|bnx2)
-            RESULT="ETH"
+	*)
+	    IS_PHY=$(ls -l /sys/class/net/$1 | grep -v virtual | wc -l)
+	    if [ $IS_PHY -eq 1 ]; then
+		RESULT="ETH"
+	    fi
             ;;
         *) ;;
     esac
@@ -122,16 +125,15 @@
       echo "" >> $OUT
     fi
 
-    local GRAB_FIRST=1
+    BRIDGE_PORTS=
     for i in $(cat $2); do
         if [ "eth$IDX" == "$4" ]; then
+	        echo "auto eth$IDX" >> $OUT
             if [ "$EXT_IP" == "dhcp" ]; then
-		echo "auto eth$IDX" >> $OUT
                 echo "iface eth$IDX inet dhcp" >> $OUT
             elif [ "$EXT_IP" == "manual" ]; then
 		echo "iface eth$IDX inet manual" >> $OUT
             else
-		echo "auto eth$IDX" >> $OUT
                 echo "iface eth$IDX inet static" >> $OUT
                 echo "    address $EXT_IP" >> $OUT
                 echo "    network $EXT_NETWORK" >> $OUT
@@ -141,16 +143,40 @@
 		echo "    dns-nameservers 8.8.8.8 8.8.4.4" >> $OUT
 		echo "    dns-search cord.lab" >> $OUT
             fi
-        elif [ $GRAB_FIRST -eq 1 ]; then
+        elif [ "eth$IDX" == "$5" ]; then
             echo "auto eth$IDX" >> $OUT
-            echo "iface eth$IDX inet dhcp" >> $OUT
-            GRAB_FIRST=0
+	    if [ "$MGT_IP" == "dhcp" ]; then
+	        echo "iface eth$IDX inet dhcp" >> $OUT
+	    elif [ "$MGT_IP" == "manual" ]; then
+		echo "iface eth$IDX inet manual" >> $OUT
+	    else
+                echo "iface eth$IDX inet static" >> $OUT
+                echo "    address $MGT_IP" >> $OUT
+                echo "    network $MGT_NETWORK" >> $OUT
+                echo "    netmask $MGT_NETMASK" >> $OUT
+                echo "    broadcast $MGT_BROADCAST" >> $OUT
+                echo "    gateway $MGT_GW" >> $OUT
+	    fi
         else
+            echo "auto eth$IDX" >> $OUT
             echo "iface eth$IDX inet manual" >> $OUT
+	    BRIDGE_PORTS="$BRIDGE_PORTS eth$IDX"
         fi
         echo "" >> $OUT
         IDX=$(expr $IDX + 1)
     done
+
+    local BRNAME=$5
+    local F=$(echo $5 | grep "^eth[0-9]*$" | wc -l)
+    if [ $F -ne 0 ]; then
+	BRNAME="br-mgmt"
+    fi
+    local BPCNT=$(echo $BRIDGE_PORTS | wc -w)
+    if [ $BPCNT -ne 0 ]; then
+	echo "auto $BRNAME" >> $OUT
+	echo "iface $BRNAME inet dhcp" >> $OUT
+	echo "    bridge_ports $BRIDGE_PORTS" >> $OUT
+    fi
 }
 
 FAB_IFACE=$1
@@ -171,6 +197,15 @@
     EXT_GW=$(first $EXT_ADDR)
 fi
 MGT_IFACE=$5
+MGT_ADDR=$6
+if [ "$MGT_ADDR" != "dhcp" ]; then
+    MGT_IP=$(echo $MGT_ADDR | cut -d/ -f1)
+    MGT_MASKBITS=$(echo $MGT_ADDR | cut -d/ -f2)
+    MGT_NETWORK=$(network $MGT_IP $MGT_MASKBITS)
+    MGT_NETMASK=$(netmask $MGT_MASKBITS)
+    MGT_BROADCAST=$(broadcast $MGT_IP $MGT_MASKBITS)
+    MGT_GW=$(first $MGT_ADDR)
+fi
 
 LIST_ETH=$(mktemp -u)
 LIST_40G=$(mktemp -u)
@@ -194,7 +229,7 @@
 
 CHANGED="false"
 
-generate_interfaces $LIST_40G $LIST_ETH $FAB_IFACE $EXT_IFACE $MGT_IFACE
+generate_interfaces $LIST_40G $LIST_ETH "$FAB_IFACE" "$EXT_IFACE" "$MGT_IFACE"
 
 diff /etc/network/interfaces $IFACES_FILE 2>&1 > /dev/null
 if [ $? -ne 0 ]; then
@@ -203,7 +238,7 @@
   cp $IFACES_FILE /etc/network/interfaces
 fi
 
-generate_persistent_names $LIST_40G $LIST_ETH $FAB_IFACE $EXT_IFACE
+generate_persistent_names $LIST_40G $LIST_ETH "$FAB_IFACE" "$EXT_IFACE"
 if [ -r /etc/udev/rules.d/70-persistent-net.rules ]; then
   diff /etc/udev/rules.d/70-persistent-net.rules $NAMES_FILE 2>&1 > /dev/null
   if [ $? -ne 0 ]; then
diff --git a/roles/compute-node/tasks/main.yml b/roles/compute-node/tasks/main.yml
index 5f5a8dd..b63bb84 100644
--- a/roles/compute-node/tasks/main.yml
+++ b/roles/compute-node/tasks/main.yml
@@ -15,6 +15,7 @@
     - git
     - python-pip
     - ifenslave-2.6
+    - bridge-utils
 
 - name: Ensure Docker Insecure Repository
   become: yes
@@ -121,7 +122,7 @@
 
 - name: Consistent Interface Naming
   become: yes
-  script: files/rename_ifaces.sh {{ compute_node.interfaces.fabric }} {{ compute_node.addresses.fabric }} {{ compute_node.interfaces.external }} {{ compute_node.addresses.external }} {{ compute_node.interfaces.management }}
+  script: files/rename_ifaces.sh "{{ compute_node.interfaces.fabric }}" "{{ compute_node.addresses.fabric }}" "{{ compute_node.interfaces.external }}" "{{ compute_node.addresses.external }}" "{{ compute_node.interfaces.management }}" "{{ compute_node.addresses.management }}"
   register: ifaces_changed
   changed_when: ifaces_changed.stdout.find("true") != -1
   tags:
@@ -149,8 +150,13 @@
     - interface_config
     - reboot
 
+- name: Ensure Port Defined
+  set_fact:
+    ansible_ssh_port: 22
+  when: ansible_ssh_port is not defined
+
 - name: Wait For Restart
-  local_action: wait_for port=22 host={{ inventory_hostname }} search_regex=OpenSSH delay=30 timeout=600 connect_timeout=15
+  local_action: wait_for port={{ ansible_ssh_port }} host={{ inventory_hostname }} search_regex=OpenSSH delay=30 timeout=600 connect_timeout=15
   when: ifaces_changed.stdout.find("true") != -1
   tags:
     - interface_config
diff --git a/roles/compute-node/vars/main.yml b/roles/compute-node/vars/main.yml
index 1906b70..64316c3 100644
--- a/roles/compute-node/vars/main.yml
+++ b/roles/compute-node/vars/main.yml
@@ -3,8 +3,8 @@
 compute_node:
     interfaces:
         fabric: "{{ fabric_iface | default('fabric') }}"
-        management: "{{ management_iface | default('eth2') }}"
-        external: "{{ external_iface | default('eth3') }}"
+        management: "{{ management_iface | default('br-mgmt') }}"
+        external: "{{ external_iface | default('') }}"
     addresses:
         fabric: "{{ fabric_ip | mandatory }}"
         management: "{{ management_ip | default('dhcp') }}"
diff --git a/roles/maas/vars/main.yml b/roles/maas/vars/main.yml
index 15d7155..062c00c 100644
--- a/roles/maas/vars/main.yml
+++ b/roles/maas/vars/main.yml
@@ -27,9 +27,9 @@
     #                connected to the internet
     #   'management' specifies the interface on which the head node will
     #                service DHCP and PXE boot requests
-    fabric: "{{ fabric_iface | default('eth0') }}"
-    management: "{{ management_iface | default('eth2') }}"
-    external: "{{ external_iface | default('eth3') }}"
+    fabric: "{{ fabric_iface | default('fabric') }}"
+    management: "{{ management_iface | default('br-mgmt') }}"
+    external: "{{ external_iface | default('') }}"
 
 networks:
     # CHANGE: