diff mbox

[RFC,02/14] KVM Test: Add a function get_interface_name() to kvm_net_utils.py

Message ID 20100720013506.2212.7371.stgit@z (mailing list archive)
State New, archived
Headers show

Commit Message

Amos Kong July 20, 2010, 1:35 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_net_utils.py b/client/tests/kvm/kvm_net_utils.py
new file mode 100644
index 0000000..ede4965
--- /dev/null
+++ b/client/tests/kvm/kvm_net_utils.py
@@ -0,0 +1,18 @@ 
+import re
+
+def get_linux_ifname(session, mac_address):
+    """
+    Get the interface name through the mac address.
+
+    @param session: session to the virtual machine
+    @mac_address: the macaddress of nic
+    """
+
+    output = session.get_command_output("ifconfig -a")
+
+    try:
+        ethname = re.findall("(\w+)\s+Link.*%s" % mac_address, output,
+                             re.IGNORECASE)[0]
+        return ethname
+    except:
+        return None