Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import configargparse
- import os
- import yaml
- p = configargparse.ArgParser()
- p.add('-n', '--name', required=True, help='name')
- p.add('-v', '--version', required=True, help='version')
- p.add('-s', '--sub', required=False, help='service category')
- options = p.parse_args()
- filename = options.name + '.yml'
- if hasattr(options, 'sub'):
- filename = options.sub + '/' + options.name + '.yml'
- f = open(filename)
- docs = yaml.safe_load_all(f)
- deployment = {}
- service = {}
- for doc in docs:
- if doc['kind'] == 'Deployment':
- deployment = doc.copy()
- if doc['kind'] == 'Service':
- service = doc.copy()
- f.close()
- # edit application yml file
- # print service['kind']
- for x in deployment['spec']['template']['spec']['containers']:
- if x['name'] == options.name:
- x['image'] = 'repo.isw.la/' + options.name + ':' + options.version
- print x['image']
- # yaml = yaml.dump_all([deployment, service], explicit_start=True, default_flow_style=False)
- with open(filename, 'w') as f:
- yaml.dump_all([deployment, service], f, explicit_start=True, default_flow_style=False, width=1000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement