2020-09-24 12:41:10 +02:00
|
|
|
import requests
|
|
|
|
|
2020-10-28 09:40:34 +01:00
|
|
|
|
|
|
|
class RPCClient:
|
2020-09-24 12:41:10 +02:00
|
|
|
"""
|
|
|
|
RPCClient Class
|
|
|
|
"""
|
|
|
|
|
|
|
|
def create_vm(self, **kwargs):
|
2020-10-28 09:40:34 +01:00
|
|
|
|
|
|
|
url = "http://127.0.0.1:8080/create?"
|
2020-09-24 12:41:10 +02:00
|
|
|
if kwargs:
|
|
|
|
q = ""
|
|
|
|
for k in kwargs.keys():
|
2020-10-28 09:40:34 +01:00
|
|
|
q += "&{}={}".format(k, kwargs[k])
|
|
|
|
|
|
|
|
url += q
|
2020-09-24 12:41:10 +02:00
|
|
|
|
|
|
|
print(url)
|
2020-10-28 09:40:34 +01:00
|
|
|
resp = requests.get(url)
|
2020-09-24 12:41:10 +02:00
|
|
|
|
|
|
|
return resp.json()
|
2020-10-28 09:40:34 +01:00
|
|
|
|
2020-09-24 12:41:10 +02:00
|
|
|
def start_vm(self, vm):
|
2020-10-28 09:40:34 +01:00
|
|
|
"""get a vm and try starting it
|
2020-09-24 12:41:10 +02:00
|
|
|
return the ID or appropriate message
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def stop_vm(self, id):
|
2020-10-28 09:40:34 +01:00
|
|
|
# stops vm of a given id
|
2020-09-24 12:41:10 +02:00
|
|
|
pass
|
|
|
|
|
2020-10-28 09:40:34 +01:00
|
|
|
|
2020-09-24 12:41:10 +02:00
|
|
|
if __name__ == "__main__":
|
2020-09-26 16:46:26 +02:00
|
|
|
import random
|
2020-10-28 09:40:34 +01:00
|
|
|
|
|
|
|
client = RPCClient()
|
2020-09-24 12:41:10 +02:00
|
|
|
print("Creating VM...")
|
2020-10-28 09:40:34 +01:00
|
|
|
name = "CentOS-8-Demo-{}-{}".format(
|
|
|
|
random.sample("abcdefghijklmn", 1)[0], random.sample(range(10), 1)[0]
|
|
|
|
)
|
|
|
|
iso_src = "/home/coolguy/Downloads/CentOS-8.2.2004-x86_64-boot.iso"
|
|
|
|
img_src = "/var/lib/libvirt/images/vol.img"
|
2020-09-24 12:41:10 +02:00
|
|
|
|
2020-10-28 09:40:34 +01:00
|
|
|
vm_info = client.create_vm(name=name, iso_source=iso_src, img_source=img_src)
|
2020-09-24 12:41:10 +02:00
|
|
|
if vm_info["status"]:
|
|
|
|
print("\n\nGuest '{}' has been created and booted".format(name))
|
|
|
|
print("UUID for {}: {}".format(name, vm_info["uuid"]))
|
|
|
|
print("ID for {} : {}".format(name, vm_info["id"]))
|
|
|
|
else:
|
2020-10-28 09:40:34 +01:00
|
|
|
print(vm_info["err"])
|