From 5f7fdb165695b9717cfae6de6b22b0d7e23c7fc3 Mon Sep 17 00:00:00 2001
From: Pranali Deore <pdeore@redhat.com>
Date: Tue, 2 Jan 2018 10:29:03 +0530
Subject: [PATCH] Add support of netapp configuration for glance in THT

This change adds all the required netapp environment configuartion
for glance in heat template.

Change-Id: Ib44796f77cbc50c3b3c37dcdd37a59f48a7baa1a
Closes-Bug: #1740456
---
 docker/services/glance-api.yaml      | 17 ++++++++++++
 environments/storage/glance-nfs.yaml |  8 ++++++
 puppet/services/glance-api.yaml      | 39 ++++++++++++++++++++++++++++
 sample-env-generator/storage.yaml    |  2 ++
 4 files changed, 66 insertions(+)

diff --git a/docker/services/glance-api.yaml b/docker/services/glance-api.yaml
index b3055ed10d..7c42cc2896 100644
--- a/docker/services/glance-api.yaml
+++ b/docker/services/glance-api.yaml
@@ -61,6 +61,16 @@ parameters:
     description: >
       NFS mount options for image storage (when GlanceNfsEnabled is true)
     type: string
+  GlanceNetappNfsEnabled:
+    default: false
+    description: >
+      When using GlanceBackend 'file', Netapp mount NFS share for image storage.
+    type: boolean
+  NetappShareLocation:
+    default: ''
+    description: >
+      Netapp share to mount for image storage (when GlanceNetappNfsEnabled is true)
+    type: string
   UpgradeRemoveUnusedPackages:
     default: false
     description: Remove package if the service is being disabled during upgrade
@@ -82,6 +92,7 @@ conditions:
 
   internal_tls_enabled: {equals: [{get_param: EnableInternalTLS}, true]}
   nfs_backend_enabled: {equals: [{get_param: GlanceNfsEnabled}, true]}
+  netapp_nfs_backend_enabled: {equals: [{get_param: GlanceNetappNfsEnabled}, true]}
   cinder_backend_enabled: {equals: [{get_param: GlanceBackend}, cinder]}
 
 
@@ -184,6 +195,11 @@ outputs:
                       - nfs_backend_enabled
                       - /var/lib/glance:/var/lib/glance
                       - ''
+                  -
+                    if:
+                      - netapp_nfs_backend_enabled
+                      - /var/lib/glance:/var/lib/glance
+                      - ''
                 -
                   if:
                     - cinder_backend_enabled
@@ -229,6 +245,7 @@ outputs:
       host_prep_tasks:
         list_concat:
         - {get_attr: [GlanceLogging, host_prep_tasks]}
+        - {get_attr: [GlanceApiPuppetBase, role_data, host_prep_tasks]}
         - - name: Mount NFS on host
             vars:
               nfs_backend_enable: {get_param: GlanceNfsEnabled}
diff --git a/environments/storage/glance-nfs.yaml b/environments/storage/glance-nfs.yaml
index f34c6683c2..d4f63964c2 100644
--- a/environments/storage/glance-nfs.yaml
+++ b/environments/storage/glance-nfs.yaml
@@ -9,6 +9,10 @@
 #   Configure and include this environment to enable the use of an NFS
 #   share as the backend for Glance.
 parameter_defaults:
+  # When using GlanceBackend 'file', Netapp mount NFS share for image storage.
+  # Type: boolean
+  GlanceNetappNfsEnabled: False
+
   # NFS mount options for image storage (when GlanceNfsEnabled is true)
   # Type: string
   GlanceNfsOptions: _netdev,bg,intr,context=system_u:object_r:glance_var_lib_t:s0
@@ -17,6 +21,10 @@ parameter_defaults:
   # Type: string
   GlanceNfsShare: ''
 
+  # Netapp share to mount for image storage (when GlanceNetappNfsEnabled is true)
+  # Type: string
+  NetappShareLocation: ''
+
   # ******************************************************
   # Static parameters - these are values that must be
   # included in the environment but should not be changed.
diff --git a/puppet/services/glance-api.yaml b/puppet/services/glance-api.yaml
index 1b23a1b692..4dd720bfd1 100644
--- a/puppet/services/glance-api.yaml
+++ b/puppet/services/glance-api.yaml
@@ -109,6 +109,16 @@ parameters:
     description: >
       NFS share to mount for image storage (when GlanceNfsEnabled is true)
     type: string
+  GlanceNetappNfsEnabled:
+    default: false
+    description: >
+      When using GlanceBackend 'file', Netapp mount NFS share for image storage.
+    type: boolean
+  NetappShareLocation:
+    default: ''
+    description: >
+      Netapp share to mount for image storage (when GlanceNetappNfsEnabled is true)
+    type: string
   GlanceNfsOptions:
     default: '_netdev,bg,intr,context=system_u:object_r:glance_var_lib_t:s0'
     description: >
@@ -302,6 +312,35 @@ outputs:
             - "%{hiera('mysql_bind_host')}"
       step_config: |
         include ::tripleo::profile::base::glance::api
+
+      host_prep_tasks:
+        - name: Mount Netapp NFS
+          vars:
+            netapp_nfs_backend_enable: {get_param: GlanceNetappNfsEnabled}
+          block:
+            - name:
+              set_fact:
+                remote_file_path: /etc/glance/glance-metadata-file.conf
+            - name:
+              file:
+                path: "{{ remote_file_path }}"
+                state: touch
+            - stat: path="{{ remote_file_path }}"
+              register: file_path
+            - copy:
+                content: {"share_location" : "{{item.NETAPP_SHARE}}", "mount_point" : "/var/lib/glance/images", "type" : "nfs",}
+                dest: "{{ remote_file_path }}"
+              with_items:
+                - NETAPP_SHARE: {get_param: NetappShareLocation}
+              when:
+                - file_path.stat.exists == true
+            - name:
+              mount: name=/var/lib/glance/images src="{{item.NETAPP_SHARE}}" fstype=nfs4 opts="{{item.NFS_OPTIONS}}" state=mounted
+              with_items:
+                - NETAPP_SHARE: {get_param: NetappShareLocation}
+                  NFS_OPTIONS: {get_param: GlanceNfsOptions}
+          when: netapp_nfs_backend_enable
+
       upgrade_tasks:
         - name: Check if glance_api is deployed
           command: systemctl is-enabled openstack-glance-api
diff --git a/sample-env-generator/storage.yaml b/sample-env-generator/storage.yaml
index dc4fbb10c6..ec0d070e37 100644
--- a/sample-env-generator/storage.yaml
+++ b/sample-env-generator/storage.yaml
@@ -60,6 +60,8 @@ environments:
           - GlanceNfsEnabled
           - GlanceNfsShare
           - GlanceNfsOptions
+          - GlanceNetappNfsEnabled
+          - NetappShareLocation
     sample_values:
       GlanceBackend: file
       GlanceNfsEnabled: True