Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #!/usr/bin/python
  2. import configargparse
  3. import os
  4. import yaml
  5.  
  6. p = configargparse.ArgParser()
  7.  
  8. p.add('-n', '--name', required=True, help='name')
  9. p.add('-v', '--version', required=True, help='version')
  10. p.add('-s', '--sub', required=False, help='service category')
  11. options = p.parse_args()
  12.  
  13. filename = options.name + '.yml'
  14. if hasattr(options, 'sub'):
  15. filename = options.sub + '/' + options.name + '.yml'
  16.  
  17. f = open(filename)
  18. docs = yaml.safe_load_all(f)
  19.  
  20. deployment = {}
  21. service = {}
  22. for doc in docs:
  23. if doc['kind'] == 'Deployment':
  24. deployment = doc.copy()
  25.  
  26. if doc['kind'] == 'Service':
  27. service = doc.copy()
  28.  
  29. f.close()
  30.  
  31. # edit application yml file
  32. # print service['kind']
  33. for x in deployment['spec']['template']['spec']['containers']:
  34. if x['name'] == options.name:
  35. x['image'] = 'repo.isw.la/' + options.name + ':' + options.version
  36. print x['image']
  37.  
  38. # yaml = yaml.dump_all([deployment, service], explicit_start=True, default_flow_style=False)
  39. with open(filename, 'w') as f:
  40. 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