Created
August 9, 2016 13:04
-
-
Save andrewdmcleod/3e42d94927f721ff29ed7cbef7f350cc to your computer and use it in GitHub Desktop.
Modify a juju bundle - change charms to 'ubuntu' or other as specified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import yaml | |
import argparse | |
import sys | |
parser = argparse.ArgumentParser(description="Process bundle.yaml and output without relations or options.") | |
parser.add_argument('-i', '--input', help="name of input yaml") | |
parser.add_argument('-o', '--output', help="name of output yaml") | |
parser.add_argument('-c', '--charm', help="charm url to use as replacement") | |
args = parser.parse_args() | |
infile = args.input | |
outfile = args.output | |
charm = args.charm | |
if infile == None: | |
infile = 'bundle.yaml' | |
if outfile == None: | |
print "No output filename specified, exiting" | |
sys.exit() | |
if charm == None: | |
charm = 'cs:xenial/ubuntu' | |
input = yaml.load(open(infile)) | |
del input['relations'] | |
for key, value in list(input['services'].iteritems()): | |
for a, b in list(input['services'][key].iteritems()): | |
if a == 'charm': | |
input['services'][key]['charm'] = charm | |
if a == 'options': | |
del input['services'][key]['options'] | |
with open(outfile, 'w') as outfile: | |
outfile.write(yaml.dump(input, default_flow_style=False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment