[VNC] update get_info.py for Task#10544

This commit is contained in:
kjg 2022-05-09 14:53:51 +00:00
parent 9da4900070
commit 0a9c8f8245
1 changed files with 38 additions and 3 deletions

View File

@ -6,6 +6,7 @@ from xmltodict import parse
from config import config
from ldap_list import vm_list
from db_export import setconn
from db_export import delconn
# Constants
ALL_VM_STATES = -1
@ -61,6 +62,22 @@ class VM:
}
class tVM:
def __init__(self, tvm: dict):
self.id = vm.get('ID', None)
self.owner = {
'id': vm.get('UID', None),
'name': vm.get('UNAME', None),
'gname': vm.get('GNAME', None)
}
self.name = vm.get('NAME', None)
self.status = vm.get('STATE', None)
if self.status:
self.status = VMState(int(self.status)).name.lower()
template = vm['TEMPLATE']
def main():
with RPCClient(opnserver) as rpc_client:
success, response, *_ = rpc_client.one.vmpool.infoextended(
@ -74,15 +91,33 @@ def main():
vm_user = vm['UNAME']
vm_id = vm['ID']
vm_port = vm['TEMPLATE']['GRAPHICS'].get('PORT')
vm_host = vm['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
vm_host = vm['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
if vm['UNAME'] == temp_uname:
#print(entry.uid, vm_id, vm_port, vm_host)
print(entry.uid, vm_id, vm_port, vm_host)
setconn(entry.uid, vm_id, vm_port, vm_host)
else:
print(response)
with RPCClient(opnserver) as rpc_client2:
success, response, *_ = rpc_client2.one.vmpool.infoextended(
session_string , VmFilterFlag.AllResources.value, START_ID, END_ID, VMState.DONE.value
)
if success:
vms2 = json.loads(json.dumps(parse(response)))['VM_POOL']['VM']
for entry in vm_list.entries:
temp_uname = entry.uid
for i, tvm in enumerate(vms2):
vm_user = tvm['UNAME']
vm_id = tvm['ID']
if tvm['UNAME'] == temp_uname:
print("terminated VM : ", entry.uid, vm_id)
delconn(entry.uid, vm_id)
else:
print(response)
if __name__ == "__main__":
main()