F #911: Add alias/es support IPv4 (#136)

* Add alias debian context.
* Add alias centos context.
* Add alias alpine context.
pull/137/head
Alejandro Huertas Herrero 6 years ago committed by Vlastimil Holer
parent 7a4a8e3ec9
commit 003e7d117c

@ -123,6 +123,16 @@ EOT
echo ""
}
gen_alias_conf() {
cat <<EOT
iface $DEV inet static
address $IP
netmask $MASK
EOT
echo ""
}
gen_iface6_conf() {
cat <<EOT
iface $DEV inet6 static
@ -171,6 +181,11 @@ get_context_interfaces()
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_interface_alias()
{
env | grep -E "^ETH${INDEX}_ALIAS[0-9]+_MAC=" | cut -d '_' -f 2 | sort
}
get_dev()
{
list="$1"
@ -218,6 +233,21 @@ EOT
[[ -n $IP ]] && gen_iface_conf
[[ -n $IP6 ]] && gen_iface6_conf
INDEX=${interface: -1}
ALIAS=$(get_interface_alias)
for nic_alias in $ALIAS; do
UPCASE_DEV="ETH${INDEX}_${nic_alias}"
IP=$(get_ip)
MASK=$(get_mask)
EXTERNAL=$(get_iface_var "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
if [[ -n $IP ]] && ([ -z "${EXTERNAL}" ] || [ $EXTERNAL == "NO" ]); then
gen_alias_conf
fi
done
done
}

@ -152,6 +152,16 @@ EOT
echo ""
}
gen_alias_conf() {
cat <<EOT
iface $DEV inet static
address $IP
netmask $MASK
EOT
echo ""
}
gen_iface6_conf() {
cat <<EOT
iface $DEV inet6 static
@ -198,6 +208,12 @@ get_context_interfaces()
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_interface_alias()
{
env | grep -E "^ETH${INDEX}_ALIAS[0-9]+_MAC=" | cut -d '_' -f 2 | sort
}
get_dev()
{
list="$1"
@ -244,6 +260,20 @@ EOT
[[ -n $IP ]] && gen_iface_conf
[[ -n $IP6 ]] && gen_iface6_conf
INDEX=${interface: -1}
ALIAS=$(get_interface_alias)
for nic_alias in $ALIAS; do
UPCASE_DEV="ETH${INDEX}_${nic_alias}"
IP=$(get_ip)
MASK=$(get_mask)
EXTERNAL=$(get_iface_var "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
if [ ! -z $IP ] && ([ -z "${EXTERNAL}" ] || [ $EXTERNAL == "NO" ]); then
gen_alias_conf
fi
done
done
}

@ -117,6 +117,12 @@ EOT
fi
}
gen_alias_conf() {
cat <<EOT
IPADDR$ALIAS_INDEX="$IP"
EOT
}
gen_iface6_conf() {
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "IPADDR_0=$IP6/${IP6_PREFIX_LENGTH:-64}"
@ -164,6 +170,11 @@ get_context_interfaces()
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort
}
get_interface_alias()
{
env | grep -E "^ETH${INDEX}_ALIAS[0-9]+_MAC=" | cut -d '_' -f 2 | sort
}
get_dev()
{
list="$1"
@ -221,9 +232,27 @@ EOT
echo "ONBOOT=yes"
fi
INDEX=${interface: -1}
ALIAS=$(get_interface_alias)
ALIAS_INDEX=0
[[ -n $IP ]] && gen_iface_conf
[[ -n $IP6 ]] && gen_iface6_conf
for nic_alias in $ALIAS; do
UPCASE_DEV="ETH${INDEX}_${nic_alias}"
IP=$(get_ip)
MASK=$(get_mask)
EXTERNAL=$(get_iface_var "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
if [ -n $IP ] && ([ -z "${EXTERNAL}" ] || [ $EXTERNAL == "NO" ]); then
gen_alias_conf
fi
ALIAS_INDEX=$((ALIAS_INDEX + 1))
done
) > ${CONFIG_PATH}/ifcfg-${DEV}
ifup ${DEV}

Loading…
Cancel
Save