On 07/11/2012 10:39 AM, Yu Mingfei wrote: > On 7/10/2012 11:44 PM, Alex Jia wrote: >> As I said, virsh domname case should receive different id or uuid >> rather than different domain name, so I thinks it's irrelevant with >> this case. > I will discuss with my partner.Thanks for your comment.^^ > >> >> In addition, as we discussed, if you want to operate XML, you should >> spit it into libvirt_xml relevant module, I think it should be common >> function for XML's adding, deleting, searching, modifying. > I have thought about it. > But I do not know where I should put rename_xml_utils() in. > If you have idea about it, tell me please.^_^
It should be common class or function for guest, network, storage, etc XML configuration adding/deleting/searching/modifying, for example: class VMXmlUtils(): def __init__(self, vm_xml): self.xml = vm_xml def add(self, cxt): XXXXXXX def delete(self, cxt): XXXXXXX def search(self, cxt): XXXXXXX def modify(self, cxt): XXXXXXX class NetworkXmlUtils(): XXXXXX Of course, it's just my thought, maybe, other guys have better idea or advise. > > BTW, do you have objection with vm.rename()? vm.rename() is fine for me, It just is irrelevant with this case. > I will use it in later patchs, for example, virsh schedinfo <vm_name > or id>. > vm_name will be changed to different type for command "virsh > schedinfo"'s test. could you explain more? I think it should be different guest, if you just rename guest without modifying others then virsh schedinfo will get the same 'cpu_shares', 'vcpu_period' and 'vcpu_quota'. if you want to change guest relevant XML configuration without any affect on guest, maybe, snapshot or clone is a good idea. What do you think? > >> >> Alex >> >> ----- Original Message ----- >> From: "Yu Mingfei"<yuming...@cn.fujitsu.com> >> To: "Chris Evich"<cev...@redhat.com>, "Lucas Meneghel >> Rodrigues"<l...@redhat.com>, "Alex Jia"<a...@redhat.com> >> Cc: autotest@test.kernel.org >> Sent: Tuesday, July 10, 2012 8:59:34 AM >> Subject: [PATCH 1/3]Add virsh domname testcases for libvirt >> >> This patch add a function rename to VM class. >> Rename() changes VM's name to a new name. >> >> Signed-off-by: Yu Mingfei<yuming...@cn.fujitsu.com> >> --- >> client/virt/libvirt_vm.py | 60 >> +++++++++++++++++++++++++++++++++++++++++++++ >> 1 files changed, 60 insertions(+), 0 deletions(-) >> >> diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py >> index d97ac0c..e2d0daf 100644 >> --- a/client/virt/libvirt_vm.py >> +++ b/client/virt/libvirt_vm.py >> @@ -1597,3 +1597,63 @@ class VM(virt_vm.BaseVM): >> Override BaseVM restore_from_file method >> """ >> virsh_restore(self.name, path, uri=self.connect_uri) >> + >> + >> + def rename(self, newname): >> + """ >> + Rename this vm. >> + @param newname:new name of vm. >> + @return:True or False >> + """ >> + def rename_xml_utils(xml_path, newname): >> + """ >> + Modify name in an xml file. >> + @param xml_path:xml file path >> + """ >> + dom = minidom.parse(xml_path) >> + 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(xml_path, "w") >> + dom.writexml(f) >> + f.close() >> + >> + if self.name == newname: >> + logging.error("Error:Please give a different name with >> current.") >> + return False >> + >> + #Create a new xml file for new vm >> + new_vm_tmp_xml = self.backup_xml() >> + try: >> + rename_xml_utils(new_vm_tmp_xml, newname) >> + except Exception, detail: >> + logging.error("Error:Edit xml failed: %s", detail) >> + if os.path.exists(new_vm_tmp_xml): >> + os.remove(new_vm_tmp_xml) >> + return False >> + >> + #Undefine old vm and define new vm >> + old_vm_tmp_xml = self.backup_xml() >> + if not self.undefine(): >> + logging.error("Error:Undefine %s failed.", self.name) >> + if os.path.exists(new_vm_tmp_xml): >> + os.remove(new_vm_tmp_xml) >> + if os.path.exists(old_vm_tmp_xml): >> + os.remove(old_vm_tmp_xml) >> + return False >> + if not self.define(new_vm_tmp_xml): >> + logging.error("Error:Define %s failed.", newname) >> + self.define(old_vm_tmp_xml) >> + return False >> + logging.debug("Rename %s to %s succeed.", self.name, newname) >> + self.name = newname >> + >> + #delete tmp files >> + if os.path.exists(new_vm_tmp_xml): >> + os.remove(new_vm_tmp_xml) >> + if os.path.exists(old_vm_tmp_xml): >> + os.remove(old_vm_tmp_xml) >> + return True >> + >> -- 1.7.1 >> >> >> > _______________________________________________ Autotest mailing list Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest