diff --git a/vnc_console_connection/get_info.py b/vnc_console_connection/get_info.py index e98ae72..466417b 100755 --- a/vnc_console_connection/get_info.py +++ b/vnc_console_connection/get_info.py @@ -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() + \ No newline at end of file