[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

View file

@ -6,6 +6,7 @@ from xmltodict import parse
from config import config from config import config
from ldap_list import vm_list from ldap_list import vm_list
from db_export import setconn from db_export import setconn
from db_export import delconn
# Constants # Constants
ALL_VM_STATES = -1 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(): def main():
with RPCClient(opnserver) as rpc_client: with RPCClient(opnserver) as rpc_client:
success, response, *_ = rpc_client.one.vmpool.infoextended( success, response, *_ = rpc_client.one.vmpool.infoextended(
@ -76,13 +93,31 @@ def main():
vm_port = vm['TEMPLATE']['GRAPHICS'].get('PORT') 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: 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) setconn(entry.uid, vm_id, vm_port, vm_host)
else: else:
print(response) 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__": if __name__ == "__main__":
main() main()