Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Last active March 12, 2019 05:11
Show Gist options
  • Save mrlesmithjr/cabe850409f806a0e56b52e4afcb1fd9 to your computer and use it in GitHub Desktop.
Save mrlesmithjr/cabe850409f806a0e56b52e4afcb1fd9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
VMS = {
'db01': {
'profile': 'Linux_DB',
'vm_size': 'medium'
},
'web01': {
'profile': 'Linux_Web',
'vm_size': 'small'
}
}
with open('profiles.json', 'r') as stream:
MAPPINGS = json.load(stream)
VM_MAPPINGS = []
for key, value in VMS.items():
profile = MAPPINGS.get(value['profile'])
specs = profile['vm_sizes'].get(value['vm_size'])
template = profile.get('template')
vm_size = value.get('vm_size')
vm_config = {
key: {
'specs': specs,
'template': template,
'vm_size': vm_size
}
}
VM_MAPPINGS.append(vm_config)
print json.dumps(VM_MAPPINGS, indent=4)
{
"Linux_DB": {
"template": "ubuntu1804_x64",
"vm_sizes": {
"small": {
"cpus": 1,
"cores": 1,
"memory_mb": 1024
},
"medium": {
"cpus": 1,
"cores": 2,
"memory_mb": 2048
}
}
},
"Linux_Web": {
"template": "ubuntu1804_x64",
"vm_sizes": {
"small": {
"cpus": 1,
"cores": 1,
"memory_mb": 1024
},
"medium": {
"cpus": 1,
"cores": 2,
"memory_mb": 2048
}
}
}
}
@mrlesmithjr
Copy link
Author

mrlesmithjr commented Mar 12, 2019

[
    {
        "db01": {
            "vm_size": "medium",
            "specs": {
                "memory_mb": 2048,
                "cores": 2,
                "cpus": 1
            },
            "template": "ubuntu1804_x64"
        }
    },
    {
        "web01": {
            "vm_size": "small",
            "specs": {
                "memory_mb": 1024,
                "cores": 1,
                "cpus": 1
            },
            "template": "ubuntu1804_x64"
        }
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment