Configure LVM on compute nodes

This patch configures LVM on compute nodes
using loop device

Related-PROD: PRODX-11806
Change-Id: I975b7a1d8be37dd019434cf894ad624d5149a209
diff --git a/de/heat-templates/fragments/SrvInstancesVMCephOSD.yaml b/de/heat-templates/fragments/SrvInstancesVMCephOSD.yaml
index 157cdff..434032f 100644
--- a/de/heat-templates/fragments/SrvInstancesVMCephOSD.yaml
+++ b/de/heat-templates/fragments/SrvInstancesVMCephOSD.yaml
@@ -103,6 +103,9 @@
     description: Comma separated list of IP of BGP neighbors
     default: ''
     type: string
+  lvm_loop_device_size:
+    type: number
+    default: 0
 
 resources:
 
@@ -141,6 +144,7 @@
             $huge_pages: { get_param: huge_pages }
             $tungstenfabric_enabled: { get_param: tungstenfabric_enabled }
             $frr_bgp_neighbors: { get_param: frr_bgp_neighbors }
+            $lvm_loop_device_size: { get_param: lvm_loop_device_size }
 
   inject_files:
     type: "OS::Heat::CloudConfig"
diff --git a/de/heat-templates/scripts/instance_boot.sh b/de/heat-templates/scripts/instance_boot.sh
index acc90f2..5695bee 100644
--- a/de/heat-templates/scripts/instance_boot.sh
+++ b/de/heat-templates/scripts/instance_boot.sh
@@ -45,6 +45,7 @@
 TUNGSTENFABRIC_ENABLED=$tungstenfabric_enabled
 SINGLE_NODE=$single_node
 DOCKER_DEFAULT_ADDRESS_POOL=$docker_default_address_pool
+LVM_LOOP_DEVICE_SIZE=$lvm_loop_device_size
 #
 # End of block
 #
@@ -100,6 +101,8 @@
 FRR_EVPN_TUNNELS_RANGE=${FRR_EVPN_TUNNELS_RANGE:-'20 50'}
 FRR_EVPN_VXLAN_DST_PORT=${FRR_EVPN_VXLAN_DST_PORT:-4790}
 
+LVM_LOOP_DEVICE_SIZE=${LVM_LOOP_DEVICE_SIZE:-0}
+
 function retry {
     local retries=$1
     shift
@@ -176,6 +179,34 @@
     systemctl restart iscsid
 }
 
+function configure_lvm {
+    #configure lvm only on compute nodes
+    if [[ ${NODE_METADATA} == *"openstack-compute-node"* ]]; then
+        truncate --size ${LVM_LOOP_DEVICE_SIZE}G /srv/disk0
+        cat <<EOF > /etc/systemd/system/setup-loopback-loop0.service
+[Unit]
+Description=Setup loop0 device
+DefaultDependencies=no
+After=systemd-udev-settle.service
+Before=lvm2-activation-early.service
+Wants=systemd-udev-settle.service
+
+[Service]
+ExecStart=-/sbin/losetup /dev/loop0 /srv/disk0
+RemainAfterExit=true
+Type=oneshot
+
+[Install]
+WantedBy=local-fs.target
+EOF
+        systemctl start setup-loopback-loop0
+        #adding short sleep to give time for service to start
+        sleep 3
+        pvcreate /dev/loop0
+        vgcreate nova-vg /dev/loop0
+    fi
+}
+
 function install_docker {
     function install_retry {
         curl --retry 6 --retry-delay 5 -fsSL "${DOCKER_URL}/gpg" | sudo apt-key add -
@@ -877,6 +908,9 @@
         configure_contrack
         disable_iptables_for_bridges
         collect_interfaces_metadata
+        if [[ "${LVM_LOOP_DEVICE_SIZE}" -gt 0 ]]; then
+            configure_lvm
+        fi
         ;;
     spare)
         prepare_metadata_files
diff --git a/de/heat-templates/top.yaml b/de/heat-templates/top.yaml
index 8d4a3d0..5a0ab27 100644
--- a/de/heat-templates/top.yaml
+++ b/de/heat-templates/top.yaml
@@ -291,6 +291,16 @@
   vsrx_flavor:
     type: string
     default: oc_vsrx
+  cmp_lvm_loop_device_size:
+    description: >
+      The size of loop device for computes to configure LVM on, in gigabytes
+    type: number
+    default: 20
+  acmp_lvm_loop_device_size:
+    description: >
+      The size of loop device for advanced computes to configure LVM on, in gigabytes
+    type: number
+    default: 0
 
 conditions:
   aio_deploy:
@@ -455,6 +465,7 @@
           tun_network: { get_attr: [tun_network, tun_network_id] }
           tun_subnet_id: { get_attr: [tun_network, tun_subnet_id] }
           hardware_metadata: { get_param: hardware_metadata}
+          lvm_loop_device_size: { get_param: cmp_lvm_loop_device_size }
 
   cmps:
     type: OS::Heat::ResourceGroup
@@ -501,6 +512,7 @@
           tun_network: { get_attr: [tun_network, tun_network_id] }
           tun_subnet_id: { get_attr: [tun_network, tun_subnet_id] }
           hardware_metadata: { get_param: hardware_metadata}
+          lvm_loop_device_size: { get_param: cmp_lvm_loop_device_size }
 
   acmps:
     type: OS::Heat::ResourceGroup
@@ -548,6 +560,7 @@
           tun_subnet_id: { get_attr: [tun_network, tun_subnet_id] }
           hardware_metadata: { get_param: hardware_metadata}
           huge_pages: { get_param: huge_pages }
+          lvm_loop_device_size: { get_param: acmp_lvm_loop_device_size }
 
   gtws:
     type: OS::Heat::ResourceGroup