Add cmps and storage network settings for SI MOCK lab

- if the network with CONTROL_NETWORK_CIDR is not
  configured at the start of the script, CONTROL_IP_ADDRESS
  got the 'src' instead of IP address because:

    $ ip route get ${CONTROL_NETWORK_CIDR%/*}
    172.16.51.0 via 172.16.50.1 dev enp8s0f0 src 172.16.50.21 uid 0

  Ensure that the CONTROL_IP_ADDRESS will be empty in case
  if control network is not configured yet (no 'via' in the route).

  Fail in case

- split the function "prepare_metadata_files" on two functions:
  "prepare_metadata_files" and "collect_ceph_metadata"

- "prepare_metadata_files" function should be executed
  at the very beginning to prepare configs before
  any other service is set up

- "network_config" function must be executed right after
  "prepare_metadata_files" to initialize the correct
  CONTROL_IP_ADDRESS in case if this address is not from
  the PXE interface and is not available until network
  configuration is completed

- add "disable-rp-filter" function to allow different
  networks on the same node

https: //mirantis.jira.com/browse/PRODX-2630
Change-Id: I9f28f8f4b60efce64eecf7eb70cf75746892424e
diff --git a/de/heat-templates/env/bmt410-mstr3-wrkr3-cmp0-gtw0-osd3.yaml b/de/heat-templates/env/bmt410-mstr3-wrkr3-cmp0-gtw0-osd3.yaml
index ec785e9..bb1ffb3 100644
--- a/de/heat-templates/env/bmt410-mstr3-wrkr3-cmp0-gtw0-osd3.yaml
+++ b/de/heat-templates/env/bmt410-mstr3-wrkr3-cmp0-gtw0-osd3.yaml
@@ -11,14 +11,14 @@
   ucp_flavor: si-bm-410-128-16-hdd0-ssd2x1t
   masters_flavor: si-bm-410-128-16-hdd0-ssd2x1t
   workers_flavor: si-bm-410-128-32-hdd0-ssd2x1t
-  cmps_flavor: oscore-bm-lab-01
+  cmps_flavor: si-bm-410-128-16-hdd0-ssd1x500g
   gtws_flavor: oscore-bm-lab-01
   lmas_flavor: oscore-bm-lab-01
   osds_flavor: si-bm-410-64-16-hdd2x2t-ssd1x500g
   spares_flavor: si-bm-410-64-16-hdd2x2t-ssd1x500g
   masters_size: 2  # UCP nodes
   worker_size: 3  # OpenStack controller nodes
-  cmp_size: 0
+  cmp_size: 3
   gtw_size: 0
   lma_size: 0
   osd_size: 3
@@ -26,18 +26,23 @@
   ucp_boot_timeout: 1200
   cluster_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCp0evjOaK8c8SKYK4r2+0BN7g+8YSvQ2n8nFgOURCyvkJqOHi1qPGZmuN0CclYVdVuZiXbWw3VxRbSW3EH736VzgY1U0JmoTiSamzLHaWsXvEIW8VCi7boli539QJP0ikJiBaNAgZILyCrVPN+A6mfqtacs1KXdZ0zlMq1BPtFciR1JTCRcVs5vP2Wwz5QtY2jMIh3aiwkePjMTQPcfmh1TkOlxYu5IbQyZ3G1ahA0mNKI9a0dtF282av/F6pwB/N1R1nEZ/9VtcN2I1mf1NW/tTHEEcTzXYo1R/8K9vlqAN8QvvGLZtZduGviNVNoNWvoxaXxDt8CPv2B2NCdQFZp
   public_net_id: 'physnet1-410'
-  control_network_cidr: '172.16.50.0/25'
+  control_network_cidr: '172.16.50.128/25'
   private_floating_network_cidr: '172.16.51.0/25'
   private_floating_network_pool_start: '172.16.51.10'
   private_floating_network_pool_end: '172.16.51.30'
   private_floating_network_ipam_pool_start: '172.16.51.31'
   private_floating_network_ipam_pool_end: '172.16.51.62'
   private_floating_network_gateway: '172.16.51.1'
+  metallb_address_pools: [ '172.16.51.130-172.16.51.250' ]
   private_floating_interface: 'os-floating'
+  storage_frontend_interface: 'ceph-control'
+  storage_backend_interface: 'ceph-replica'
   tunnel_interface: 'os-tenant'
   live_migration_interface: 'os-tenant'
-  #master_metadata: {"labels": {"role": "stacklight", "stacklight": "enabled"}}
-  worker_metadata: {"labels": {"openstack-control-plane":"enabled", "openstack-compute-node":"enabled", "openvswitch":"enabled", "gateway": "enabled"}}
+  ucp_metadata: {"role":"ucp", "labels": {"role": "stacklight", "stacklight": "enabled"}}
+  master_metadata: {"role":"master", "labels": {"role": "stacklight", "stacklight": "enabled"}}
+  worker_metadata: {"labels": {"openstack-control-plane":"enabled", "openvswitch":"enabled", "openstack-gateway": "enabled"}}
+  cmp_metadata: {"labels": {"openstack-compute-node":"enabled","openvswitch":"enabled"}}
   osd_metadata: {"labels": {"role": "ceph-osd-node"}}
   spare_metadata: {"labels": {"role": "spare-node"}}
 
@@ -45,7 +50,7 @@
   hardware_metadata: |
     '0c:c4:7a:33:26:7c':
       write_files:
-      - path: '/etc/netplan/99-cz7714.yaml'
+      - path: '/etc/netplan/99-cz7714-osd.yaml'
         content: |
           network:
             version: 2
@@ -75,25 +80,36 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.130/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
+              ceph-replica:
+                id: 417
+                link: bond1
+                addresses:
+                - {{ STORAGE_BACKEND_INTERFACE_IP }}/{{ STORAGE_BACKEND_NETWORK_NETMASK }}
 
     '0c:c4:7a:33:26:6e':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz7725-osd.yaml'
         content: |
           network:
             version: 2
@@ -123,25 +139,36 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.131/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
+              ceph-replica:
+                id: 417
+                link: bond1
+                addresses:
+                - {{ STORAGE_BACKEND_INTERFACE_IP }}/{{ STORAGE_BACKEND_NETWORK_NETMASK }}
 
     '0c:c4:7a:33:26:6a':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz7726-osd.yaml'
         content: |
           network:
             version: 2
@@ -171,25 +198,36 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.132/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
+              ceph-replica:
+                id: 417
+                link: bond1
+                addresses:
+                - {{ STORAGE_BACKEND_INTERFACE_IP }}/{{ STORAGE_BACKEND_NETWORK_NETMASK }}
 
     '0c:c4:7a:34:92:94':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz7727-spare.yaml'
         content: |
           network:
             version: 2
@@ -219,25 +257,36 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.133/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
+              ceph-replica:
+                id: 417
+                link: bond1
+                addresses:
+                - {{ STORAGE_BACKEND_INTERFACE_IP }}/{{ STORAGE_BACKEND_NETWORK_NETMASK }}
 
     '0c:c4:7a:aa:e0:9e':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz10095-os-control.yaml'
         content: |
           network:
             version: 2
@@ -267,25 +316,31 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.134/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
 
     '0c:c4:7a:aa:e0:9c':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz10096-os-control.yaml'
         content: |
           network:
             version: 2
@@ -315,25 +370,31 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.135/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
 
     '0c:c4:7a:aa:78:2c':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz10097-os-control.yaml'
         content: |
           network:
             version: 2
@@ -363,25 +424,31 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.136/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
 
     '0c:c4:7a:aa:78:7a':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz10098-ucp-control.yaml'
         content: |
           network:
             version: 2
@@ -411,25 +478,24 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                # Hardcoded IP for the UCP node (when UCP_MASTER_HOST is empty), to replace PXE with k8s_control IP
+                - {% if UCP_MASTER_HOST == "" %}172.16.50.254/25{% else %}172.16.50.137/25{% endif %}
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
-                id: 415
-                link: bond1
-              os-tenant:
-                id: 416
-                link: bond1
 
     '0c:c4:7a:aa:e0:98':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz10099-ucp-control.yaml'
         content: |
           network:
             version: 2
@@ -459,47 +525,147 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                # Hardcoded IP for the UCP node (when UCP_MASTER_HOST is empty), to replace PXE with k8s_control IP
+                - {% if UCP_MASTER_HOST == "" %}172.16.50.254/25{% else %}172.16.50.138/25{% endif %}
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+
+    '0c:c4:7a:aa:78:7c':
+      write_files:
+      - path: '/etc/netplan/99-cz10100-ucp-control.yaml'
+        content: |
+          network:
+            version: 2
+            ethernets:
+              eno1:
+                dhcp4: false
+              ens4f1:
+                dhcp4: false
+              ens4f2:
+                dhcp4: false
+              ens4f3:
+                dhcp4: false
+            bonds:
+              bond0:
+                dhcp4: no
+                interfaces: [eno1, ens4f1]
+                parameters:
+                  mode: active-backup
+                  mii-monitor-interval: 1
+              bond1:
+                dhcp4: no
+                interfaces: [ens4f2, ens4f3]
+                parameters:
+                  mode: active-backup
+                  mii-monitor-interval: 1
+            vlans:
+              k8s-control:
+                id: 411
+                link: bond0
+                addresses:
+                # Hardcoded IP for the UCP node (when UCP_MASTER_HOST is empty), to replace PXE with k8s_control IP
+                - {% if UCP_MASTER_HOST == "" %}172.16.50.254/25{% else %}172.16.50.139/25{% endif %}
+              os-floating:
+                id: 412
+                link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
+              k8s-metallb:
+                id: 413
+                link: bond0
+              management:
+                id: 414
+                link: bond0
+
+    '0c:c4:7a:55:6a:28':
+      write_files:
+      - path: '/etc/netplan/99-cz7636-os-compute.yaml'
+        content: |
+          network:
+            version: 2
+            ethernets:
+              enp3s0f0:
+                dhcp4: false
+              enp3s0f1:
+                dhcp4: false
+              enp3s0f2:
+                dhcp4: false
+              enp3s0f3:
+                dhcp4: false
+            bonds:
+              bond0:
+                dhcp4: no
+                interfaces: [enp3s0f0, enp3s0f1]
+                parameters:
+                  mode: active-backup
+                  mii-monitor-interval: 1
+              bond1:
+                dhcp4: no
+                interfaces: [enp3s0f2, enp3s0f3]
+                parameters:
+                  mode: active-backup
+                  mii-monitor-interval: 1
+            vlans:
+              k8s-control:
+                id: 411
+                link: bond0
+                addresses:
+                - 172.16.50.140/25
+              os-floating:
+                id: 412
+                link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
+              k8s-metallb:
+                id: 413
+                link: bond0
+              management:
+                id: 414
+                link: bond0
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
 
-    '0c:c4:7a:aa:78:7c':
+    '0c:c4:7a:54:a2:5e':
       write_files:
-      - path: '/etc/netplan/99-cz7725.yaml'
+      - path: '/etc/netplan/99-cz7641-os-compute.yaml'
         content: |
           network:
             version: 2
             ethernets:
-              eno1:
+              enp3s0f0:
                 dhcp4: false
-              ens4f1:
+              enp3s0f1:
                 dhcp4: false
-              ens4f2:
+              enp3s0f2:
                 dhcp4: false
-              ens4f3:
+              enp3s0f3:
                 dhcp4: false
             bonds:
               bond0:
                 dhcp4: no
-                interfaces: [eno1, ens4f1]
+                interfaces: [enp3s0f0, enp3s0f1]
                 parameters:
                   mode: active-backup
                   mii-monitor-interval: 1
               bond1:
                 dhcp4: no
-                interfaces: [ens4f2, ens4f3]
+                interfaces: [enp3s0f2, enp3s0f3]
                 parameters:
                   mode: active-backup
                   mii-monitor-interval: 1
@@ -507,22 +673,83 @@
               k8s-control:
                 id: 411
                 link: bond0
+                addresses:
+                - 172.16.50.141/25
               os-floating:
                 id: 412
                 link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
               k8s-metallb:
                 id: 413
                 link: bond0
-              k8s-dataplane:
+              management:
                 id: 414
                 link: bond0
-              os-storage:
+              ceph-control:
                 id: 415
                 link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
               os-tenant:
                 id: 416
                 link: bond1
 
+    '0c:c4:7a:54:a0:50':
+      write_files:
+      - path: '/etc/netplan/99-cz7642-os-compute.yaml'
+        content: |
+          network:
+            version: 2
+            ethernets:
+              enp3s0f0:
+                dhcp4: false
+              enp3s0f1:
+                dhcp4: false
+              enp3s0f2:
+                dhcp4: false
+              enp3s0f3:
+                dhcp4: false
+            bonds:
+              bond0:
+                dhcp4: no
+                interfaces: [enp3s0f0, enp3s0f1]
+                parameters:
+                  mode: active-backup
+                  mii-monitor-interval: 1
+              bond1:
+                dhcp4: no
+                interfaces: [enp3s0f2, enp3s0f3]
+                parameters:
+                  mode: active-backup
+                  mii-monitor-interval: 1
+            vlans:
+              k8s-control:
+                id: 411
+                link: bond0
+                addresses:
+                - 172.16.50.142/25
+              os-floating:
+                id: 412
+                link: bond1
+                addresses:
+                - {{ PUBLIC_INTERFACE_IP }}/{{ PUBLIC_INTERFACE_NETMASK }}
+              k8s-metallb:
+                id: 413
+                link: bond0
+              management:
+                id: 414
+                link: bond0
+              ceph-control:
+                id: 415
+                link: bond1
+                addresses:
+                - {{ STORAGE_FRONTEND_INTERFACE_IP }}/{{ STORAGE_FRONTEND_NETWORK_NETMASK }}
+              os-tenant:
+                id: 416
+                link: bond1
+
+
   functions_override: |
 
     function network_config {
@@ -532,5 +759,11 @@
         netplan --debug apply
         sleep 15
 
-        ip a a ${PUBLIC_INTERFACE_IP}/${PUBLIC_INTERFACE_NETMASK} dev ${PUBLIC_INTERFACE}
+        # Re-init the variables related to the just configured k8s-control network
+        CONTROL_IP_ADDRESS=$(ip route get ${CONTROL_NETWORK_CIDR%/*} | head -n1 | fgrep -v ' via ' | awk '/ src / {print $6}')
+
+        #UCP_MASTER_HOST=${UCP_MASTER_HOST:-${CONTROL_IP_ADDRESS}}
+        # Hardcoded IP for the UCP node because the servers output contain PXE IP instead of k8s_control IP
+        UCP_MASTER_HOST=172.16.50.254
+        UCP_IP_ADDRESS=${UCP_IP_ADDRESS:-$CONTROL_IP_ADDRESS}
     }
diff --git a/de/heat-templates/scripts/instance_boot.sh b/de/heat-templates/scripts/instance_boot.sh
index 7a6d8da..1e495e3 100644
--- a/de/heat-templates/scripts/instance_boot.sh
+++ b/de/heat-templates/scripts/instance_boot.sh
@@ -43,7 +43,7 @@
     DOCKER_PACKAGES="${DOCKER_EE_PACKAGES}"
 fi
 CONTROL_NETWORK_CIDR=${CONTROL_NETWORK_CIDR:-"10.10.0.0/24"}
-CONTROL_IP_ADDRESS=$(ip route get ${CONTROL_NETWORK_CIDR%/*} | awk '/ src / {print $6}')
+CONTROL_IP_ADDRESS=$(ip route get ${CONTROL_NETWORK_CIDR%/*} | head -n1 | fgrep -v ' via ' | awk '/ src / {print $6}')
 PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-ens4}
 UCP_USERNAME=${UCP_USERNAME:-admin}
 UCP_PASSWORD=${UCP_PASSWORD:-administrator}
@@ -257,6 +257,11 @@
 }
 
 function prepare_network {
+    if [ -z "${CONTROL_IP_ADDRESS}" ]; then
+        wait_condition_send "FAILURE" "CONTROL_IP_ADDRESS is not found for the network ${CONTROL_NETWORK_CIDR}"
+        exit 1
+    fi
+
     systemctl restart systemd-resolved
     # Make sure local hostname is present in /etc/hosts
     sed -i "s/127.0.0.1 localhost/127.0.0.1 localhost\n${CONTROL_IP_ADDRESS} $(hostname)/" /etc/hosts
@@ -283,6 +288,15 @@
     sudo netfilter-persistent reload
 }
 
+function disable_rp_filter {
+    # Run this func before "network_config" to create new interfaces with the default rp_filter value
+    cat << EOF > /etc/sysctl.d/99-disable-rp-filter.conf
+net.ipv4.conf.all.rp_filter=0
+net.ipv4.conf.default.rp_filter=0
+EOF
+    sysctl -p /etc/sysctl.d/99-disable-rp-filter.conf
+}
+
 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)}
@@ -338,10 +352,13 @@
 # For example netplan.io metadata, the restart of services
 # is not covered by script.
 function prepare_metadata_files {
+    /usr/sbin/prepare-metadata.py  --metadata-file /usr/share/metadata/lab-metadata.yaml
+}
+
+function collect_ceph_metadata {
     local ceph_osd_node
     ceph_osd_node=$(kubectl get nodes -l role=ceph-osd-node -o jsonpath={.items[?\(@.metadata.name==\"$(hostname)\"\)].metadata.name})
 
-    /usr/sbin/prepare-metadata.py  --metadata-file /usr/share/metadata/lab-metadata.yaml
     if [[ -f /usr/share/metadata/ceph.yaml && ${ceph_osd_node} ]]; then
         HW_METADATA="{\"ceph\": {\"$(hostname)\": \"$(base64 -w 0 /usr/share/metadata/ceph.yaml)\"}}"
     fi
@@ -349,13 +366,17 @@
 
 
 case "$NODE_TYPE" in
+    # Please keep the "prepare_metadata_files", "disable-rp-filter", "network_config" and "prepare_network" functions
+    # at the very beginning in the same order.
     ucp)
+        prepare_metadata_files
+        disable_rp_filter
+        network_config
         prepare_network
         update_docker_network
         install_required_packages
         workaround_default_forward_policy
         install_docker
-        network_config
         swarm_init
         create_ucp_config
         install_ucp
@@ -364,43 +385,48 @@
         install_kubectl
         wait_for_node
         set_node_labels
-        prepare_metadata_files
+        collect_ceph_metadata
         ;;
     master)
+        prepare_metadata_files
+        disable_rp_filter
+        network_config
         prepare_network
         update_docker_network
         install_required_packages
         workaround_default_forward_policy
         install_docker
-        network_config
         download_bundles
         join_node manager
         install_kubectl
         wait_for_node
         set_node_labels
-        prepare_metadata_files
+        collect_ceph_metadata
         ;;
     worker)
+        prepare_metadata_files
+        disable_rp_filter
+        network_config
         prepare_network
         update_docker_network
         install_required_packages
         workaround_default_forward_policy
         install_docker
-        network_config
         download_bundles
         join_node worker
         install_kubectl
         wait_for_node
         set_node_labels
-        prepare_metadata_files
+        collect_ceph_metadata
         ;;
     spare)
         prepare_metadata_files
+        disable_rp_filter
+        network_config
         prepare_network
         update_docker_network
         install_required_packages
         install_docker
-        network_config
         download_bundles
         workaround_default_forward_policy
         ;;
diff --git a/de/heat-templates/top.yaml b/de/heat-templates/top.yaml
index 5c3b390..0ce2437 100644
--- a/de/heat-templates/top.yaml
+++ b/de/heat-templates/top.yaml
@@ -87,6 +87,12 @@
   storage_backend_interface:
     type: string
     default: 'ens6'
+  ucp_metadata:
+    type: json
+    default: {"role":"ucp"}
+  master_metadata:
+    type: json
+    default: {"role":"master"}
   worker_metadata:
     type: json
     default: {}
@@ -191,7 +197,7 @@
      - storage_network
     type: MCP2::SrvInstances
     properties:
-      metadata: {"role":"ucp"}
+      metadata: { get_param: ucp_metadata}
       docker_ee_url: { get_param: docker_ee_url }
       docker_ee_release: { get_param: docker_ee_release }
       node_type: "ucp"
@@ -218,7 +224,7 @@
       resource_def:
         type: MCP2::SrvInstances
         properties:
-          metadata: {"role":"master"}
+          metadata: { get_param: master_metadata}
           node_type: "master"
           key_name: { get_param: "OS::stack_name" }
           image: { get_param: image }
@@ -398,14 +404,14 @@
           storage_backend_network_cidr: { get_param: storage_backend_network_cidr }
           hardware_metadata: { get_param: hardware_metadata}
 
-  spares:  # spares for workers
+  spares:  # spares for osds/cmps
     type: OS::Heat::ResourceGroup
     depends_on:
      - ucp
     properties:
       count: { get_param: spare_size }
       resource_def:
-        type: MCP2::SrvInstancesCeph
+        type: MCP2::SrvInstancesCephOSD
         properties:
           metadata: { get_param: spare_metadata }
           node_type: "spare"
@@ -428,6 +434,10 @@
           storage_frontend_network: { get_attr: [storage_network, storage_frontend_network_id] }
           storage_frontend_subnet_id: { get_attr: [storage_network, storage_frontend_subnet_id] }
           storage_frontend_network_cidr: { get_param: storage_frontend_network_cidr }
+          storage_backend_interface: { get_param: storage_backend_interface }
+          storage_backend_network: { get_attr: [storage_network, storage_backend_network_id] }
+          storage_backend_subnet_id: { get_attr: [storage_network, storage_backend_subnet_id] }
+          storage_backend_network_cidr: { get_param: storage_backend_network_cidr }
           hardware_metadata: { get_param: hardware_metadata}
 
   ntws: