Move node labeling and net configuration to bootstrap

The patch moves node labeling and network interface along with
bridge, veth pairs from pipelines to heat bootstrap script. Net
configuration is set by netplan therefore it is made in matter
of permanent config.

Related-PROD: PRODX-2361
Change-Id: I12a5e839ad453b73d6f505859ef80838289a4184
diff --git a/de/heat-templates/scripts/instance_boot.sh b/de/heat-templates/scripts/instance_boot.sh
index c16b494..9ec1054 100644
--- a/de/heat-templates/scripts/instance_boot.sh
+++ b/de/heat-templates/scripts/instance_boot.sh
@@ -13,10 +13,14 @@
 KUBECTL_VERSION=${KUBECTL_VERSION:-v1.14.0}
 NODE_DEPLOYMENT_RETRIES=${NODE_DEPLOYMENT_RETRIES:-15}
 FLOATING_NETWORK_PREFIXES=${FLOATING_NETWORK_PREFIXES:-10.11.12.0/24}
+PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-ens4}
+PUBLIC_NODE_IP_ADDRESS=$(ip addr show dev ${PUBLIC_INTERFACE} | grep -Po 'inet \K[\d.]+' | egrep -v "127.0.|172.17")
+PUBLIC_NODE_IP_NETMASK=$(ip addr show dev ${PUBLIC_INTERFACE} | grep -Po 'inet \K[\d.]+\/[\d]+' | egrep -v "127.0.|172.17" | cut -d'/' -f2)
 
 NODE_TYPE=$node_type
 UCP_MASTER_HOST=$ucp_master_host
 UCP_MASTER_HOST=${UCP_MASTER_HOST:-${NODE_IP_ADDRESS}}
+NODE_METADATA='$node_metadata'
 
 function retry {
     local retries=$1
@@ -174,12 +178,51 @@
     done
 }
 
+function configure_public_interface {
+    local public_interface=${1:-${PUBLIC_INTERFACE}}
+    local cloud_netplan_cfg="/etc/netplan/50-cloud-init.yaml"
+    local match_ip_line
+
+    DEBIAN_FRONTEND=noninteractive apt -y install bridge-utils atop
+
+cat << EOF > /etc/systemd/network/10-veth-phy-br.netdev
+[NetDev]
+Name=veth-phy
+Kind=veth
+[Peer]
+Name=veth-br
+EOF
+    sed -i 's/.*ethernets:.*/&\n        veth-phy: {}/' ${cloud_netplan_cfg}
+    sed -i 's/.*ethernets:.*/&\n        veth-br: {}/' ${cloud_netplan_cfg}
+
+    match_ip_line=$(grep -nm1 "${PUBLIC_NODE_IP_ADDRESS}/${PUBLIC_NODE_IP_NETMASK}" ${cloud_netplan_cfg} | cut -d: -f1)
+
+    sed -i "$((${match_ip_line}-1)),$((${match_ip_line}))d" ${cloud_netplan_cfg}
+
+cat << EOF >> ${cloud_netplan_cfg}
+    bridges:
+        br-public:
+            dhcp4: false
+            interfaces:
+            - ${PUBLIC_INTERFACE}
+            - veth-br
+            addresses:
+            - ${PUBLIC_NODE_IP_ADDRESS}/${PUBLIC_NODE_IP_NETMASK}
+EOF
+    netplan --debug apply
+}
+
+function set_node_labels {
+
+    kubectl patch node $(hostname) -p "{\"metadata\": ${NODE_METADATA}}"
+}
 
 case "$NODE_TYPE" in
     ucp)
         prepare_network
         update_docker_network
         install_docker_ce
+        configure_public_interface
         swarm_init
         create_ucp_config
         install_ucp
@@ -188,26 +231,31 @@
         install_kubectl
         workaround_default_forward_policy
         wait_for_node
+        set_node_labels
         ;;
     master)
         prepare_network
         update_docker_network
         install_docker_ce
+        configure_public_interface
         download_bundles
         join_node manager
         install_kubectl
         workaround_default_forward_policy
         wait_for_node
+        set_node_labels
         ;;
     worker)
         prepare_network
         update_docker_network
         install_docker_ce
+        configure_public_interface
         download_bundles
         join_node worker
         install_kubectl
         workaround_default_forward_policy
         wait_for_node
+        set_node_labels
         ;;
     *)
         echo "Usage: $0 {ucp|master|worker}"
diff --git a/de/heat-templates/srv-group.yaml b/de/heat-templates/srv-group.yaml
index a2cf684..dee472b 100644
--- a/de/heat-templates/srv-group.yaml
+++ b/de/heat-templates/srv-group.yaml
@@ -49,6 +49,7 @@
             $wait_condition_notify: { get_attr: [ wait_handle, curl_cli ] }
             $ucp_license_key: { get_file: ./scripts/license.lic }
             $ucp_master_host: { get_param: ucp_master_host }
+            $node_metadata: { get_param: metadata }
 
   server:
     type: OS::Nova::Server
@@ -90,6 +91,9 @@
   server_private_ip:
     description: IP address of server in private network
     value: { get_attr: [ server_port, fixed_ips, 0, ip_address] }
+  server_private_floating_ip:
+    description: IP address of server in private floating network
+    value: { get_attr: [server, networks, { get_param: private_floating_network }, 0]}
   server_public_ip:
     description: Floating IP address of server in public network
     value: { get_attr: [ server_floating_ip, floating_ip_address ] }
diff --git a/de/heat-templates/top.yaml b/de/heat-templates/top.yaml
index f6a5e6f..b0ce896 100644
--- a/de/heat-templates/top.yaml
+++ b/de/heat-templates/top.yaml
@@ -195,3 +195,6 @@
   gtws_ips:
     description: Private IP addresses of the deployed gtw instances
     value: { get_attr: [gtws, server_public_ip] }
+  worker_private_floating_ips:
+    description: IPs might be used as gateway
+    value: { get_attr: [workers, server_private_floating_ip] }