Sorry, Chris:
I fix a bug to this patch.
if params.has_key("uri"):
uri = params.get("uri")
==>
uri = params.get("uri", "")
----
Signed-off-by: Yu Mingfei <[email protected]>
---
client/virt/libvirt_xml_utils.py | 42 ++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
create mode 100644 client/virt/libvirt_xml_utils.py
diff --git a/client/virt/libvirt_xml_utils.py b/client/virt/libvirt_xml_utils.py
new file mode 100644
index 0000000..0481db9
--- /dev/null
+++ b/client/virt/libvirt_xml_utils.py
@@ -0,0 +1,42 @@
+import logging, os, shutil
+from xml.dom.minidom import parse, parseString
+from autotest.client.shared import utils, error
+import libvirt_vm
+
+
+def create_new_vm(old_vm, newname, params):
+ """
+ Create a new vm through an exist vm,the difference is name and uuid.
+
+ @param old_vm:an exist vm object
+ @param newname:new vm name
+ @param params:params dict of your test target
+ @return:return a vm object
+ """
+ oldfile = "/etc/libvirt/qemu/%s.xml" % old_vm.name
+ newfile = "/etc/libvirt/qemu/%s.xml" % newname
+ if oldfile == newfile:
+ logging.info("use old vm.")
+ return old_vm
+ shutil.copy(oldfile, newfile)
+ dom = parse(newfile)
+ root = dom.documentElement
+ node_name = root.getElementsByTagName("name")[0]
+ node_name.firstChild.data = "%s" % newname
+ node_uuid = root.getElementsByTagName("uuid")[0]
+ root.removeChild(node_uuid)
+ f=open(newfile, "w")
+ dom.writexml(f)
+ f.close()
+
+ if not os.path.exists(newfile):
+ raise error.TestError("Failed to create xml file.")
+
+ uri = params.get("uri", "")
+ status = libvirt_vm.virsh_define(newfile, uri)
+ if not status:
+ os.remove(newfile)
+ raise error.TestError("Failed to define a VM.")
+
+ new_vm = libvirt_vm.VM(newname, params, old_vm.root_dir,
old_vm.address_cache)
+ return new_vm
--
1.7.1
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest