From b9cf7d42b1dd861bfd812de3928f58fe6aa46ce8 Mon Sep 17 00:00:00 2001
From: vsaienko <vsaienko@mirantis.com>
Date: Fri, 11 Dec 2015 11:41:00 +0200
Subject: [PATCH] Add Link-Local-Connection info to ironic port

This patch introduce new variable called IRONIC_USE_LINK_LOCAL.
Link-Local-Connection information is used by Neutron to bind_port
on the switch.

Change-Id: Icfb9257bded5b234a9d05f2b2de6d6580f2f42aa
Partial-bug: #1526403
---
 devstack/lib/ironic                          | 24 +++++++++++++++++++-
 devstack/tools/ironic/scripts/create-node.sh |  3 ++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/devstack/lib/ironic b/devstack/lib/ironic
index 2682d2bf8f..080672b7be 100644
--- a/devstack/lib/ironic
+++ b/devstack/lib/ironic
@@ -207,6 +207,11 @@ IRONIC_AUTH_STRATEGY=${IRONIC_AUTH_STRATEGY:-keystone}
 IRONIC_TERMINAL_SSL=$(trueorfalse False IRONIC_TERMINAL_SSL)
 IRONIC_TERMINAL_CERT_DIR=${IRONIC_TERMINAL_CERT_DIR:-$IRONIC_DATA_DIR/terminal_cert/}
 
+# This flag is used to allow adding Link-Local-Connection info
+# to ironic port-create command. LLC info is obtained from
+# IRONIC_{VM,HW}_NODES_FILE
+IRONIC_USE_LINK_LOCAL=$(trueorfalse False IRONIC_USE_LINK_LOCAL)
+
 # get_pxe_boot_file() - Get the PXE/iPXE boot file path
 function get_pxe_boot_file {
     local relpath=syslinux/pxelinux.0
@@ -832,6 +837,21 @@ function enroll_nodes {
                 vbmc_port=$(echo $hardware_info | awk '{print $2}')
                 node_options+=" -i ipmi_port=$vbmc_port"
             fi
+            # Local-link-connection options
+            if [[ "${IRONIC_USE_LINK_LOCAL}" == "True" ]]; then
+                local llc_opts=""
+                local switch_info
+                local switch_id
+                local port_id
+
+                switch_info=$(echo $hardware_info |awk '{print $3}')
+                switch_id=$(echo $hardware_info |awk '{print $4}')
+                port_id=$(echo $hardware_info |awk '{print $5}')
+
+                llc_opts="-l switch_id=${switch_id} -l switch_info=${switch_info} -l port_id=${port_id}"
+
+                local ironic_api_version='--ironic-api-version latest'
+            fi
         else
             # Currently we require all hardware platform have same CPU/RAM/DISK info
             # in future, this can be enhanced to support different type, and then
@@ -887,7 +907,9 @@ function enroll_nodes {
             ironic node-update $node_id add properties/root_device='{"vendor": "0x1af4"}'
         fi
 
-        ironic port-create --address $mac_address --node $node_id
+        # In case we using portgroups, we should API version that support them.
+        # Othervise API will return 406 ERROR
+        ironic $ironic_api_version port-create --address $mac_address --node $node_id $llc_opts
 
         total_nodes=$((total_nodes+1))
         total_cpus=$((total_cpus+$ironic_node_cpu))
diff --git a/devstack/tools/ironic/scripts/create-node.sh b/devstack/tools/ironic/scripts/create-node.sh
index 0b0278b717..7850ff4cae 100755
--- a/devstack/tools/ironic/scripts/create-node.sh
+++ b/devstack/tools/ironic/scripts/create-node.sh
@@ -78,4 +78,5 @@ fi
 
 # echo mac
 VM_MAC=$(virsh dumpxml $NAME | grep "mac address" | head -1 | cut -d\' -f2)
-echo $VM_MAC $VBMC_PORT
+switch_id=$(ip link show dev $BRIDGE | egrep -o "ether [A-Za-z0-9:]+"|sed "s/ether\ //")
+echo $VM_MAC $VBMC_PORT $BRIDGE $switch_id ovs-$NAME