Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Automatically run overcloud export when using ephemeral heat
Browse files Browse the repository at this point in the history
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
  • Loading branch information
slagle committed Apr 28, 2021
1 parent f4920c4 commit 7483b62
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
3 changes: 3 additions & 0 deletions tripleoclient/export.py
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tripleoclient/utils.py
Expand Up @@ -68,6 +68,7 @@
from tripleo_common import update
from tripleoclient import constants
from tripleoclient import exceptions
from tripleoclient import export
from tripleoclient import heat_launcher

try:
Expand Down Expand Up @@ -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
18 changes: 18 additions & 0 deletions tripleoclient/v1/overcloud_deploy.py
Expand Up @@ -1200,6 +1200,24 @@ def take_action(self, parsed_args):
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(
Expand Down
21 changes: 8 additions & 13 deletions tripleoclient/v1/overcloud_export.py
Expand Up @@ -16,10 +16,10 @@
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):
Expand All @@ -36,8 +36,9 @@ def get_parser(self, prog_name):
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 '
Expand Down Expand Up @@ -86,15 +87,9 @@ def take_action(self, parsed_args):
# 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)
Expand Down

0 comments on commit 7483b62

Please sign in to comment.