def save_to_file(self, path): """ Override BaseVM save_to_file method """ state = virsh.domstate(self.name) if state not in ('paused',): raise virt_vm.VMStatusError("Cannot save a VM that is %s" % state) logging.debug("Saving VM %s to %s" %(self.name, path)) virsh.save(self.name, path, uri=self.connect_uri) state = virsh.domstate(self.name) if state not in ('shut off',): raise virt_vm.VMStatusError("VM not shut off after save")
def restore_from_file(self, path): """ Override BaseVM restore_from_file method """ state = virsh.domstate(self.name) if state not in ('shut off',): raise virt_vm.VMStatusError("Can not restore VM that is %s" % state) logging.debug("Restoring VM from %s" % path) virsh.restore(path, uri=self.connect_uri) state = virsh.domstate(self.name) if state not in ('paused','running'): raise virt_vm.VMStatusError("VM not paused after restore, it is %s." % state)
def save(name, path, **dargs): """ Store state of VM into named file. @param: name: VM Name to operate on @param: path: absolute path to state file @param: dargs: standardized virsh function API keywords """ state = domstate(name, **dargs) if state not in ('paused', ): raise virt_vm.VMStatusError("Cannot save a VM that is %s" % state) logging.debug("Saving VM %s to %s" % (name, path)) command("save %s %s" % (name, path), **dargs) # libvirt always stops VM after saving state = domstate(name, **dargs) if state not in ('shut off', ): raise virt_vm.VMStatusError("VM not shut off after save")
def virsh_save(name, path, uri=""): """ Store state of VM into named file. @param: name: VM Name to operate on @param: uri: URI of libvirt hypervisor to use @param: path: absolute path to state file """ state = virsh_domstate(name, uri) if state not in ('paused', ): raise virt_vm.VMStatusError("Cannot save a VM that is %s" % state) logging.debug("Saving VM %s to %s" % (name, path)) virsh_cmd("save %s %s" % (name, path), uri) # libvirt always stops VM after saving state = virsh_domstate(name, uri) if state not in ('shut off', ): raise virt_vm.VMStatusError("VM not shut off after save")
def restore(name, path, **dargs): """ Load state of VM from named file and remove file. @param: name: VM Name to operate on @param: path: absolute path to state file. @param: dargs: standardized virsh function API keywords """ # Blindly assume named VM corresponds with state in path # rely on higher-layers to take exception if mismatch state = domstate(name, **dargs) if state not in ('shut off', ): raise virt_vm.VMStatusError("Can not restore VM that is %s" % state) logging.debug("Restoring VM from %s" % path) command("restore %s" % path, **dargs) state = domstate(name, **dargs) if state not in ('paused', 'running'): raise virt_vm.VMStatusError("VM not paused after restore, it is %s." % state)
def virsh_restore(name, path, uri=""): """ Load state of VM from named file and remove file. @param: name: VM Name to operate on @param: uri: URI of libvirt hypervisor to use @param: path: absolute path to state file. """ # Blindly assume named VM cooresponds with state in path # rely on higher-layers to take exception if missmatch state = virsh_domstate(name, uri) if state not in ('shut off', ): raise virt_vm.VMStatusError("Can not restore VM that is %s" % state) logging.debug("Restoring VM from %s" % path) virsh_cmd("restore %s" % path, uri) state = virsh_domstate(name, uri) if state not in ('paused', 'running'): raise virt_vm.VMStatusError("VM not paused after restore, it is %s." % state)