How to use print_as_yaml method in molecule

Best Python code snippet using molecule_python

awsconfig2xld.py

Source:awsconfig2xld.py Github

copy

Full Screen

...6import yaml7#8# Util9#10def print_as_yaml(dict):11 print(yaml.safe_dump(dict, default_flow_style=False))12# Hack to properly print Yaml13# https://stackoverflow.com/questions/45004464/yaml-dump-adding-unwanted-newlines-in-multiline-strings14yaml.SafeDumper.org_represent_str = yaml.SafeDumper.represent_str15def repr_str(dumper, data):16 if '\n' in data:17 return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|')18 return dumper.org_represent_str(data)19yaml.add_representer(str, repr_str, Dumper=yaml.SafeDumper)20#21# Create XLD YAML from AWS credentials and config22#23def aws_credentials_to_infrastructure(credentialsfile):24 # Read AWS credentials file25 credentials = configparser.ConfigParser()26 credentials.read(credentialsfile)27 # Build CIs for XL Deploy28 return {29 'apiVersion': 'xl-deploy/v1beta1',30 'kind': 'Infrastructure',31 'spec': [32 {33 'name': 'aws',34 'type': 'aws.Cloud',35 'accesskey': credentials['default']['aws_access_key_id'],36 'accessSecret': credentials['default']['aws_secret_access_key']37 }38 ]39 }40def aws_config_to_environment(configfile, infrastructure):41 # Read AWS config file42 config = configparser.ConfigParser()43 config.read(configfile)44 # Build CIs for XL Deploy45 return {46 'apiVersion': 'xl-deploy/v1beta1',47 'kind': 'Environments',48 'spec': [49 {50 'name': 'AWS Dictionary',51 'type': 'udm.Dictionary',52 'entries': {53 'region': config['default']['region'],54 'username': getpass.getuser()55 }56 },57 {58 'name': 'AWS',59 'type': 'udm.Environment',60 'members': [61 '~Infrastructure/' + infrastructure['spec'][0]['name']62 ],63 'dictionaries': [64 '~Environments/AWS Dictionary'65 ]66 }67 ]68 }69 return environment70# Converts AWS credentials and config files to XL Deploy objects71credentialsfile = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.expanduser('~'), '.aws/credentials')72infrastructure = aws_credentials_to_infrastructure(credentialsfile)73configfile = sys.argv[2] if len(sys.argv) > 2 else os.path.join(os.path.expanduser('~'), '.aws/config')74environment = aws_config_to_environment(configfile, infrastructure)75# Print YAML76print_as_yaml(infrastructure)77print("---")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful