[PATCH 1/4] client.bin.net.net_utils: Introduce get_local_ip()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Get ip address in local system which can communicate
with a given ip, that will be useful for subtests like
netperf2.

Signed-off-by: Jiri Zupka <jzupka@xxxxxxxxxx>
---
 client/bin/net/net_utils.py |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/client/bin/net/net_utils.py b/client/bin/net/net_utils.py
index 868958c..7c96ba0 100644
--- a/client/bin/net/net_utils.py
+++ b/client/bin/net/net_utils.py
@@ -5,6 +5,7 @@ This library is to release in the public repository.
 
 import commands, os, re, socket, sys, time, struct
 from autotest_lib.client.common_lib import error
+from autotest_lib.client.bin import utils as client_utils
 import utils
 
 TIMEOUT = 10 # Used for socket timeout and barrier timeout
@@ -27,6 +28,22 @@ class network_utils(object):
         utils.system('/sbin/ifconfig -a')
 
 
+    def get_ip_local(self, query_ip, netmask="24"):
+        """
+        Get ip address in local system which can communicate with query_ip.
+
+        @param query_ip: IP of client which wants to communicate with
+                autotest machine.
+        @return: IP address which can communicate with query_ip
+        """
+        ip = client_utils.system_output("ip addr show to %s/%s" %
+                                        (query_ip, netmask))
+        ip = re.search(r"inet ([0-9.]*)/",ip)
+        if ip is None:
+            return ip
+        return ip.group(1)
+
+
     def disable_ip_local_loopback(self, ignore_status=False):
         utils.system("echo '1' > /proc/sys/net/ipv4/route/no_local_loopback",
                      ignore_status=ignore_status)
-- 
1.7.5.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux