Correct bug where starting a running instance triggered failed state

This commit is contained in:
Joshua Boniface 2018-08-23 19:01:57 -04:00
parent 57b3c62fb0
commit 09b4191427
1 changed files with 24 additions and 11 deletions

View File

@ -115,19 +115,32 @@ class VMInstance:
self.instart = False self.instart = False
return return
# Try to get the current state in case it's already running
try: try:
# Grab the domain information from Zookeeper self.dom = self.lookupByUUID(self.domuuid)
xmlconfig = zkhandler.readdata(self.zk_conn, '/domains/{}/xml'.format(self.domuuid)) curstate = self.dom.state()[0]
dom = lv_conn.createXML(xmlconfig, 0) except:
curstate = 'notstart'
if curstate == libvirt.VIR_DOMAIN_RUNNING:
# If it is running just update the model
self.addDomainToList() self.addDomainToList()
ansiiprint.echo('Successfully started VM', '{}:'.format(self.domuuid), 'o')
self.dom = dom
zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): '' }) zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): '' })
except libvirt.libvirtError as e: else:
ansiiprint.echo('Failed to create VM', '{}:'.format(self.domuuid), 'e') # Or try to create it
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'failed' }) try:
zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): str(e) }) # Grab the domain information from Zookeeper
self.dom = None xmlconfig = zkhandler.readdata(self.zk_conn, '/domains/{}/xml'.format(self.domuuid))
dom = lv_conn.createXML(xmlconfig, 0)
self.addDomainToList()
ansiiprint.echo('Successfully started VM', '{}:'.format(self.domuuid), 'o')
self.dom = dom
zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): '' })
except libvirt.libvirtError as e:
ansiiprint.echo('Failed to create VM', '{}:'.format(self.domuuid), 'e')
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'failed' })
zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): str(e) })
self.dom = None
lv_conn.close() lv_conn.close()
self.instart = False self.instart = False