On 07/03/2012 04:05 PM, Yu Mingfei wrote: > On 7/3/2012 3:52 PM, Alex Jia wrote: >> On 07/03/2012 03:46 PM, Alex Jia wrote: >>> On 07/03/2012 02:35 PM, Yu Mingfei wrote: >>>> This patch adds a new filefor xml functions. >>>> >>>> Signed-off-by: Yu Mingfei<[email protected]> >>>> --- >>>> client/virt/libvirt_xml_utils.py | 43 >>>> ++++++++++++++++++++++++++++++++++++++ >>>> 1 files changed, 43 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..84a21b6 >>>> --- /dev/null >>>> +++ b/client/virt/libvirt_xml_utils.py >>>> @@ -0,0 +1,43 @@ >>>> +import logging, os, shutil >>>> +from xml.dom.minidom import parse, parseString >>>> +from autotest.client.shared import utils, error >>>> +import libvirt_vm >> from autotest.client.virt import libvirt_vm > I put libvirt_xml_utils.py in virt directory, > and libvirt_vm.py is also in this directory. > So I use "import libvirt_vm" directly.^^ I see, but you should keep consistent with previous codes, and your PATCH 2/3 v2 is using from autotest.client.virt 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. >>> It just renames a vm, couldn't virsh edit do this? > Yes > >>>> + >>>> + @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.") >>>> + >>>> + if params.has_key("uri"): >>>> + 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 >>> _______________________________________________ >>> Autotest mailing list >>> [email protected] >>> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest >> >> >> >
_______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
