From 0aefaf3f5b1c608e7ffca4ce259a7c7ef0644194 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Wed, 17 Nov 2021 07:43:26 -0500 Subject: [PATCH] Write clouds.yaml/heatrc for tripleo launch heat When "openstack tripleo launch heat" is used to start an ephemeral Heat process, a clouds.yaml and heatrc file are now written to the Heat working dir that can be used to interact with the ephemeral Heat API. Change-Id: I35ad22a77362e73695c16b1e5abf02e05f9fdada Signed-off-by: James Slagle (cherry picked from commit 723bf34caf152333da8b49ecd54fabb9289ef99c) --- tripleoclient/utils.py | 32 +++++++++++++++++++++++++ tripleoclient/v1/tripleo_launch_heat.py | 3 +++ 2 files changed, 35 insertions(+) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 7f5b879d2..a052d7245 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -43,6 +43,7 @@ import subprocess import sys import tarfile import tempfile +import textwrap import time import yaml @@ -3112,6 +3113,37 @@ def get_ceph_networks(network_data_path, return storage_net_map +def write_ephemeral_heat_clouds_yaml(heat_dir): + clouds_yaml_path = os.path.join(heat_dir, 'clouds.yaml') + clouds_dict = {} + clouds_dict['heat'] = {} + clouds_dict['heat']['auth_type'] = "none" + clouds_dict['heat']['endpoint'] = \ + "http://127.0.0.1:8006/v1/admin" + heat_yaml = dict(clouds=clouds_dict) + with open(clouds_yaml_path, 'w') as f: + f.write(yaml.dump(heat_yaml)) + + heatrc = textwrap.dedent(""" + # Clear any old environment that may conflict. + for key in $( set | awk -F= '/^OS_/ {print $1}' ); do + unset "${key}" + done + export OS_CLOUD=heat + # Add OS_CLOUDNAME to PS1 + if [ -z "${CLOUDPROMPT_ENABLED:-}" ]; then + export PS1=${PS1:-""} + export PS1=${OS_CLOUD:+"($OS_CLOUD)"} $PS1 + export CLOUDPROMPT_ENABLED=1 + fi + """) + + # Also write a heatrc file + heatrc_path = os.path.join(heat_dir, 'heatrc') + with open(heatrc_path, 'w') as f: + f.write(heatrc) + + def get_host_groups_from_ceph_spec(ceph_spec_path, prefix='', key='hostname', get_non_admin=True): """Get hosts per group based on labels in ceph_spec_path file diff --git a/tripleoclient/v1/tripleo_launch_heat.py b/tripleoclient/v1/tripleo_launch_heat.py index 8857cc643..0ada7fb00 100644 --- a/tripleoclient/v1/tripleo_launch_heat.py +++ b/tripleoclient/v1/tripleo_launch_heat.py @@ -218,6 +218,9 @@ class LaunchHeat(command.Command): msg = _('Heat launch failed.') self.log.error(msg) raise exceptions.DeploymentError(msg) + else: + self.log.info("Writing heat clouds.yaml") + utils.write_ephemeral_heat_clouds_yaml(parsed_args.heat_dir) def _configure_logging(self, parsed_args): formatter = logging.Formatter(