boot-qemu: Use hostname -I to obtian container IP
The code was using `awk 'END{print $1}' /etc/hosts` to obtain the
container IP, it works OK for containers with IPv4-only address, but
does not work for containers with IPv6 address, because the last line of
`/etc/hosts` is IPv6 address in such containers. Then the script will
use `127.0.0.1` as the IP address to start the QEMU, which will not work
for QEMU CI because the host can not access the QEMU's ports.
Fix this by using `hostname -I` to obtain the IPv4 address.
Tested: Verify QEMU CI passes in containers with IPv6 address.
Change-Id: I3ce39b5633a913c303ccc8297cdf39a87f5be99a
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
diff --git a/scripts/boot-qemu.sh b/scripts/boot-qemu.sh
index 7b3b7a4..f4d6153 100755
--- a/scripts/boot-qemu.sh
+++ b/scripts/boot-qemu.sh
@@ -85,8 +85,8 @@
cp "${DEFAULT_IMAGE_LOC}/${MACHINE}/${DRIVE}" "${TMP_DRIVE_PATH}"
fi
-# Obtain IP from /etc/hosts if IP is not valid set to localhost
-IP=$(awk 'END{print $1}' /etc/hosts)
+# Obtain IP from `hostname -I`
+IP=$(hostname -I | awk '{print $1}')
if [[ "$IP" != *.*.*.* ]]; then
IP=127.0.0.1
fi