Change hostname to ip address if we can get it from ifconfig.

Change-Id: I6719ffe0c3c9356cf48b391b0a257e268eec94dc

BUG=7780
TEST=Ran it with cros_run_vm_test.

Review URL: http://codereview.chromium.org/3829002
This commit is contained in:
Chris Sosa 2010-10-15 10:43:23 -07:00
parent 365d4b0cc8
commit ccfa2ac970

View File

@ -69,6 +69,20 @@ function remote_reboot_sh {
remote_sh "$@"
}
# Returns the hostname of this machine.
# It tries to find the ipaddress using ifconfig, however, it will
# default to $HOSTNAME on failure. We try to use the ip address first as
# some targets may have dns resolution issues trying to contact back
# to us.
function get_hostname {
local hostname
# Try to parse ifconfig for ip address
hostname=$(ifconfig eth0 \
| grep 'inet addr' \
| sed 's/.\+inet addr:\(\S\+\).\+/\1/') || hostname=${HOSTNAME}
echo ${hostname}
}
# Reinterprets path from outside the chroot for use inside.
# $1 - The path to reinterpret.
function reinterpret_path_for_chroot() {
@ -169,7 +183,7 @@ function get_devserver_url {
local devserver_url=""
if [ ${FLAGS_ignore_hostname} -eq ${FLAGS_TRUE} ]; then
if [ -z ${FLAGS_update_url} ]; then
devserver_url="http://$HOSTNAME:${FLAGS_devserver_port}/update"
devserver_url="http://$(get_hostname):${FLAGS_devserver_port}/update"
else
devserver_url="${FLAGS_update_url}"
fi