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

Commit

Permalink
Allow nic-config conversion without Heat
Browse files Browse the repository at this point in the history
The current script requires the orchestration (Heat)
be available. This change will allow the script to convert
existing templates provided without the orchestration
service present.

Change-Id: Ie94de5841617cd8dc87ee7dccc5d4ece5b908cb9
(cherry picked from commit 0c3ea4c)
  • Loading branch information
bshephar committed Feb 28, 2022
1 parent 5cfac47 commit 3ad4133
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tools/convert_heat_nic_config_to_ansible_j2.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ def parse_opts(argv):
parser.add_argument('template',
metavar='TEMPLATE_FILE',
help='Existing NIC config template to convert.')
parser.add_argument('--standalone',
default=False,
action='store_true',
help='This switch allows the script to operate in '
'environments where the orchestration service '
'is not available. Such as environemnts with '
'ephemeral-heat')

opts = parser.parse_args(argv[1:])

Expand Down Expand Up @@ -225,7 +232,8 @@ def convert_get_param(self, old):
if isinstance(param, str):
if param in self.param_to_var_map:
return self.param_to_var_map[param]
elif param in self.stack_env.get('parameter_defaults', {}):
elif (self.stack_env and
param in self.stack_env.get('parameter_defaults', {})):
stack_value = self.stack_env['parameter_defaults'][param]
print('INFO - Custom Parameter {} was hard-coded in the '
'converted template using the value from the Heat stack '
Expand Down Expand Up @@ -389,7 +397,7 @@ def convert_template(self, template):
net_config_res_props = net_config_res['properties']

if net_config_res['type'] == 'OS::Heat::Value':
h_net_conf = net_config_res_props['value']
h_net_conf = net_config_res_props['value']['network_config']
elif net_config_res['type'] == 'OS::Heat::SoftwareConfig':
h_net_conf = net_config_res_props['config']['str_replace'][
'params']['$network_config']['network_config']
Expand Down Expand Up @@ -501,7 +509,10 @@ def main():
j2_template = os.path.splitext(template)[0] + '.j2'
validate_files(opts, template, networks_file, j2_template)

stack_env = get_stack_environment(opts.stack)
if not opts.standalone:
stack_env = get_stack_environment(opts.stack)
else:
stack_env = None

converter = ConvertToAnsibleJ2(stack_env, networks_file)

Expand Down

0 comments on commit 3ad4133

Please sign in to comment.