From ac1f25550723c95b81628d6fac85e5fecc8acfb5 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Tue, 20 Apr 2021 11:40:47 -0400 Subject: [PATCH] Use ephemeral Heat client if set In the cases where custom ansible plugins talk to the Heat API, we need to use the ephemeral Heat client if it has been defined. This will ensure Heat is appropriately configured to talk to the right API. Otherwise, configure a Heat client in the normal fashion. Depends-On: I2c3e9088bf92146b07d46288c2264368e15aa63b Change-Id: I0e45cbed37f2b92dcd1c435f86cf041d03ed2251 Signed-off-by: James Slagle --- .../module_utils/tripleo_common_utils.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tripleo_ansible/ansible_plugins/module_utils/tripleo_common_utils.py b/tripleo_ansible/ansible_plugins/module_utils/tripleo_common_utils.py index 3cb41d42d..b41928bca 100644 --- a/tripleo_ansible/ansible_plugins/module_utils/tripleo_common_utils.py +++ b/tripleo_ansible/ansible_plugins/module_utils/tripleo_common_utils.py @@ -19,6 +19,8 @@ # tripleo-common expects the legacy clients. Once # we've updated tripleo-common to use the SDK we # should revise this. +import os + from glanceclient import client as glanceclient from heatclient.v1 import client as heatclient from ironicclient import client as ironicclient @@ -30,6 +32,14 @@ from tripleo_common.utils import parameters import ironic_inspector_client +try: + # TODO(slagle): the try/except can be removed once tripleo_common is + # released with + # https://review.opendev.org/c/openstack/tripleo-common/+/787819 + from tripleo_common.utils import heat +except ImportError: + heat = None + class DeriveParamsError(Exception): """Error while performing a derive parameters operation""" @@ -74,8 +84,14 @@ class TripleOCommon(object): if 'heatclient' in self.client_cache: return self.client_cache['heatclient'] else: - self.client_cache['heatclient'] = \ - heatclient.Client(session=self.sess) + if heat and os.environ.get('OS_HEAT_TYPE', '') == 'ephemeral': + host = os.environ.get('OS_HEAT_HOST', '127.0.0.1') + port = os.environ.get('OS_HEAT_PORT', 8006) + self.client_cache['heatclient'] = \ + heat.local_orchestration_client(host, int(port)) + else: + self.client_cache['heatclient'] = \ + heatclient.Client(session=self.sess) return self.client_cache['heatclient'] def get_compute_client(self):