From 45bde4b9b34a94648cd62027a4b3d4e59cc9609a Mon Sep 17 00:00:00 2001
From: Jim Rollenhagen <jim@jimrollenhagen.com>
Date: Thu, 27 Dec 2018 13:56:51 -0500
Subject: [PATCH] Allow cinder services to use independent hostnames

This allows cinder service endpoints to use custom hostnames, and adds the
following variables:

* cinder_internal_fqdn
* cinder_external_fqdn

These default to the old values of kolla_internal_fqdn or
kolla_external_fqdn.

This also adds a cinder_api_listen_port option, which defaults to
cinder_api_port for backward compatibility.

This option allow the user to differentiate between the port the
service listens on, and the port the service is reachable on. This is
useful for external load balancers which live on the same host as the
service itself.

Change-Id: I2a5036456afac6135dca3723ae754ea9f8bc8475
Implements: blueprint service-hostnames
---
 ansible/group_vars/all.yml                         |  3 +++
 ansible/roles/cinder/defaults/main.yml             | 14 ++++++++------
 ansible/roles/cinder/tasks/precheck.yml            |  2 +-
 ansible/roles/cinder/templates/cinder-wsgi.conf.j2 |  4 ++--
 ansible/roles/cinder/templates/cinder.conf.j2      |  2 +-
 5 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index df35e488e7..4d507c087e 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -190,7 +190,10 @@ barbican_api_port: "9311"
 
 blazar_api_port: "1234"
 
+cinder_internal_fqdn: "{{ kolla_internal_fqdn }}"
+cinder_external_fqdn: "{{ kolla_external_fqdn }}"
 cinder_api_port: "8776"
+cinder_api_listen_port: "{{ cinder_api_port }}"
 
 congress_api_port: "1789"
 
diff --git a/ansible/roles/cinder/defaults/main.yml b/ansible/roles/cinder/defaults/main.yml
index 2463d6801b..473c282104 100644
--- a/ansible/roles/cinder/defaults/main.yml
+++ b/ansible/roles/cinder/defaults/main.yml
@@ -19,11 +19,13 @@ cinder_services:
         mode: "http"
         external: false
         port: "{{ cinder_api_port }}"
+        listen_port: "{{ cinder_api_listen_port }}"
       cinder_api_external:
         enabled: "{{ enable_cinder }}"
         mode: "http"
         external: true
         port: "{{ cinder_api_port }}"
+        listen_port: "{{ cinder_api_listen_port }}"
   cinder-scheduler:
     container_name: cinder_scheduler
     group: cinder-scheduler
@@ -153,12 +155,12 @@ cinder_volume_dimensions: "{{ default_container_dimensions }}"
 ####################
 # OpenStack
 ####################
-cinder_v2_admin_endpoint: "{{ admin_protocol }}://{{ kolla_internal_fqdn }}:{{ cinder_api_port }}/v2/%(tenant_id)s"
-cinder_v2_internal_endpoint: "{{ internal_protocol }}://{{ kolla_internal_fqdn }}:{{ cinder_api_port }}/v2/%(tenant_id)s"
-cinder_v2_public_endpoint: "{{ public_protocol }}://{{ kolla_external_fqdn }}:{{ cinder_api_port }}/v2/%(tenant_id)s"
-cinder_v3_admin_endpoint: "{{ admin_protocol }}://{{ kolla_internal_fqdn }}:{{ cinder_api_port }}/v3/%(tenant_id)s"
-cinder_v3_internal_endpoint: "{{ internal_protocol }}://{{ kolla_internal_fqdn }}:{{ cinder_api_port }}/v3/%(tenant_id)s"
-cinder_v3_public_endpoint: "{{ public_protocol }}://{{ kolla_external_fqdn }}:{{ cinder_api_port }}/v3/%(tenant_id)s"
+cinder_v2_admin_endpoint: "{{ admin_protocol }}://{{ cinder_internal_fqdn }}:{{ cinder_api_port }}/v2/%(tenant_id)s"
+cinder_v2_internal_endpoint: "{{ internal_protocol }}://{{ cinder_internal_fqdn }}:{{ cinder_api_port }}/v2/%(tenant_id)s"
+cinder_v2_public_endpoint: "{{ public_protocol }}://{{ cinder_external_fqdn }}:{{ cinder_api_port }}/v2/%(tenant_id)s"
+cinder_v3_admin_endpoint: "{{ admin_protocol }}://{{ cinder_internal_fqdn }}:{{ cinder_api_port }}/v3/%(tenant_id)s"
+cinder_v3_internal_endpoint: "{{ internal_protocol }}://{{ cinder_internal_fqdn }}:{{ cinder_api_port }}/v3/%(tenant_id)s"
+cinder_v3_public_endpoint: "{{ public_protocol }}://{{ cinder_external_fqdn }}:{{ cinder_api_port }}/v3/%(tenant_id)s"
 
 cinder_logging_debug: "{{ openstack_logging_debug }}"
 
diff --git a/ansible/roles/cinder/tasks/precheck.yml b/ansible/roles/cinder/tasks/precheck.yml
index 060fe0cbd6..b49a6f47bb 100644
--- a/ansible/roles/cinder/tasks/precheck.yml
+++ b/ansible/roles/cinder/tasks/precheck.yml
@@ -8,7 +8,7 @@
 - name: Checking free port for Cinder API
   wait_for:
     host: "{{ api_interface_address }}"
-    port: "{{ cinder_api_port }}"
+    port: "{{ cinder_api_listen_port }}"
     connect_timeout: 1
     timeout: 1
     state: stopped
diff --git a/ansible/roles/cinder/templates/cinder-wsgi.conf.j2 b/ansible/roles/cinder/templates/cinder-wsgi.conf.j2
index a514fefa16..224b07f137 100644
--- a/ansible/roles/cinder/templates/cinder-wsgi.conf.j2
+++ b/ansible/roles/cinder/templates/cinder-wsgi.conf.j2
@@ -1,11 +1,11 @@
 {% set python_path = '/usr/lib/python2.7/site-packages' if cinder_install_type == 'binary' else '/var/lib/kolla/venv/lib/python2.7/site-packages' %}
-Listen {{ api_interface_address }}:{{ cinder_api_port }}
+Listen {{ api_interface_address }}:{{ cinder_api_listen_port }}
 
 ServerSignature Off
 ServerTokens Prod
 TraceEnable off
 
-<VirtualHost *:{{ cinder_api_port }}>
+<VirtualHost *:{{ cinder_api_listen_port }}>
     WSGIDaemonProcess cinder-api processes={{ openstack_service_workers }} threads=1 user=cinder group=cinder display-name=%{GROUP} python-path={{ python_path }}
     WSGIProcessGroup cinder-api
     WSGIScriptAlias / /var/www/cgi-bin/cinder/cinder-wsgi
diff --git a/ansible/roles/cinder/templates/cinder.conf.j2 b/ansible/roles/cinder/templates/cinder.conf.j2
index eb9491eb1d..6eef0f113c 100644
--- a/ansible/roles/cinder/templates/cinder.conf.j2
+++ b/ansible/roles/cinder/templates/cinder.conf.j2
@@ -51,7 +51,7 @@ backup_swift_key =
 {% endif %}
 
 osapi_volume_listen = {{ api_interface_address }}
-osapi_volume_listen_port = {{ cinder_api_port }}
+osapi_volume_listen_port = {{ cinder_api_listen_port }}
 
 api_paste_config = /etc/cinder/api-paste.ini