Systematize logging output
This commit is contained in:
parent
7b427a8730
commit
89e7a2b5b3
|
@ -23,7 +23,7 @@ class VMInstance:
|
||||||
libvirt_name = "qemu:///system"
|
libvirt_name = "qemu:///system"
|
||||||
conn = libvirt.open(libvirt_name)
|
conn = libvirt.open(libvirt_name)
|
||||||
if conn == None:
|
if conn == None:
|
||||||
print('>>> Failed to open local libvirt connection.')
|
print('>>> %s - Failed to open local libvirt connection.' % self.domuuid)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -55,12 +55,12 @@ class VMInstance:
|
||||||
|
|
||||||
# Start up the VM
|
# Start up the VM
|
||||||
def start_vm(self, conn, xmlconfig):
|
def start_vm(self, conn, xmlconfig):
|
||||||
print(">>> Starting VM %s" % self.domuuid)
|
print(">>> %s - Starting VM" % self.domuuid)
|
||||||
self.instart = True
|
self.instart = True
|
||||||
try:
|
try:
|
||||||
dom = conn.createXML(xmlconfig, 0)
|
dom = conn.createXML(xmlconfig, 0)
|
||||||
except libvirt.libvirtError as e:
|
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'))
|
self.zk.set(self.zkey + '/state', 'stop'.encode('ascii'))
|
||||||
|
|
||||||
if not self.domuuid in self.thishypervisor.domain_list:
|
if not self.domuuid in self.thishypervisor.domain_list:
|
||||||
|
@ -71,7 +71,7 @@ class VMInstance:
|
||||||
|
|
||||||
# Stop the VM forcibly
|
# Stop the VM forcibly
|
||||||
def stop_vm(self):
|
def stop_vm(self):
|
||||||
print(">>> Forcibly stopping VM %s" % self.domuuid)
|
print(">>> %s - Forcibly stopping VM" % self.domuuid)
|
||||||
self.instop = True
|
self.instop = True
|
||||||
self.dom.destroy()
|
self.dom.destroy()
|
||||||
if self.domuuid in self.thishypervisor.domain_list:
|
if self.domuuid in self.thishypervisor.domain_list:
|
||||||
|
@ -86,7 +86,7 @@ class VMInstance:
|
||||||
|
|
||||||
# Shutdown the VM gracefully
|
# Shutdown the VM gracefully
|
||||||
def shutdown_vm(self):
|
def shutdown_vm(self):
|
||||||
print(">>> Stopping VM %s" % self.domuuid)
|
print(">>> %s - Gracefully stopping VM" % self.domuuid)
|
||||||
self.inshutdown = True
|
self.inshutdown = True
|
||||||
self.dom.shutdown()
|
self.dom.shutdown()
|
||||||
try:
|
try:
|
||||||
|
@ -96,6 +96,7 @@ class VMInstance:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
if tick >= 60:
|
if tick >= 60:
|
||||||
|
print(">>> %s - Shutdown timeout expired" % self.domuuid)
|
||||||
self.stop_vm()
|
self.stop_vm()
|
||||||
self.inshutdown = False
|
self.inshutdown = False
|
||||||
return
|
return
|
||||||
|
@ -114,14 +115,14 @@ class VMInstance:
|
||||||
|
|
||||||
# Migrate the VM to a target host
|
# Migrate the VM to a target host
|
||||||
def migrate_vm(self):
|
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
|
self.inmigrate = True
|
||||||
try:
|
try:
|
||||||
dest_conn = libvirt.open('qemu+tcp://%s/system' % self.hypervisor)
|
dest_conn = libvirt.open('qemu+tcp://%s/system' % self.hypervisor)
|
||||||
if dest_conn == None:
|
if dest_conn == None:
|
||||||
raise
|
raise
|
||||||
except:
|
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 + '/hypervisor', self.thishypervisor.name.encode('ascii'))
|
||||||
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
||||||
return
|
return
|
||||||
|
@ -130,9 +131,9 @@ class VMInstance:
|
||||||
target_dom = self.dom.migrate(dest_conn, libvirt.VIR_MIGRATE_LIVE, None, None, 0)
|
target_dom = self.dom.migrate(dest_conn, libvirt.VIR_MIGRATE_LIVE, None, None, 0)
|
||||||
if target_dom == None:
|
if target_dom == None:
|
||||||
raise
|
raise
|
||||||
print('>>> Migrated successfully')
|
print('>>> %s - Migrated successfully' % self.domuuid)
|
||||||
except:
|
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()
|
self.stop_vm()
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
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)
|
# Receive the migration from another host (wait until VM is running)
|
||||||
def receive_migrate(self, conn):
|
def receive_migrate(self, conn):
|
||||||
print('>>> Receiving migration of %s' % self.domuuid)
|
print('>>> %s - Receiving migration' % self.domuuid)
|
||||||
self.inreceive = True
|
self.inreceive = True
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -162,7 +163,7 @@ class VMInstance:
|
||||||
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
||||||
if not self.domuuid in self.thishypervisor.domain_list:
|
if not self.domuuid in self.thishypervisor.domain_list:
|
||||||
self.thishypervisor.domain_list.append(self.domuuid)
|
self.thishypervisor.domain_list.append(self.domuuid)
|
||||||
print('>>> Migrated successfully')
|
print('>>> %s - Migrated successfully' % self.domuuid)
|
||||||
self.inreceive = False
|
self.inreceive = False
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -173,7 +174,7 @@ class VMInstance:
|
||||||
libvirt_name = "qemu:///system"
|
libvirt_name = "qemu:///system"
|
||||||
conn = libvirt.open(libvirt_name)
|
conn = libvirt.open(libvirt_name)
|
||||||
if conn == None:
|
if conn == None:
|
||||||
print('>>> Failed to open local libvirt connection.')
|
print('>>> %s - Failed to open local libvirt connection.' % self.domuuid)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Check the current state of the VM
|
# Check the current state of the VM
|
||||||
|
|
Loading…
Reference in New Issue