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