Skip to content

Commit

Permalink
Allow active network interface to be overriden (#2489)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna authored Sep 13, 2023
1 parent 0499672 commit 398a218
Showing 1 changed file with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,41 @@ env_and_envsubst '$EKSD_NAME' \
# directory containing the kickstart config
if [ "$IMAGE_FORMAT" = "ova" ] && \
( [ "$IMAGE_OS" = "redhat" ] || ( [ "$IMAGE_OS" = "ubuntu" ] && [ "$IMAGE_OS_VERSION" != "2004" ] ) ); then
echo "Finding correct interface for packer temporary http server"
ACTIVE_INTERFACE=""
if [ "$(uname -s)" = "Linux" ]; then
INTERFACES=($(ls /sys/class/net))
for interface in "${INTERFACES[@]}"; do
if [ "$interface" = "eth0" ] || [ "$interface" = "en0" ] || [ "$interface" = "eno1" ]; then
ACTIVE_INTERFACE=$interface
echo "Found interface: $interface"
break
fi
done
HTTP_SERVER_IP=$(ip a l $ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
elif [ "$(uname -s)" = "Darwin" ]; then
ACTIVE_INTERFACE="en0"
HTTP_SERVER_IP=$(ifconfig $ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
fi

if [ -z $ACTIVE_INTERFACE ]; then
echo "ACTIVE_INTERFACE cannot be an empty string. Please check your network configuration
and set an appropriate value for ACTIVE_INTERFACE"
exit 1
# Get Packer HTTP server IP from env var if set
PACKER_HTTP_SERVER_IP=${PACKER_HTTP_SERVER_IP:-}
if [ -z $PACKER_HTTP_SERVER_IP ]; then
# Get active network interface from env var if set
PACKER_ACTIVE_INTERFACE="${PACKER_ACTIVE_INTERFACE:-}"
if [ -z $PACKER_ACTIVE_INTERFACE ]; then
echo "Finding interface for Packer temporary HTTP server"
if [ "$(uname -s)" = "Linux" ]; then
INTERFACES=($(ls /sys/class/net))
for interface in "${INTERFACES[@]}"; do
if [ "$interface" = "eth0" ] || [ "$interface" = "en0" ] || [ "$interface" = "eno1" ]; then
PACKER_ACTIVE_INTERFACE=$interface
echo "Found interface: $interface"
break
fi
done
elif [ "$(uname -s)" = "Darwin" ]; then
PACKER_ACTIVE_INTERFACE="en0"
fi
fi

if [ -z $PACKER_ACTIVE_INTERFACE ]; then
echo "PACKER_ACTIVE_INTERFACE cannot be automatically determined. Please export PACKER_ACTIVE_INTERFACE=<Current Host's primary network interface>"
exit 1
fi

if [ "$(uname -s)" = "Linux" ]; then
PACKER_HTTP_SERVER_IP=$(ip a l $PACKER_ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
elif
[ "$(uname -s)" = "Darwin" ]; then
PACKER_HTTP_SERVER_IP=$(ifconfig $PACKER_ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
fi
fi

PACKER_HTTP_SERVER_IP=${PACKER_HTTP_SERVER_IP:-$HTTP_SERVER_IP}
if [ -z $PACKER_HTTP_SERVER_IP ]; then
echo "PACKER_HTTP_SERVER_IP cannot be automatically determined. Please export PACKER_HTTP_SERVER_IP=<Current Host's IP>"
exit 1
Expand Down

0 comments on commit 398a218

Please sign in to comment.