Automatically run overcloud export when using ephemeral heat

The overcloud export environment will be automatically created when
using ephemeral heat. Since the stack is ephemeral, we need to go ahead
and do the export before stopping Heat. While we backup the heat db so
we have the stack saved if needed, it's just eaiser and eliminates a
manual step to do the export if we do it automatically.

Signed-off-by: James Slagle <jslagle@redhat.com>
Change-Id: Idc326cb7baa54a7d2d01a2be002dfffa6a59ef6a
This commit is contained in:
James Slagle 2021-02-24 15:36:03 -05:00
parent f4920c49f6
commit 7483b62332
4 changed files with 42 additions and 13 deletions

View File

@ -91,6 +91,9 @@ def export_stack(heat, stack, should_filter=False,
file = os.path.join(config_download_dir,
stack,
export_param["file"])
if not os.path.exists(file):
LOG.warning('File %s was not found during export' %
file)
with open(file, 'r') as ff:
try:
export_data = json.load(ff)

View File

@ -68,6 +68,7 @@ from tripleo_common.utils import stack as stack_utils
from tripleo_common import update
from tripleoclient import constants
from tripleoclient import exceptions
from tripleoclient import export
from tripleoclient import heat_launcher
try:
@ -2636,3 +2637,15 @@ def get_default_working_dir(stack):
return os.path.join(
os.path.expanduser('~'),
"overcloud-deploy", stack)
def export_overcloud(heat, stack, excludes, should_filter,
config_download_dir):
data = export.export_passwords(heat, stack, excludes)
data.update(export.export_stack(
heat, stack, should_filter, config_download_dir))
# do not add extra host entries for VIPs for stacks deployed off that
# exported data, since it already contains those entries
data.update({'AddVipsToEtcHosts': False})
data = dict(parameter_defaults=data)
return data

View File

@ -1200,6 +1200,24 @@ class DeployOvercloud(command.Command):
utils.copy_clouds_yaml(user)
utils.create_tempest_deployer_input(output_dir=self.working_dir)
try:
if (parsed_args.heat_type != 'installed' and
parsed_args.config_download):
# Create overcloud export
data = utils.export_overcloud(
self.orchestration_client,
parsed_args.stack, True, False,
config_download_dir)
export_file = os.path.join(
self.working_dir, "%s-export.yaml" % parsed_args.stack)
# write the exported data
with open(export_file, 'w') as f:
yaml.safe_dump(data, f, default_flow_style=False)
os.chmod(export_file, 0o600)
except Exception as e:
self.log.error('Exception creating overcloud export.')
self.log.error(e)
print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
print("Overcloud Horizon Dashboard URL: {0}".format(horizon_url))
print("Overcloud rc file: {} and {}".format(

View File

@ -16,10 +16,10 @@ import os.path
import yaml
from osc_lib.i18n import _
from osc_lib import utils
from osc_lib import utils as osc_utils
from tripleoclient import command
from tripleoclient import export
from tripleoclient import utils
class ExportOvercloud(command.Command):
@ -36,8 +36,9 @@ class ExportOvercloud(command.Command):
help=_('Name of the environment main Heat stack '
'to export information from. '
'(default=Env: OVERCLOUD_STACK_NAME)'),
default=utils.env('OVERCLOUD_STACK_NAME',
default='overcloud'))
default=osc_utils.env(
'OVERCLOUD_STACK_NAME',
default='overcloud'))
parser.add_argument('--output-file', '-o', metavar='<output file>',
help=_('Name of the output file for the stack '
'data export. It will default to '
@ -86,15 +87,9 @@ class ExportOvercloud(command.Command):
# prepare clients to access the environment
clients = self.app.client_manager
heat = clients.orchestration
data = export.export_passwords(heat, stack,
not parsed_args.no_password_excludes)
data.update(export.export_stack(
heat, stack, False, config_download_dir))
# do not add extra host entries for VIPs for stacks deployed off that
# exported data, since it already contains those entries
data.update({'AddVipsToEtcHosts': False})
data = dict(parameter_defaults=data)
data = utils.export_overcloud(
heat, stack, excludes=not parsed_args.no_password_excludes,
should_filter=False, config_download_dir=config_download_dir)
# write the exported data
with open(output_file, 'w') as f:
yaml.safe_dump(data, f, default_flow_style=False)