From f692b4c9ac81e409a90a4cb49dc6fa52e5f2752c Mon Sep 17 00:00:00 2001
From: MinSun <minsu@cisco.com>
Date: Thu, 5 Jul 2018 10:16:59 +0800
Subject: [PATCH] Make nova nova_instance_datadir_volume configurable.

User can use custom directory for nova instance.
For example using a shared file system as backend.

Change-Id: I11fe4891719a2e2a34888d8b798df5602e294e4f
---
 ansible/group_vars/all.yml                   | 1 +
 ansible/roles/destroy/tasks/cleanup_host.yml | 1 +
 ansible/roles/nova/defaults/main.yml         | 6 +++---
 tools/cleanup-host                           | 5 +++++
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index bc4302e29a..d817b3c9fb 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -701,6 +701,7 @@ nova_backend_ceph: "{{ enable_ceph }}"
 nova_backend: "{{ 'rbd' if nova_backend_ceph | bool else 'default' }}"
 # Valid options are [ kvm, qemu, vmware, xenapi ]
 nova_compute_virt_type: "kvm"
+nova_instance_datadir_volume: "nova_compute"
 
 #######################
 # Murano options
diff --git a/ansible/roles/destroy/tasks/cleanup_host.yml b/ansible/roles/destroy/tasks/cleanup_host.yml
index e36791059d..b1ae71d20c 100644
--- a/ansible/roles/destroy/tasks/cleanup_host.yml
+++ b/ansible/roles/destroy/tasks/cleanup_host.yml
@@ -6,6 +6,7 @@
     enable_haproxy: "{{ enable_haproxy }}"
     enable_swift: "{{ enable_swift }}"
     glance_file_datadir_volume: "{{ glance_file_datadir_volume }}"
+    nova_instance_datadir_volume: "{{ nova_instance_datadir_volume }}"
     kolla_internal_vip_address: "{{ kolla_internal_vip_address }}"
     kolla_external_vip_address: "{{ kolla_external_vip_address }}"
     kolla_dev_repos_directory: "{{ kolla_dev_repos_directory }}"
diff --git a/ansible/roles/nova/defaults/main.yml b/ansible/roles/nova/defaults/main.yml
index 4bdd3fe0d9..5963a0efa2 100644
--- a/ansible/roles/nova/defaults/main.yml
+++ b/ansible/roles/nova/defaults/main.yml
@@ -18,7 +18,7 @@ nova_services:
       - "/sys/fs/cgroup:/sys/fs/cgroup"
       - "kolla_logs:/var/log/kolla/"
       - "libvirtd:/var/lib/libvirt"
-      - "nova_compute:/var/lib/nova/"
+      - "{{ nova_instance_datadir_volume }}:/var/lib/nova/"
       - "{% if enable_cinder_backend_nfs | bool %}/var/lib/nova/mnt:/var/lib/nova/mnt:shared{% endif %}"
       - "nova_libvirt_qemu:/etc/libvirt/qemu"
   nova-ssh:
@@ -30,7 +30,7 @@ nova_services:
       - "{{ node_config_directory }}/nova-ssh/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla"
-      - "nova_compute:/var/lib/nova"
+      - "{{ nova_instance_datadir_volume }}:/var/lib/nova"
       - "{% if enable_cinder_backend_nfs | bool %}/var/lib/nova/mnt:/var/lib/nova/mnt:shared{% endif %}"
   placement-api:
     container_name: "placement_api"
@@ -124,7 +124,7 @@ nova_services:
       - "kolla_logs:/var/log/kolla/"
       - "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}"
       - "libvirtd:/var/lib/libvirt"
-      - "nova_compute:/var/lib/nova/"
+      - "{{ nova_instance_datadir_volume }}:/var/lib/nova/"
       - "{% if enable_cinder_backend_nfs | bool %}/var/lib/nova/mnt:/var/lib/nova/mnt:shared{% endif %}"
   nova-compute-ironic:
     container_name: "nova_compute_ironic"
diff --git a/tools/cleanup-host b/tools/cleanup-host
index d9ea768087..10a952a1b3 100755
--- a/tools/cleanup-host
+++ b/tools/cleanup-host
@@ -56,6 +56,11 @@ if [[ "$glance_file_datadir_volume" != "glance" && -d "$glance_file_datadir_volu
     rm -rfv  $glance_file_datadir_volume
 fi
 
+if [[ "$nova_instance_datadir_volume" != "nova_compute" && -d "$nova_instance_datadir_volume" ]]; then
+    echo "Removing nova_compute volume if it is customzied"
+    rm -rfv  $nova_instance_datadir_volume
+fi
+
 FOLDER_PATH="/etc/kolla/"
 
 if [[ -e "$FOLDER_PATH/ovsdpdk-db/ovs-dpdkctl.sh" ]]; then