On 06/29/2012 08:12 AM, Cleber Rosa wrote: > On 06/29/2012 06:31 AM, Yu Mingfei wrote: >> +def vm_new_name(old_vm, newname, params): >> + 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() > > ^ Chris, IMHO this is a great opportunity for trying out xml_utils. >
Yes! It needs a better search capabilities though. ElementTree is suppose to support XPATH, but I'm finding our 2.6 version isn't working well. i.e. del element.find('/name/uuid') doesn't always work as you'd expect. It seems okay with a single path token but not multiple :( I'm working on fixing that. Once it's up-to-snuff, I'll go through current code and swap it in. For now, using minidom is fine. -- Chris Evich, RHCA, RHCE, RHCDS, RHCSS Quality Assurance Engineer e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214 _______________________________________________ Autotest mailing list Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest