From mboxrd@z Thu Jan 1 00:00:00 1970 From: Amos Kong Subject: [PATCH v2 02/17] Add a get_ifname function Date: Mon, 23 Aug 2010 16:52:03 +0800 Message-ID: <20100823085203.19173.14718.stgit@190> References: <20100823084745.19173.61655.stgit@190> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: lmr@redhat.com, kvm@vger.kernel.org To: autotest@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:59478 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751772Ab0HWItH (ORCPT ); Mon, 23 Aug 2010 04:49:07 -0400 In-Reply-To: <20100823084745.19173.61655.stgit@190> Sender: kvm-owner@vger.kernel.org List-ID: It's more clear to use 'nic_mode + nic_index + vnc_port' than 'tap0', It's also unique for one guest. Signed-off-by: Amos Kong --- 0 files changed, 0 insertions(+), 0 deletions(-) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 6812c98..e4f216c 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -428,7 +428,7 @@ class VM: if tftp: tftp = kvm_utils.get_path(root_dir, tftp) qemu_cmd += add_net(help, vlan, nic_params.get("nic_mode", "user"), - nic_params.get("nic_ifname"), + self.get_ifname(vlan), script, downscript, tftp, nic_params.get("bootp"), redirs, self.netdev_id[vlan]) @@ -960,6 +960,24 @@ class VM: "redirected" % port) return self.redirs.get(port) + def get_ifname(self, nic_index=0): + """ + Return the ifname of tap device for the guest nic. + + The vnc_port is unique for each VM, nic_index is unique for each nic + of one VM, it can avoid repeated ifname. + + @param nic_index: Index of the NIC + """ + nics = kvm_utils.get_sub_dict_names(self.params, "nics") + nic_name = nics[nic_index] + nic_params = kvm_utils.get_sub_dict(self.params, nic_name) + if nic_params.get("nic_ifname"): + return nic_params.get("nic_ifname") + else: + return "%s_%s_%s" % (nic_params.get("nic_model"), + nic_index, self.vnc_port) + def get_macaddr(self, nic_index=0): """ Return the macaddr of guest nic.