Skip to content
Snippets Groups Projects
Commit c57eac21 authored by Andreas Hamacher's avatar Andreas Hamacher
Browse files

Merge branch 'hypvervisorinventory' into 'master'

helper script added

See merge request !343
parents 7cd2779c 901ad1cd
No related branches found
No related tags found
1 merge request!343helper script added
#!/usr/bin/python3
# The purpose of this script is to enrich every VM of an ansible inventory file
# in json format with the available hypervisor mapping found in /projects/pMOSP/hypervisor/
hypervisormapping = open('m3-latest', 'r') # coming from /projects/pMOSP/hypervisor/m3-latest
# for monarch see /projects/pMOSP/hypervisor/monarch-vm-hw-mapping-2020
mapping = hypervisormapping.readlines()
mapping=mapping[3:-1]
import json,socket,sys
with open('m3inventory.json') as json_file: # this file was created via m3inventory > m3inventory.json
inv = json.load(json_file)
for map in mapping:
vm=map.split('|')[2].strip()
hyp=map.split('|')[4].strip()
if vm not in inv['_meta']['hostvars'].keys():
sys.stderr.write("Not found in inventory: {}\n".format(vm))
continue
inv['_meta']['hostvars'][vm]['hypervisor_ip']=socket.gethostbyname(hyp+'-1g.erc.monash.edu')
print( "#!/bin/bash\necho '"+json.dumps(inv,indent=4, sort_keys=True)+"'")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment