Last active
November 21, 2019 09:37
-
-
Save shalomb/5cc2851ea37c16e15cf951bf6e98f5db to your computer and use it in GitHub Desktop.
Openstack [clouds.yaml](https://docs.openstack.org/python-openstackclient/pike/configuration/index.html) updater
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 python3 | |
import yaml | |
def get_content(file='clouds.yaml'): | |
with open(file, 'r') as stream: | |
return yaml.safe_load(stream) | |
def set_content(file='clouds.yaml', content=None): | |
with open(file, 'wt') as stream: | |
print(yaml.dump(content, default_flow_style=False), file=stream) | |
def update_clouds(): | |
content = get_content() | |
content['clouds']['openstack']['auth'].update({ | |
'user_domain_name': 'null', | |
'project_domain_name': 'Default', | |
'protocol': 'oidc', | |
'discovery_endpoint': 'https://getMeToTheServer', | |
'identity_provider': 'sso', | |
'client_secret': 'blah', | |
'client_id': 'blahblah' | |
}) | |
set_content(content=content) | |
if __name__ == '__main__': | |
update_clouds() |
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 python3 | |
import datetime | |
import sys | |
import yaml | |
class Clouds(object): | |
def __init__(self, clouds_yaml): | |
self.file = clouds_yaml | |
def content(self): | |
with open(self.file, 'r') as stream: | |
return yaml.safe_load(stream) | |
def update(self, content=None): | |
with open(self.file, 'wt') as stream: | |
stream.write(yaml.dump(content, default_flow_style=False)) | |
def update_clouds(file): | |
clouds = Clouds(clouds_yaml=file) | |
content = clouds.content() | |
content['clouds']['openstack']['auth'].update({ | |
'client_id': datetime.datetime.now(), | |
'client_secret': 'blah', | |
'discovery_endpoint': 'https://getMeToTheServer', | |
'identity_provider': 'sso', | |
'project_domain_name': 'Default', | |
'protocol': 'oidc', | |
'user_domain_name': 'null', | |
}) | |
# print(content) | |
clouds.update(content=content) | |
if __name__ == '__main__': | |
file = sys.argv[1] | |
update_clouds(sys.argv[1]) | |
# $ ./clouds_yaml_util-oo.py /tmp/clouds.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment