From 1ebb1ccee2e40639b9f3d2e2c638f933cad68887 Mon Sep 17 00:00:00 2001
From: Jim Rollenhagen <jim@jimrollenhagen.com>
Date: Thu, 27 Dec 2018 15:41:39 -0500
Subject: [PATCH] Allow aodh services to use independent hostnames

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

* aodh_internal_fqdn
* aodh_external_fqdn

These default to the old values of kolla_internal_fqdn or
kolla_external_fqdn.

This also adds a aodh_api_listen_port option, which defaults to
aodh_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: Iee08b725d066bfbe543d9319c47941d59c22212a
Implements: blueprint service-hostnames
---
 ansible/group_vars/all.yml                     | 3 +++
 ansible/roles/aodh/defaults/main.yml           | 8 +++++---
 ansible/roles/aodh/tasks/precheck.yml          | 2 +-
 ansible/roles/aodh/templates/aodh.conf.j2      | 2 +-
 ansible/roles/aodh/templates/wsgi-aodh.conf.j2 | 4 ++--
 5 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index bc3fa85665..ed80001a05 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -184,7 +184,10 @@ neutron_ipam_driver: "internal"
 
 # The default ports used by each service.
 # The list should be in alphabetical order
+aodh_internal_fqdn: "{{ kolla_internal_fqdn }}"
+aodh_external_fqdn: "{{ kolla_external_fqdn }}"
 aodh_api_port: "8042"
+aodh_api_listen_port: "{{ aodh_api_port }}"
 
 barbican_internal_fqdn: "{{ kolla_internal_fqdn }}"
 barbican_external_fqdn: "{{ kolla_external_fqdn }}"
diff --git a/ansible/roles/aodh/defaults/main.yml b/ansible/roles/aodh/defaults/main.yml
index c23bfe3d07..70b7f45d36 100644
--- a/ansible/roles/aodh/defaults/main.yml
+++ b/ansible/roles/aodh/defaults/main.yml
@@ -20,11 +20,13 @@ aodh_services:
         mode: "http"
         external: false
         port: "{{ aodh_api_port }}"
+        listen_port: "{{ aodh_api_listen_port }}"
       aodh_api_external:
         enabled: "{{ enable_aodh }}"
         mode: "http"
         external: true
         port: "{{ aodh_api_port }}"
+        listen_port: "{{ aodh_api_listen_port }}"
   aodh-evaluator:
     container_name: aodh_evaluator
     group: aodh-evaluator
@@ -116,9 +118,9 @@ aodh_notifier_dimensions: "{{ default_container_dimensions }}"
 ####################
 # OpenStack
 ####################
-aodh_admin_endpoint: "{{ admin_protocol }}://{{ kolla_internal_fqdn }}:{{ aodh_api_port }}"
-aodh_internal_endpoint: "{{ internal_protocol }}://{{ kolla_internal_fqdn }}:{{ aodh_api_port }}"
-aodh_public_endpoint: "{{ public_protocol }}://{{ kolla_external_fqdn }}:{{ aodh_api_port }}"
+aodh_admin_endpoint: "{{ admin_protocol }}://{{ aodh_internal_fqdn }}:{{ aodh_api_port }}"
+aodh_internal_endpoint: "{{ internal_protocol }}://{{ aodh_internal_fqdn }}:{{ aodh_api_port }}"
+aodh_public_endpoint: "{{ public_protocol }}://{{ aodh_external_fqdn }}:{{ aodh_api_port }}"
 
 aodh_logging_debug: "{{ openstack_logging_debug }}"
 
diff --git a/ansible/roles/aodh/tasks/precheck.yml b/ansible/roles/aodh/tasks/precheck.yml
index 07f5b4e532..39cf225880 100644
--- a/ansible/roles/aodh/tasks/precheck.yml
+++ b/ansible/roles/aodh/tasks/precheck.yml
@@ -8,7 +8,7 @@
 - name: Checking free port for Aodh API
   wait_for:
     host: "{{ api_interface_address }}"
-    port: "{{ aodh_api_port }}"
+    port: "{{ aodh_api_listen_port }}"
     connect_timeout: 1
     timeout: 1
     state: stopped
diff --git a/ansible/roles/aodh/templates/aodh.conf.j2 b/ansible/roles/aodh/templates/aodh.conf.j2
index a5ae91e69f..8fc3c3c16d 100644
--- a/ansible/roles/aodh/templates/aodh.conf.j2
+++ b/ansible/roles/aodh/templates/aodh.conf.j2
@@ -7,7 +7,7 @@ evaluation_interval = {{ aodh_evaluation_interval }}
 transport_url = {{ rpc_transport_url }}
 
 [api]
-port = {{ aodh_api_port }}
+port = {{ aodh_api_listen_port }}
 host = {{ api_interface_address }}
 
 [database]
diff --git a/ansible/roles/aodh/templates/wsgi-aodh.conf.j2 b/ansible/roles/aodh/templates/wsgi-aodh.conf.j2
index 2fe3e9be85..8e30d152ab 100644
--- a/ansible/roles/aodh/templates/wsgi-aodh.conf.j2
+++ b/ansible/roles/aodh/templates/wsgi-aodh.conf.j2
@@ -1,6 +1,6 @@
 {% set python_path = '/usr/lib/python2.7/site-packages' if aodh_install_type == 'binary' else '/var/lib/kolla/venv/lib/python2.7/site-packages' %}
 {% set binary_path = '/usr/bin' if aodh_install_type == 'binary' else '/var/lib/kolla/venv/bin' %}
-Listen {{ api_interface_address }}:{{ aodh_api_port }}
+Listen {{ api_interface_address }}:{{ aodh_api_listen_port }}
 
 ServerSignature Off
 ServerTokens Prod
@@ -14,7 +14,7 @@ TraceEnable off
     </FilesMatch>
 </Directory>
 
-<VirtualHost *:{{ aodh_api_port }}>
+<VirtualHost *:{{ aodh_api_listen_port }}>
   ## Logging
   ErrorLog "/var/log/kolla/aodh/aodh_wsgi_error.log"
   ServerSignature Off