Last active
February 4, 2021 16:27
-
-
Save JacobCallahan/1c948ca2466aaeb5de395743f1555e19 to your computer and use it in GitHub Desktop.
generate virt-who esx json data
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
import argparse | |
import json | |
import uuid | |
def gen_json(hypervisors, guests): | |
virtwho = {} | |
hypervisor_list = [] | |
for i in range(hypervisors): | |
guest_list = [] | |
for c in range(guests): | |
guest_list.append( | |
{ | |
"guestId": str(uuid.uuid4()), | |
"state": 1, | |
"attributes": {"active": 1, "virtWhoType": "esx"}, | |
} | |
) | |
_id = str(uuid.uuid4()).replace("-", ".") | |
hypervisor_list.append({ | |
"hypervisorId": {"hypervisorId": _id}, | |
"name": str(uuid.uuid4()).replace("-", "."), | |
"guestIds": guest_list, | |
"facts": { | |
"hypervisor.type": "VMware ESXi", | |
"dmi.system.uuid": _id, | |
"cpu.cpu_socket(s)": "2", | |
} | |
}) | |
return {"hypervisors": hypervisor_list} | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"hypervisors", type=int, help="The number of hypervisors to create." | |
) | |
parser.add_argument( | |
"guests", type=int, help="The number of guests per hypervisor to create." | |
) | |
parser.add_argument("path", type=str, help="The file path to save the output to.") | |
args = parser.parse_args() | |
data = gen_json(args.hypervisors, args.guests) | |
with open(args.path, "w") as f: | |
json.dump(data, f) | |
To submit this data to satellite you can use curl.
curl -k -X POST --cert /etc/pki/consumer/cert.pem --key /etc/pki/consumer/key.pem https://<sathost>/rhsm/hypervisors -H "Content-Type: application/json" -d @"test1.json"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage examples