From 89e7a2b5b34cbf170d1d8bd7bda4b2a9bbab43b1 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 4 Jun 2018 00:55:54 -0400 Subject: [PATCH] Systematize logging output --- VMInstance.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/VMInstance.py b/VMInstance.py index 44c45e8d..314fb1d5 100644 --- a/VMInstance.py +++ b/VMInstance.py @@ -23,7 +23,7 @@ class VMInstance: libvirt_name = "qemu:///system" conn = libvirt.open(libvirt_name) if conn == None: - print('>>> Failed to open local libvirt connection.') + print('>>> %s - Failed to open local libvirt connection.' % self.domuuid) exit(1) try: @@ -55,12 +55,12 @@ class VMInstance: # Start up the VM def start_vm(self, conn, xmlconfig): - print(">>> Starting VM %s" % self.domuuid) + print(">>> %s - Starting VM" % self.domuuid) self.instart = True try: dom = conn.createXML(xmlconfig, 0) except libvirt.libvirtError as e: - print('>>> Failed to create domain %s' % self.domuuid) + print('>>> %s - Failed to create VM' % self.domuuid) self.zk.set(self.zkey + '/state', 'stop'.encode('ascii')) if not self.domuuid in self.thishypervisor.domain_list: @@ -71,7 +71,7 @@ class VMInstance: # Stop the VM forcibly def stop_vm(self): - print(">>> Forcibly stopping VM %s" % self.domuuid) + print(">>> %s - Forcibly stopping VM" % self.domuuid) self.instop = True self.dom.destroy() if self.domuuid in self.thishypervisor.domain_list: @@ -86,7 +86,7 @@ class VMInstance: # Shutdown the VM gracefully def shutdown_vm(self): - print(">>> Stopping VM %s" % self.domuuid) + print(">>> %s - Gracefully stopping VM" % self.domuuid) self.inshutdown = True self.dom.shutdown() try: @@ -96,6 +96,7 @@ class VMInstance: time.sleep(0.5) if tick >= 60: + print(">>> %s - Shutdown timeout expired" % self.domuuid) self.stop_vm() self.inshutdown = False return @@ -114,14 +115,14 @@ class VMInstance: # Migrate the VM to a target host def migrate_vm(self): - print('>>> Migrating %s to %s' % (self.domuuid, self.hypervisor)) + print('>>> %s - Migrating VM to %s' % (self.domuuid, self.hypervisor)) self.inmigrate = True try: dest_conn = libvirt.open('qemu+tcp://%s/system' % self.hypervisor) if dest_conn == None: raise except: - print('>>> Failed to open connection to qemu+tcp://%s/system' % self.hypervisor) + print('>>> %s - Failed to open connection to qemu+tcp://%s/system; aborting migration' % self.hypervisor) self.zk.set(self.zkey + '/hypervisor', self.thishypervisor.name.encode('ascii')) self.zk.set(self.zkey + '/state', 'start'.encode('ascii')) return @@ -130,9 +131,9 @@ class VMInstance: target_dom = self.dom.migrate(dest_conn, libvirt.VIR_MIGRATE_LIVE, None, None, 0) if target_dom == None: raise - print('>>> Migrated successfully') + print('>>> %s - Migrated successfully' % self.domuuid) except: - print('>>> Could not migrate to the new domain; forcing away uncleanly') + print('>>> %s - Could not live migrate VM; forcing away uncleanly' % self.domuuid) self.stop_vm() time.sleep(0.5) self.zk.set(self.zkey + '/state', 'start'.encode('ascii')) @@ -147,7 +148,7 @@ class VMInstance: # Receive the migration from another host (wait until VM is running) def receive_migrate(self, conn): - print('>>> Receiving migration of %s' % self.domuuid) + print('>>> %s - Receiving migration' % self.domuuid) self.inreceive = True while True: try: @@ -162,7 +163,7 @@ class VMInstance: self.zk.set(self.zkey + '/state', 'start'.encode('ascii')) if not self.domuuid in self.thishypervisor.domain_list: self.thishypervisor.domain_list.append(self.domuuid) - print('>>> Migrated successfully') + print('>>> %s - Migrated successfully' % self.domuuid) self.inreceive = False # @@ -173,7 +174,7 @@ class VMInstance: libvirt_name = "qemu:///system" conn = libvirt.open(libvirt_name) if conn == None: - print('>>> Failed to open local libvirt connection.') + print('>>> %s - Failed to open local libvirt connection.' % self.domuuid) exit(1) # Check the current state of the VM