Add template with contrail support
PRODX-2628

Change-Id: I9a9e5171b9f44d8e82f51f4ce07146bf0b03a0cb
diff --git a/de/heat-templates/env/mstr3-wrkr3-cmp2-lma3-osd3-ntw3.yaml b/de/heat-templates/env/mstr3-wrkr3-cmp2-lma3-osd3-ntw3.yaml
new file mode 100644
index 0000000..cd6e9d9
--- /dev/null
+++ b/de/heat-templates/env/mstr3-wrkr3-cmp2-lma3-osd3-ntw3.yaml
@@ -0,0 +1,69 @@
+resource_registry:
+  "MCP2::NetworkAcc": ../fragments/NetworkAccVM.yaml
+  "MCP2::NetworkPrvFl": ../fragments/NetworkPrvFl.yaml
+  "MCP2::SrvInstances": ../fragments/SrvInstancesVM.yaml
+
+parameters:
+  image: bionic-server-cloudimg-amd64-20190612
+  ucp_flavor: system.compact.openstack.control
+  masters_flavor: system.compact.openstack.control
+  workers_flavor: system.compact.openstack.control
+  cmps_flavor: system.virtual.openstack.compute
+  lmas_flavor: system.compact.stacklight.server
+  osds_flavor: system.virtual.ceph.osd
+  ntws_flavor: system.compact.opencontrail.control
+  public_net_id: public
+  host_interface: 'ens3'
+  masters_size: 2
+  worker_size: 3
+  cmp_size: 2
+  lma_size: 3
+  osd_size: 3
+  ntw_size: 3
+  ucp_boot_timeout: 1200
+  cluster_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCp0evjOaK8c8SKYK4r2+0BN7g+8YSvQ2n8nFgOURCyvkJqOHi1qPGZmuN0CclYVdVuZiXbWw3VxRbSW3EH736VzgY1U0JmoTiSamzLHaWsXvEIW8VCi7boli539QJP0ikJiBaNAgZILyCrVPN+A6mfqtacs1KXdZ0zlMq1BPtFciR1JTCRcVs5vP2Wwz5QtY2jMIh3aiwkePjMTQPcfmh1TkOlxYu5IbQyZ3G1ahA0mNKI9a0dtF282av/F6pwB/N1R1nEZ/9VtcN2I1mf1NW/tTHEEcTzXYo1R/8K9vlqAN8QvvGLZtZduGviNVNoNWvoxaXxDt8CPv2B2NCdQFZp
+  private_floating_network_cidr: '10.11.12.0/24'
+  private_floating_interface: 'ens4'
+  worker_metadata: {"labels": {"openstack-control-plane": "enabled", "openvswitch": "enabled"}}
+  cmp_metadata: {"labels": {"openstack-compute-node": "enabled", "tfvrouter": "enabled"}}
+  lma_metadata: {"labels": {"role": "stacklight", "stacklight": "enabled"}}
+  osd_metadata: {"labels": {"role": "ceph-osd-node"}}
+  ntw_metadata: {"labels": {"tfanalytics": "enabled", "tfconfig": "enabled", "tfcontrol": "enabled", "tfwebui": "enabled", "tfconfigdb": "enabled", "tfanalyticsdb": "enabled"}}
+  functions_override: |
+    function network_config {
+        PUBLIC_NODE_IP_ADDRESS=${PUBLIC_INTERFACE_IP:-$(ip addr show dev ${PUBLIC_INTERFACE} | grep -Po 'inet \K[\d.]+' | egrep -v "127.0.|172.17")}
+        PUBLIC_NODE_IP_NETMASK=${PUBLIC_INTERFACE_NETMASK:-$(ip addr show dev ${PUBLIC_INTERFACE} | grep -Po 'inet \K[\d.]+\/[\d]+' | egrep -v "127.0.|172.17" | cut -d'/' -f2)}
+
+        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
+    }
diff --git a/de/heat-templates/top.yaml b/de/heat-templates/top.yaml
index 0001cc2..53fe0ba 100644
--- a/de/heat-templates/top.yaml
+++ b/de/heat-templates/top.yaml
@@ -37,6 +37,10 @@
     type: number
     description: Number of gtw workers to deploy
     default: 0
+  ntw_size:
+    type: number
+    description: Number of contrail nodes to deploy
+    default: 0
   ucp_boot_timeout:
     type: number
     description: Boot timeout for UCP instance
@@ -73,6 +77,9 @@
   osd_metadata:
     type: json
     default: {}
+  ntw_metadata:
+    type: json
+    default: {}
   ucp_flavor:
     type: string
     default: 'system.compact.openstack.control'
@@ -94,6 +101,9 @@
   osds_flavor:
     type: string
     default: 'system.compact.openstack.control'
+  ntws_flavor:
+    type: string
+    default: 'system.compact.openstack.control'
   functions_override:
     type: string
   docker_ee_url:
@@ -307,6 +317,33 @@
           ucp_master_host: { get_attr: [ucp, server_private_ip] }
           functions_override: { get_param: functions_override }
 
+  ntws:
+    type: OS::Heat::ResourceGroup
+    depends_on:
+     - ucp
+    properties:
+      count: { get_param: ntw_size }
+      resource_def:
+        type: MCP2::SrvInstances
+        properties:
+          metadata: { get_param: ntw_metadata }
+          node_type: "worker"
+          key_name: { get_param: "OS::stack_name" }
+          image: { get_param: image }
+          flavor: { get_param: ntws_flavor }
+          docker_ee_url: { get_param: docker_ee_url }
+          docker_ee_release: { get_param: docker_ee_release }
+          accessible_network: { get_attr: [accessible_network, public_network] }
+          private_floating_network: { get_attr: [private_floating_network, private_floating_network_id] }
+          private_floating_subnet_id: { get_attr: [private_floating_network, private_floating_subnet_id] }
+          private_floating_interface: { get_param: private_floating_interface }
+          private_floating_network_cidr: { get_param: private_floating_network_cidr }
+          accessible_subnet_id: { get_attr: [accessible_network, accessible_subnet_id]}
+          public_net_id: { get_param: public_net_id }
+          host_interface: { get_param: host_interface }
+          ucp_master_host: { get_attr: [ucp, server_private_ip] }
+          functions_override: { get_param: functions_override }
+
 outputs:
   ucp_ips:
     description: Private IP addresses of the deployed ucp instances
@@ -329,6 +366,9 @@
   osds_ips:
     description: Private IP addresses of the deployed osd instances
     value: { get_attr: [osds, server_public_ip] }
+  ntws_ips:
+    description: Private IP addresses of the deployed contrail instances
+    value: { get_attr: [ntws, server_public_ip] }
   worker_private_floating_ips:
     description: IPs might be used as gateway
     value: { get_attr: [workers, server_private_floating_ip] }