542 lines
19 KiB
Python
Executable File
542 lines
19 KiB
Python
Executable File
#!/usr/bin/python
|
|
# Copyright 2022 Red Hat, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# 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
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# 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 argparse
|
|
import jinja2
|
|
import logging
|
|
import os
|
|
import sys
|
|
import yaml
|
|
|
|
# STANDALONE_VARS is a dict with keys of ansible var names, and values of a
|
|
# jinja2 template. The jinja2 template can use jinja2 variables as defined from
|
|
# TEMPLATE_VARS below.
|
|
STANDALONE_VARS = {
|
|
'tripleo_nova_compute_DEFAULT_transport_url': {
|
|
'template':
|
|
'rabbit://'
|
|
'{% for node in oslo_messaging_rpc_node_names %}'
|
|
'{% if not loop.first %},{% endif %}'
|
|
'{{oslo_messaging_rpc_user_name}}:{{oslo_messaging_rpc_password}}'
|
|
'@{{node}}:5672'
|
|
'{% endfor %}'
|
|
'/?ssl={% if oslo_messaging_rpc_use_ssl=="True" %}1'
|
|
'{% else %}0{% endif %}',
|
|
'section': 'DEFAULT',
|
|
'option': 'transport_url'
|
|
},
|
|
'tripleo_ovn_metadata_agent_DEFAULT_transport_url': {
|
|
'template':
|
|
'rabbit://'
|
|
'{% for node in oslo_messaging_rpc_node_names %}'
|
|
'{% if not loop.first %},{% endif %}'
|
|
'{{oslo_messaging_rpc_user_name}}:{{oslo_messaging_rpc_password}}'
|
|
'@{{node}}:5672'
|
|
'{% endfor %}'
|
|
'/?ssl={% if oslo_messaging_rpc_use_ssl=="True" %}1'
|
|
'{% else %}0{% endif %}',
|
|
'section': 'DEFAULT',
|
|
'option': 'transport_url'
|
|
},
|
|
'tripleo_ovn_metadata_agent_oslo_messaging_notifications_transport_url': {
|
|
'template':
|
|
'rabbit://'
|
|
'{% for node in oslo_messaging_rpc_node_names %}'
|
|
'{% if not loop.first %},{% endif %}'
|
|
'{{oslo_messaging_rpc_user_name}}:{{oslo_messaging_rpc_password}}'
|
|
'@{{node}}:5672'
|
|
'{% endfor %}'
|
|
'/?ssl={% if oslo_messaging_rpc_use_ssl=="True" %}1'
|
|
'{% else %}0{% endif %}',
|
|
'section': 'oslo_messaging_notifications',
|
|
'option': 'transport_url'
|
|
},
|
|
'tripleo_nova_compute_oslo_messaging_notifications_transport_url': {
|
|
'template':
|
|
'rabbit://'
|
|
'{% for node in oslo_messaging_rpc_node_names %}'
|
|
'{% if not loop.first %},{% endif %}'
|
|
'{{oslo_messaging_rpc_user_name}}:{{oslo_messaging_rpc_password}}'
|
|
'@{{node}}:5672'
|
|
'{% endfor %}'
|
|
'/?ssl={% if oslo_messaging_rpc_use_ssl=="True" %}1'
|
|
'{% else %}0{% endif %}',
|
|
'section': 'DEFAULT',
|
|
'option': 'oslo_messaging_notifications_transport_url'
|
|
},
|
|
'tripleo_nova_compute_cache_memcache_servers': {
|
|
'template':
|
|
'{% for node in memcached_node_names %}'
|
|
'{% if not loop.first %},{% endif %}'
|
|
'{{ node }}:{{ memcached_port }}'
|
|
'{% endfor %}',
|
|
'section': 'cache',
|
|
'option': 'memcache_servers'
|
|
},
|
|
'tripleo_nova_compute_cinder_auth_url': {
|
|
'template': '{{ nova_cinder_auth_url }}',
|
|
'section': 'cinder',
|
|
'option': 'auth_url'
|
|
},
|
|
'tripleo_nova_compute_cinder_password': {
|
|
'template': '{{ nova_cinder_password }}',
|
|
'section': 'cinder',
|
|
'option': 'password'
|
|
},
|
|
'tripleo_nova_compute_neutron_auth_url': {
|
|
'template': '{{ nova_neutron_auth_url }}',
|
|
'section': 'neutron',
|
|
'option': 'auth_url'
|
|
},
|
|
'tripleo_nova_compute_neutron_password': {
|
|
'template': '{{ nova_neutron_password }}',
|
|
'section': 'neutron',
|
|
'option': 'password'
|
|
},
|
|
'ctlplane_dns_nameservers': {
|
|
'template': '{{ ctlplane_dns_nameservers }}',
|
|
},
|
|
'dns_search_domains': {
|
|
'template': '{{ dns_search_domains }}',
|
|
},
|
|
'tripleo_nova_compute_vnc_novncproxy_base_url': {
|
|
'template':
|
|
'{{ vncproxy_protocol }}://{{ vncproxy_host }}:{{ vncproxy_port }}',
|
|
'section': 'vnc',
|
|
'option': 'novncproxy_base_url'
|
|
},
|
|
'tripleo_nova_compute_service_user_username': {
|
|
'template': 'nova',
|
|
'section': 'service_user',
|
|
'option': 'username'
|
|
},
|
|
'tripleo_nova_compute_service_user_password': {
|
|
'template': '{{ service_user_password }}',
|
|
'section': 'service_user',
|
|
'option': 'password'
|
|
},
|
|
'tripleo_nova_compute_service_user_auth_url': {
|
|
'template': '{{ service_user_auth_url }}',
|
|
'section': 'service_user',
|
|
'option': 'auth_url'
|
|
},
|
|
'tripleo_nova_compute_service_user_auth_type': {
|
|
'template': 'password',
|
|
'section': 'service_user',
|
|
'option': 'auth_type'
|
|
},
|
|
'tripleo_nova_compute_service_user_project_name': {
|
|
'template': '{{ service_user_project_name }}',
|
|
'section': 'service_user',
|
|
'option': 'project_name'
|
|
},
|
|
'tripleo_nova_compute_service_user_project_domain_name': {
|
|
'template': 'Default',
|
|
'section': 'service_user',
|
|
'option': 'project_domain_name'
|
|
},
|
|
'tripleo_nova_compute_service_user_user_domain_name': {
|
|
'template': 'Default',
|
|
'section': 'service_user',
|
|
'option': 'user_domain_name'
|
|
},
|
|
'tripleo_nova_compute_service_user_region_name': {
|
|
'template': '{{ service_user_region_name }}',
|
|
'section': 'service_user',
|
|
'option': 'region_name'
|
|
},
|
|
'tripleo_nova_compute_service_user_send_service_user_token': {
|
|
'template': '{{ service_user_send_service_user_token }}',
|
|
'section': 'service_user',
|
|
'option': 'send_service_user_token'
|
|
},
|
|
|
|
'tripleo_nova_compute_placement_username': {
|
|
'template': 'placement',
|
|
'section': 'placement',
|
|
'option': 'username'
|
|
},
|
|
'tripleo_nova_compute_placement_password': {
|
|
'template': '{{ placement_password }}',
|
|
'section': 'placement',
|
|
'option': 'password'
|
|
},
|
|
'tripleo_nova_compute_placement_auth_url': {
|
|
'template': '{{ placement_auth_url }}',
|
|
'section': 'placement',
|
|
'option': 'auth_url'
|
|
},
|
|
'tripleo_nova_compute_placement_auth_type': {
|
|
'template': 'password',
|
|
'section': 'placement',
|
|
'option': 'auth_type'
|
|
},
|
|
'tripleo_nova_compute_placement_project_name': {
|
|
'template': '{{ placement_project_name }}',
|
|
'section': 'placement',
|
|
'option': 'project_name'
|
|
},
|
|
'tripleo_nova_compute_placement_project_domain_name': {
|
|
'template': 'Default',
|
|
'section': 'placement',
|
|
'option': 'project_domain_name'
|
|
},
|
|
'tripleo_nova_compute_placement_user_domain_name': {
|
|
'template': 'Default',
|
|
'section': 'placement',
|
|
'option': 'user_domain_name'
|
|
},
|
|
'tripleo_nova_compute_placement_region_name': {
|
|
'template': '{{ placement_region_name }}',
|
|
'section': 'placement',
|
|
'option': 'region_name'
|
|
},
|
|
'tripleo_nova_compute_placement_valid_interfaces': {
|
|
'template': '{{ placement_valid_interfaces }}',
|
|
'section': 'placement',
|
|
'option': 'valid_interfaces'
|
|
},
|
|
'tripleo_nova_compute_neutron_auth_type': {
|
|
'template': 'v3password',
|
|
'section': 'neutron',
|
|
'option': 'auth_type'
|
|
},
|
|
'tripleo_nova_compute_neutron_project_name': {
|
|
'template': 'service',
|
|
'section': 'neutron',
|
|
'option': 'project_name'
|
|
},
|
|
'tripleo_nova_compute_neutron_user_domain_name': {
|
|
'template': 'Default',
|
|
'section': 'neutron',
|
|
'option': 'user_domain_name'
|
|
},
|
|
'tripleo_nova_compute_neutron_project_domain_name': {
|
|
'template': 'Default',
|
|
'section': 'neutron',
|
|
'option': 'project_domain_name'
|
|
},
|
|
'tripleo_nova_compute_neutron_region_name': {
|
|
'template': 'regionOne',
|
|
'section': 'neutron',
|
|
'option': 'region_name'
|
|
},
|
|
'tripleo_nova_compute_neutron_username': {
|
|
'template': 'neutron',
|
|
'section': 'neutron',
|
|
'option': 'username'
|
|
},
|
|
'tripleo_ovn_dbs': {
|
|
'template': '{{ ovn_dbs }}',
|
|
},
|
|
'tripleo_ovn_metadata_agent_database_connection': {
|
|
'template': '{{ neutron_database_connection }}',
|
|
'section': 'database',
|
|
'option': 'connection'
|
|
},
|
|
'tripleo_ovn_metadata_agent_keystone_www_authenticate_uri': {
|
|
'template': '{{ neutron_keystone_auth_uri }}',
|
|
'section': 'keystone_authtoken',
|
|
'option': 'www_authenticate_uri'
|
|
},
|
|
'tripleo_ovn_metadata_agent_keystone_auth_url': {
|
|
'template': '{{ neutron_keystone_auth_url }}',
|
|
'section': 'keystone_authtoken',
|
|
'option': 'auth_url'
|
|
},
|
|
'tripleo_ovn_metadata_agent_keystone_password': {
|
|
'template': '{{ neutron_keystone_password }}',
|
|
'section': 'keystone_authtoken',
|
|
'option': 'password'
|
|
},
|
|
'tripleo_ovn_metadata_agent_placement_password': {
|
|
'template': '{{ neutron_placement_password }}',
|
|
'section': 'placement',
|
|
'option': 'password'
|
|
},
|
|
'tripleo_ovn_metadata_agent_nova_auth_url': {
|
|
'template': '{{ neutron_nova_auth_url }}',
|
|
'section': 'nova',
|
|
'option': 'auth_url'
|
|
},
|
|
'tripleo_ovn_metadata_agent_nova_password': {
|
|
'template': '{{ neutron_nova_password }}',
|
|
'section': 'nova',
|
|
'option': 'password'
|
|
},
|
|
'tripleo_ovn_metadata_agent_placement_auth_url': {
|
|
'template': '{{ neutron_placement_auth_url }}',
|
|
'section': 'placement',
|
|
'option': 'auth_url'
|
|
},
|
|
'tripleo_ovn_metadata_agent_metadata_agent_DEFAULT_nova_metadata_host': {
|
|
'template': '{{ neutron_metadata_host }}',
|
|
'section': 'DEFAULT',
|
|
'option': 'nova_metadata_host'
|
|
},
|
|
'tripleo_ovn_metadata_agent_metadata_agent_DEFAULT_metadata_proxy_shared_secret': {
|
|
'template': '{{ neutron_metadata_shared_secret }}',
|
|
'section': 'DEFAULT',
|
|
'option': 'metadata_proxy_shared_secret'
|
|
},
|
|
|
|
}
|
|
|
|
# TEMPLATE_VARS is a dict with keys jinja2 variables names that will be passed
|
|
# when the templates from STANDALONE_VARS are rendered. The values are a dict
|
|
# of a file name and YAML key to look up from the config-download directory.
|
|
# The file names use string formatting with replacement fields (role).
|
|
TEMPLATE_VARS = {
|
|
'oslo_messaging_rpc_user_name': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.oslo_messaging_rpc_user_name'
|
|
},
|
|
'oslo_messaging_rpc_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.oslo_messaging_rpc_password'
|
|
},
|
|
'oslo_messaging_rpc_use_ssl': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.oslo_messaging_rpc_use_ssl'
|
|
},
|
|
'oslo_messaging_rpc_node_names': {
|
|
'file': 'group_vars/overcloud.json',
|
|
'key': 'oslo_messaging_rpc_node_names'
|
|
},
|
|
'memcached_port': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.memcached_port'
|
|
},
|
|
'memcached_node_names': {
|
|
'file': 'group_vars/overcloud.json',
|
|
'key': 'memcached_node_names'
|
|
},
|
|
'nova_cinder_auth_url': {
|
|
'file': 'group_vars/{role}',
|
|
# nova-compute which sets nova::cinder::auth_url may not be deployed
|
|
# if the deployment is a standalone ctlplane, but the auth_url for
|
|
# neutron is the same value.
|
|
'key': 'service_configs.nova::network::neutron::auth_url'
|
|
},
|
|
'nova_cinder_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.cinder::db::mysql::password'
|
|
},
|
|
'nova_neutron_auth_url': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::network::neutron::auth_url'
|
|
},
|
|
'nova_neutron_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::network::neutron::password'
|
|
},
|
|
'ctlplane_dns_nameservers': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'ctlplane_dns_nameservers'
|
|
},
|
|
'dns_search_domains': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'dns_search_domains'
|
|
},
|
|
'vncproxy_protocol': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::vncproxy::common::vncproxy_protocol'
|
|
},
|
|
'vncproxy_host': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::vncproxy::common::vncproxy_host'
|
|
},
|
|
'vncproxy_port': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::vncproxy::common::vncproxy_port'
|
|
},
|
|
|
|
'service_user_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::keystone::service_user::password'
|
|
},
|
|
'service_user_auth_url': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::keystone::service_user::auth_url'
|
|
},
|
|
'service_user_project_name': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::keystone::service_user::project_name'
|
|
},
|
|
'service_user_region_name': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::keystone::service_user::region_name'
|
|
},
|
|
'service_user_send_service_user_token': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::keystone::service_user::send_service_user_token'
|
|
},
|
|
|
|
'placement_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::placement::password'
|
|
},
|
|
'placement_auth_url': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::placement::auth_url'
|
|
},
|
|
'placement_project_name': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::placement::project_name'
|
|
},
|
|
'placement_valid_interfaces': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::placement::valid_interfaces'
|
|
},
|
|
'ovn_dbs': {
|
|
'file': 'group_vars/overcloud.json',
|
|
'key': 'ovn_dbs_node_ips'
|
|
},
|
|
'placement_region_name': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.nova::placement::region_name'
|
|
},
|
|
'neutron_database_connection': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::db::database_connection'
|
|
},
|
|
'neutron_keystone_auth_uri': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::keystone::authtoken::www_authenticate_uri'
|
|
},
|
|
#'neutron_keystone_memcached_servers': {
|
|
# 'file': 'group_vars/{role}',
|
|
# 'key': 'service_configs.neutron::keystone::authtoken::memc'
|
|
#},
|
|
'neutron_keystone_auth_url': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::keystone::authtoken::auth_url'
|
|
},
|
|
'neutron_keystone_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::keystone::authtoken::password'
|
|
},
|
|
'neutron_placement_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::server::placement::password'
|
|
},
|
|
'neutron_placement_auth_url': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::server::placement::auth_url'
|
|
},
|
|
'neutron_nova_password': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::server::notifications::nova::password'
|
|
},
|
|
'neutron_nova_auth_url': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::server::notifications::nova::auth_url'
|
|
},
|
|
'neutron_metadata_host': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::agents::ovn_metadata::metadata_host'
|
|
},
|
|
'neutron_metadata_shared_secret': {
|
|
'file': 'group_vars/{role}',
|
|
'key': 'service_configs.neutron::agents::ovn_metadata::shared_secret'
|
|
},
|
|
}
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(
|
|
description=("tripleo-standalone-vars"),
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
parser.add_argument(
|
|
'--config-download-dir', '-c',
|
|
action='store',
|
|
default='~/overcloud-deploy/overcloud/config-download/overcloud',
|
|
help=('The config-download directory for the deployment used as '
|
|
'the source of the generated ansible variables.'))
|
|
parser.add_argument('--output-file', '-o',
|
|
default='99-standalone-vars',
|
|
help=("Output file containing the generated ansible "
|
|
"vars."))
|
|
parser.add_argument('--role', '-r',
|
|
default='Controller',
|
|
help="Primary role name from the source deployment.")
|
|
parser.add_argument('--force', '-f',
|
|
action='store_true',
|
|
help="Force overwriting the output file if it exists.")
|
|
|
|
args = parser.parse_args(sys.argv[1:])
|
|
return args
|
|
|
|
|
|
def main():
|
|
|
|
logging.basicConfig()
|
|
log = logging.getLogger()
|
|
log.setLevel(logging.INFO)
|
|
|
|
args = parse_args()
|
|
|
|
if os.path.exists(args.output_file) and not args.force:
|
|
print("Output file {} exists. Won't continue without --force, or "
|
|
"delete the file first.".format(args.output_file))
|
|
sys.exit(1)
|
|
|
|
tmpl_vars = {}
|
|
standalone_vars = {}
|
|
nova_config = {}
|
|
standalone_vars['tripleo_nova_compute_config_overrides'] = nova_config
|
|
file_cache = {}
|
|
format_dict = dict(role=args.role)
|
|
|
|
for t_var, t_dict in TEMPLATE_VARS.items():
|
|
# Load the file if not already in file_cache
|
|
log.info('Looking up {}'.format(t_var))
|
|
file_path = os.path.join(
|
|
args.config_download_dir,
|
|
t_dict['file']).format(**format_dict)
|
|
if file_path not in file_cache:
|
|
with open(file_path) as f:
|
|
log.info('Caching {}'.format(file_path))
|
|
file_cache[file_path] = yaml.safe_load(f.read())
|
|
|
|
keys = t_dict['key'].split('.')
|
|
val = file_cache[file_path][keys[0]]
|
|
for k in keys[1:]:
|
|
val = val[k]
|
|
tmpl_vars[t_var] = val
|
|
|
|
for s_var, s_tmpl in STANDALONE_VARS.items():
|
|
log.info("Loading template for {}".format(s_var))
|
|
jinja_tmpl = jinja2.Environment().from_string(s_tmpl['template'])
|
|
log.info("Rendering {}".format(s_var))
|
|
s_val = jinja_tmpl.render(**tmpl_vars)
|
|
try:
|
|
s_val_yaml = yaml.safe_load(s_val)
|
|
except yaml.YAMLError as ye:
|
|
s_val_yaml = s_val
|
|
standalone_vars[s_var] = s_val_yaml
|
|
if 'section' in s_tmpl:
|
|
section_config = nova_config.setdefault(s_tmpl['section'], {})
|
|
section_config[s_tmpl['option']] = s_val
|
|
|
|
config_dict = {'Compute': {'vars': standalone_vars}}
|
|
with open(args.output_file, 'w') as f:
|
|
f.write(yaml.safe_dump(config_dict, default_flow_style=False, width=10000))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|