Merge "Add dhcp support for ramdisk element."

This commit is contained in:
Jenkins 2014-07-18 12:23:45 +00:00 committed by Gerrit Code Review
commit fc5e791a6b
6 changed files with 46 additions and 18 deletions

View File

@ -0,0 +1 @@
dhclient

View File

@ -0,0 +1 @@
pkg-map

View File

@ -34,10 +34,12 @@ mount -t proc proc /proc
readonly _BOOTIF_=$(get_kernel_parameter BOOTIF)
readonly _IP_=$(get_kernel_parameter ip)
readonly BOOT_MAC_ADDRESS=$(echo "$_BOOTIF_" | sed -e "s/-/:/g" | sed -e "s/^01://g" | tr 'a-f' 'A-F')
readonly BOOT_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1)
readonly BOOT_SERVER=$(echo "$_IP_" | cut -d':' -f2)
readonly BOOT_NETMASK=$(echo "$_IP_" | cut -d':' -f4)
readonly BOOT_GATEWAY=$(echo "$_IP_" | cut -d':' -f3)
# IP address and other parameters may be set later in the init script
BOOT_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1)
BOOT_NETMASK=$(echo "$_IP_" | cut -d':' -f4)
BOOT_GATEWAY=$(echo "$_IP_" | cut -d':' -f3)
readonly DISK=$(get_kernel_parameter disk)

View File

@ -26,20 +26,35 @@ if [ $rv -ne 0 ]; then
troubleshoot
fi
fi
ifconfig "$BOOT_INTERFACE" "$BOOT_IP_ADDRESS" netmask "$BOOT_NETMASK"
route del default || true
route add default gw $BOOT_GATEWAY
echo "pinging to boot server $BOOT_SERVER"
w=30
while [ $w -gt 0 ]; do
ping -c 5 -q "$BOOT_SERVER" > /dev/null
if [ $? -eq 0 ]; then
break
# Check if boot IP address was specific or retrieve from DHCP
if [ -n "$BOOT_IP_ADDRESS" ]; then
ifconfig "$BOOT_INTERFACE" "$BOOT_IP_ADDRESS" netmask "$BOOT_NETMASK"
route del default || true
route add default gw $BOOT_GATEWAY
else
dhclient -1 "$BOOT_INTERFACE"
if [[ $? == 2 ]]; then
echo "Error getting IP address for $BOOT_INTERFACE with MAC \
$BOOT_MAC_ADDRESS"
troubleshoot
fi
sleep 1
w=`expr $w - 5`
done
BOOT_IP_ADDRESS=$(ifconfig "$BOOT_INTERFACE" | grep 'inet addr:' | \
cut -d: -f2 | awk '{ print $1}')
BOOT_NETMASK=$(ifconfig "$BOOT_INTERFACE" | grep 'Mask:' | cut -d':' -f4)
BOOT_GATEWAY=$(route -n | grep "$BOOT_INTERFACE" | grep '^0.0.0.0' | \
awk '{print $2}')
echo "obtained the following from dhcp: "
echo " ip address = $BOOT_IP_ADDRESS"
echo " netmask = $BOOT_NETMASK"
echo " gateway = $BOOT_GATEWAY"
fi
if [ -n "$BOOT_SERVER" ]; then
echo "pinging to boot server $BOOT_SERVER"
wait_for 6 1 ping -c 5 -q "$BOOT_SERVER" > /dev/null
fi
echo "network ready"

View File

@ -2,6 +2,5 @@
set -eux
set -o pipefail
if [ "opensuse" = "$DISTRO_NAME" ]; then
install-packages dhcp-client
fi
DHCP_CLIENT=$(pkg-map --element ramdisk dhcp_client)
install-packages $DHCP_CLIENT

10
elements/ramdisk/pkg-map Normal file
View File

@ -0,0 +1,10 @@
{
"family":{
"debian":{
"dhcp_client":"isc-dhcp-client"
}
},
"default":{
"dhcp_client":"dhclient"
}
}