diff options
author | 2013-05-14 11:19:43 -0700 | |
---|---|---|
committer | 2013-06-06 09:25:27 -0700 | |
commit | d5e511f945152cc860640b5276272c50830e735d (patch) | |
tree | d97078c7b84efe41b5edebcdb29fd2a61bf2c3ff /merge.py | |
parent | 621a4dd9ca7029d1cc3bf46aa595f94d659479d5 (diff) |
Add ability to combine roles into one role.
Diffstat (limited to 'merge.py')
-rw-r--r-- | merge.py | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -1,7 +1,33 @@ import sys import yaml +import argparse -templates = list(sys.argv[1:]) +parser = argparse.ArgumentParser() +parser.add_argument('templates', nargs='+') +parser.add_argument('--master-role', nargs='?', + help='Translate slave_roles to this') +parser.add_argument('--slave-roles', nargs='*', + help='Translate all of these to master_role') + +args = parser.parse_args() + +templates = args.templates + +def _translate_role(role): + global args + if not args.master_role: + return role + if role == args.master_role: + return role + if role not in args.slave_roles: + return role + return args.master_role + +def translate_role(role): + r = _translate_role(role) + if not isinstance(r, basestring): + raise Exception('%s -> %r' % (role, r)) + return r errors = [] end_template={'HeatTemplateFormatVersion': '2012-12-12', @@ -39,6 +65,7 @@ for template_path in templates: # XXX Assuming ImageId is always a Ref del end_template['Parameters'][rbody['Properties']['ImageId']['Ref']] role = rbody.get('Metadata', {}).get('OpenStack::Role', r) + role = translate_role(role) if role != r: resource_changes.append((r, role)) if role in end_template.get('Resources', {}): |