Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

coreos-base/oem-rackspace: Get public and private IP based on routes #184

Open
wants to merge 1 commit into
base: flatcar-master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions coreos-base/oem-rackspace/files/flatcar-setup-environment
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,35 @@ sed -i -e '/^FLATCAR_PUBLIC_IPV4=/d' \

# We spin loop until the nova-agent sets up the ip addresses
function get_ip () {
IF=$1
IP=
PREFIX="$1"
while [ 1 ]; do
IP=$(ifconfig $IF | awk '/inet /{print $2}')
IP=""
IF="$(ip -4 route get $PREFIX | awk '{for(i=1;i<=NF;i++)if($i=="dev")print $(i+1)}')"
if [ "$IF" != "" ] && [ "$IF" != "lo" ]; then
IP=$(ifconfig $IF | awk '/inet /{print $2}')
fi
if [ "$IP" != "" ]; then
break
fi
sleep .1
done
echo "$IP"
}

function get_private_ip () {
STARTSWITH="$1"
IP=""
while [ 1 ]; do
IP="$(ifconfig | awk "/inet $STARTSWITH/"'{print $2}' | head -n 1)"
if [ "$IP" != "" ]; then
break
fi
sleep .1
done
echo $IP
echo "$IP"
}

echo FLATCAR_PUBLIC_IPV4=$(get_ip eth0) >> $ENV
echo FLATCAR_PRIVATE_IPV4=$(get_ip eth1) >> $ENV
# Gets IP for interface with route to 1.0.0.0
echo FLATCAR_PUBLIC_IPV4=$(get_ip 1) >> $ENV
# Gets IP starting with 10.
echo FLATCAR_PRIVATE_IPV4=$(get_private_ip "10.") >> $ENV