Index: lib/cros_build_lib.py |
diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py |
index ec7c0281676ee5b7fa8082f73e26e47c3206868c..906b7b4bad046cc98827b5277ed0de0b0c979b51 100644 |
--- a/lib/cros_build_lib.py |
+++ b/lib/cros_build_lib.py |
@@ -6,6 +6,7 @@ |
import inspect |
import os |
+import re |
import subprocess |
import sys |
@@ -239,3 +240,21 @@ def ReinterpretPathForChroot(path): |
new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) |
return new_path |
+ |
+ |
+def GetIPAddress(device='eth0'): |
+ """Returns the IP Address for a given device using ifconfig. |
+ |
+ socket.gethostname() is insufficient for machines where the host files are |
+ not set up "correctly." Since some of our builders may have this issue, |
+ this method gives you a generic way to get the address so you are reachable |
+ either via a VM or remote machine on the same network. |
+ """ |
+ ifconfig_output = RunCommand(['ifconfig', device], redirect_stdout=True, |
+ print_cmd=False) |
+ match = re.search('.*inet addr:(\d+\.\d+\.\d+\.\d+).*', ifconfig_output) |
+ if match: |
+ return match.group(1) |
+ else: |
+ Warning('Failed to find ip address in %s' % ifconfig_output) |
+ return None |