You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.0 KiB

# Copyright 2019 Red Hat, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
import logging
import os
import re
import sys
import yaml
from osc_lib.i18n import _
from tripleoclient import constants
from tripleoclient import utils as oooutils
LOG = logging.getLogger(__name__ + ".utils")
def export_passwords(swift, stack, excludes=True):
# Export the passwords from swift
obj = 'plan-environment.yaml'
container = stack
resp_headers, content = swift.get_object(container, obj)
except Exception as e:
LOG.error("An error happened while exporting the password "
"file from swift: %s", str(e))
data = yaml.safe_load(content)["passwords"]
if excludes:
excluded_passwords = []
for k in data:
for pattern in constants.EXPORT_PASSWORD_EXCLUDE_PATTERNS:
if re.match(pattern, k, re.I):
[data.pop(e) for e in excluded_passwords]
return data
def export_stack(heat, stack, should_filter=False,
# data to export
# parameter: Parameter to be exported
# file: IF file specified it is taken as source instead of heat
# output.File is relative to <config-download-dir>/stack.
# filter: in case only specific settings should be
# exported from parameter data.
export_data = {
"EndpointMap": {
"parameter": "EndpointMapOverride",
"HostsEntry": {
"parameter": "ExtraHostFileEntries",
"GlobalConfig": {
"parameter": "GlobalConfigExtraMapData",
"AllNodesConfig": {
"file": "group_vars/overcloud.json",
"parameter": "AllNodesExtraMapData",
"filter": ["oslo_messaging_notify_short_bootstrap_node_name",
data = {}
heat_stack = oooutils.get_stack(heat, stack)
for export_key, export_param in export_data.items():
param = export_param["parameter"]
if "file" in export_param:
# get file data
file = os.path.join(config_download_dir,
with open(file, 'r') as ff:
export_data = json.load(ff)
except Exception as e:
_('Could not read file %s') % file)
# get stack data
export_data = oooutils.get_stack_output_item(
heat_stack, export_key)
if export_data:
# When we export information from a cell controller stack
# we don't want to filter.
if "filter" in export_param and should_filter:
for filter_key in export_param["filter"]:
if filter_key in export_data:
element = {filter_key: export_data[filter_key]}
data.setdefault(param, {}).update(element)
data[param] = export_data
raise Exception(
"No data returned to export %s from." % param)
return data