Signed-off-by: Tang Chen <tangc...@cn.fujitsu.com> --- client/virt/libvirt_vm.py | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py index ce594af..4a1409c 100644 --- a/client/virt/libvirt_vm.py +++ b/client/virt/libvirt_vm.py @@ -188,6 +188,27 @@ def virsh_dumpxml(name, uri = ""): return virsh_cmd("dumpxml %s" % name, uri) +def dumpxml_to_local_file(name, file_path, uri=""): + """ + Dump the guest's xml to a file on localhost. + @param name: VM name + @param file_path: The full path to new xml file. + If the file exists, it will be cleaned. + """ + try: + f = open(file_path, 'w') + xml = virsh_dumpxml(name, uri) + f.write(xml) + f.close() + return True + except error.CmdError, detail: + logging.error("Failed to dump xmlfile of %s to %s.\n%s", + (name, file_path, detail)) + if not f.closed: + f.close() + return False + + def virsh_is_alive(name, uri = ""): """ Return True if the domain is started/alive. @@ -689,6 +710,15 @@ class VM(virt_vm.BaseVM): return virsh_dumpxml(self.name, self.connect_uri) + def backup_xml(self, file_path): + """ + Backup the guest's xmlfile. + + @param file_path: Full path to the backup file. + """ + return dumpxml_to_local_file(self.name, file_path, self.connect_uri) + + def clone(self, name=None, params=None, root_dir=None, address_cache=None, copy_state=False): """ -- 1.7.1 _______________________________________________ Autotest mailing list Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest