def resume(self): self.say("resuming...") domain = self.get_domain(self.entity(), raise_exception=False) if not domain: self.warn("does not exist") return if domain_has_state(domain, libvirt.VIR_DOMAIN_RUNNING): self.say("is already running") return if not domain_has_state(domain, libvirt.VIR_DOMAIN_PAUSED): self.say("is not suspended") return self.each_child("resume") domain.resume() if not domain_wait_state(domain, libvirt.VIR_DOMAIN_RUNNING): self.warn("could not resumed") return self.success("resumed!") self.each_child("after_resume") self.finalize()
def resume(self): self.say("resuming...") domain = self.get_domain(self.entity(), raise_exception=False) if not domain: self.warn("does not exist") return if domain_has_state(domain, libvirt.VIR_DOMAIN_RUNNING): self.say("is already running") return if not domain_has_state(domain, libvirt.VIR_DOMAIN_PAUSED): self.say("is not suspended") return self.each_child("resume") domain.resume() if not domain_wait_state(domain, libvirt.VIR_DOMAIN_RUNNING): self.warn("could not resumed") return self.success("resumed!") self.each_child("after_resume")
def destroy(self): self.say("destroying...") domain = self.get_domain(self.entity(), raise_exception=False) if not domain: self.warn("does not exist") return if domain_has_state(domain, libvirt.VIR_DOMAIN_PAUSED): domain.resume() if domain_has_state(domain, libvirt.VIR_DOMAIN_RUNNING): self._stop_domain(domain, force=True) if domain.isActive(): raise error.Bug("Could not remove running " "domain {}".format(self.ident())) self.each_child("destroy", reverse=True) domain.undefine() self.success("removed!") self.each_child("after_destroy", reverse=True)
def _stop_domain(self, domain, force=False): if not domain.isActive(): self.say("is already stopped") return if domain_has_state(domain, libvirt.VIR_DOMAIN_PAUSED): domain.resume() domain.shutdown() if not wait_until_inactive(domain): # Try to force off domain.destroy() if not wait_until_inactive(domain): self.warn("could not be stopped") return self.success("stopped!")
def suspend(self): self.say("suspending...") domain = self.get_domain(self.entity(), raise_exception=False) if not domain: self.warn("does not exist") return if domain_has_state(domain, libvirt.VIR_DOMAIN_PAUSED): self.warn("is already suspended") return self.each_child("suspend") domain.suspend() if not domain_wait_state(domain, libvirt.VIR_DOMAIN_PAUSED): self.warn("failed to suspend") return self.success("suspended!")
def test_domain_has_state(): domain = FakeDomain(libvirt.VIR_DOMAIN_PAUSED) assert(util.domain_has_state(domain, libvirt.VIR_DOMAIN_PAUSED))