Handle the case when libvirt object doesn't exists for given VM
This can be some "virtual" VM (like dom0).
This commit is contained in:
parent
5763beb898
commit
c3d9b1971a
@ -666,8 +666,16 @@ class QubesVm(object):
|
|||||||
domain_config = self.create_config_file()
|
domain_config = self.create_config_file()
|
||||||
if self._libvirt_domain:
|
if self._libvirt_domain:
|
||||||
self._libvirt_domain.undefine()
|
self._libvirt_domain.undefine()
|
||||||
|
try:
|
||||||
self._libvirt_domain = vmm.libvirt_conn.defineXML(domain_config)
|
self._libvirt_domain = vmm.libvirt_conn.defineXML(domain_config)
|
||||||
self.uuid = uuid.UUID(bytes=self._libvirt_domain.UUID())
|
self.uuid = uuid.UUID(bytes=self._libvirt_domain.UUID())
|
||||||
|
except libvirt.libvirtError:
|
||||||
|
if libvirt.virGetLastError()[0] == libvirt.VIR_ERR_NO_DOMAIN:
|
||||||
|
# accept the fact that libvirt doesn't know anything about this
|
||||||
|
# domain...
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def libvirt_domain(self):
|
def libvirt_domain(self):
|
||||||
@ -695,6 +703,9 @@ class QubesVm(object):
|
|||||||
if dry_run:
|
if dry_run:
|
||||||
return 666
|
return 666
|
||||||
|
|
||||||
|
if self.libvirt_domain is None:
|
||||||
|
return 0
|
||||||
|
|
||||||
if not self.libvirt_domain.isActive():
|
if not self.libvirt_domain.isActive():
|
||||||
return 0
|
return 0
|
||||||
return self.libvirt_domain.info()[1]
|
return self.libvirt_domain.info()[1]
|
||||||
@ -745,6 +756,9 @@ class QubesVm(object):
|
|||||||
return "NA"
|
return "NA"
|
||||||
|
|
||||||
libvirt_domain = self.libvirt_domain
|
libvirt_domain = self.libvirt_domain
|
||||||
|
if libvirt_domain is None:
|
||||||
|
return "NA"
|
||||||
|
|
||||||
if libvirt_domain.isActive():
|
if libvirt_domain.isActive():
|
||||||
if libvirt_domain.state()[0] == libvirt.VIR_DOMAIN_PAUSED:
|
if libvirt_domain.state()[0] == libvirt.VIR_DOMAIN_PAUSED:
|
||||||
return "Paused"
|
return "Paused"
|
||||||
@ -1722,12 +1736,18 @@ class QubesVm(object):
|
|||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.is_running():
|
||||||
|
raise QubesException ("VM not running!")
|
||||||
|
|
||||||
self.libvirt_domain.suspend()
|
self.libvirt_domain.suspend()
|
||||||
|
|
||||||
def unpause(self):
|
def unpause(self):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.is_paused():
|
||||||
|
raise QubesException ("VM not paused!")
|
||||||
|
|
||||||
self.libvirt_domain.resume()
|
self.libvirt_domain.resume()
|
||||||
|
|
||||||
def get_xml_attrs(self):
|
def get_xml_attrs(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user