This patch adds 2 functions to libvirt_vm: 1) virsh_dominfo(): return vm's information. 2) is_persistent(): return True if VM is persistent.
Signed-off-by: Tang Chen <[email protected]> --- client/virt/libvirt_vm.py | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py index c7a99b5..c73406b 100644 --- a/client/virt/libvirt_vm.py +++ b/client/virt/libvirt_vm.py @@ -106,6 +106,12 @@ def virsh_domstate(name, uri = ""): """ return virsh_cmd("domstate %s" % name, uri) +def virsh_dominfo(name, uri = ""): + """ + Return the VM information. + """ + return virsh_cmd("dominfo %s" % (name), uri) + def virsh_domid(name, uri = ""): """ Return VM's ID. @@ -443,6 +449,29 @@ class VM(virt_vm.BaseVM): """ return virsh_is_dead(self.name, self.connect_uri) + def is_persistent(self): + """ + Return True if VM is persistent. + """ + if not virsh_domain_exists(self.name, self.connect_uri): + logging.warning("VM does not exist on uri %s" % self.connect_uri) + return False + dom_info = virsh_dominfo(self.name, self.connect_uri).split("\n") + persistent_info = "" + for tmp_info in dom_info: + if tmp_info.count('Persistent'): + persistent_info = tmp_info + break + if persistent_info.count('yes'): + return True + else: + return False + + def undefine(self): + """ + Undefine the VM. + """ + return virsh_undefine(self.name, self.connect_uri) def state(self): """ -- 1.7.3.1 -- Best Regards, Tang chen _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
