Commit 212ed23d authored by Nikos Skalkotos's avatar Nikos Skalkotos

Add new DEFAULT_NIC_CONFIG configuration parameter

This can be used to define an action for the default NIC that
Ganeti will attach to an instance if none of the --net and --no-nics
input arguments are defined on the instance creation command.

This resolves #90
parent f1b97bf4
......@@ -123,6 +123,20 @@ some external programs in ``/etc/default/snf-image``:
# card's NETWORK_TAGS variable.
# STATELESS_DHCPV6_TAGS="nfdhcpd stateless_dhcpv6"
# DEFAULT_NIC_CONFIG: This option defines the network configuration to be
# performed if there is a default NIC attached to the instance with no further
# information associated with it. This will happen if the user creates an
# instance and does not define any of the --net and --no-nics input arguments.
# In this case Ganeti will create a NIC with a random MAC and set up according
# to the cluster level NIC parameters. The user may want to leave this NIC
# unconfigured (by leaving this option empty), perform "dhcp" or use one of the
# various IPv6 auto configuration methods. The supported IPv6 methods are:
# "dhcpv6" (Stateful DHCPv6), "slaac_dhcp" (Stateless DHCPv6) and "slaac"
# (Stateless Autoconfiguration). IPv4 and IPv6 configuration methods can be
# defined in conjunction using the plus (`+') sign. IPv4 must precede (e.g.:
# "dhcp+slaac_dhcp").
# DEFAULT_NIC_CONFIG="dhcp"
# UNATTEND: This variable overwrites the unattend.xml file used when deploying
# a Windows image. snf-image-helper will use its own unattend.xml file if this
# variable is empty.
......@@ -167,6 +181,9 @@ The most common configuration parameters the user may need to overwrite are:
* **PROGRESS_MONITOR**: To specify an executable that will handle the
monitoring messages exported by *snf-image*
* **DHCP_TAGS**: To specify which Ganeti networks support DHCP
* **DEFAULT_NIC_CONFIG**: To specify a configuration method for the default
NIC Ganeti will attach on instances that were created without using the
*--net* or *--no-nics* input arguments.
* **STATELESS_DHCPV6_TAGS**: To specify which Ganeti networks support SLAAC
and stateless DHCPv6
* **STATEFUL_DHCPV6_TAGS**: To specify which Ganeti networks support DHCPv6
......
......@@ -112,28 +112,47 @@ for index in $(seq 0 $((SNF_IMAGE_NIC_COUNT-1))); do
ipv6=yes
fi
ARGS="-n $index"
ARGS=("-n" "$index")
if [ "$ipv4" = yes ]; then
if [ "$dhcp" = yes ]; then
ARGS+=" -4 dhcp"
ARGS+=("-4" "dhcp")
else
ARGS+=" -4 static"
ARGS+=("-4" "static")
fi
fi
if [ "$ipv6" = yes ]; then
if [ "$dhcp6" = stateful ]; then
ARGS+=" -6 dhcp"
ARGS+=("-6" "dhcp")
elif [ "$dhcp6" = stateless ]; then
ARGS+=" -6 slaac_dhcp"
ARGS+=("-6" "slaac_dhcp")
else
ARGS+=" -6 slaac"
ARGS+=("-6" "slaac")
fi
fi
echo "Running: $networking_tool $ARGS"
"$networking_tool" $ARGS
if [ $SNF_IMAGE_NIC_COUNT -eq 1 -a "$ipv4" = "no" -a "$ipv6" = "no" ]; then
# This looks like being the default NIC.
keys=(dhcp {dhcp+,}{dhcpv6,slaac,slaac_dhcp})
values=("-4 dhcp" {"-4 dhcp ",}{"-6 dhcp","-6 slaac","-6 slaac_dhcp"})
declare -A default_nic_action
for((i=0; i<${#keys[@]}; i++)); do
default_nic_action["${keys[$i]}"]="${values[$i]}"
done
warn "Detected a default NIC with no further info associated with it."
if [ -z "$SNF_IMAGE_DEFAULT_NIC_CONFIG" ]; then
warn "No configuration for default NIC is defined"
else
warn "Performing configuration for default NIC: $SNF_IMAGE_DEFAULT_NIC_CONFIG"
ARGS+=(${default_nic_action["$SNF_IMAGE_DEFAULT_NIC_CONFIG"]})
fi
fi
echo "Running: $networking_tool ${ARGS[@]}"
"$networking_tool" "${ARGS[@]}"
done
......
......@@ -562,6 +562,21 @@ fi
: ${DHCP_TAGS:="auto dhcp nfdhcpd"}
: ${STATEFUL_DHCPV6_TAGS:="dhcpv6 stateful_dhcpv6"}
: ${STATELESS_DHCPV6_TAGS:="nfdhcpd stateless_dhcpv6"}
: ${DEFAULT_NIC_CONFIG:="dhcp"}
found=no
for val in "" dhcp {dhcp+,}{dhcpv6,slaac,slaac_dhcp}; do
if [ "$DEFAULT_NIC_CONFIG" = "$val" ]; then
found=yes
break
fi
done
if [ "$found" = "no" ]; then
log_error "DEFAULT_NIC_CONFIG (=\`$DEFAULT_NIC_CONFIG') has invalid value."
log_error "Valid values are: \`'" dhcp {dhcp+,}{dhcpv6,slaac,slaac_dhcp}
exit 1
fi
SCRIPT_NAME=$(basename $0)
......
......@@ -185,6 +185,7 @@ snf_export_HOSTNAME="$instance"
snf_export_DHCP_TAGS="$DHCP_TAGS"
snf_export_STATEFUL_DHCPV6_TAGS="$STATEFUL_DHCPV6_TAGS"
snf_export_STATELESS_DHCPV6_TAGS="$STATELESS_DHCPV6_TAGS"
snf_export_DEFAULT_NIC_CONFIG="$DEFAULT_NIC_CONFIG"
if [ -n "${IMG_PASSWD+dummy}" ]; then
snf_export_PASSWD="$IMG_PASSWD"
......
......@@ -114,6 +114,20 @@
# card's NETWORK_TAGS variable.
# STATELESS_DHCPV6_TAGS="nfdhcpd stateless_dhcpv6"
# DEFAULT_NIC_CONFIG: This option defines the network configuration to be
# performed if there is a default NIC attached to the instance with no further
# information associated with it. This will happen if the user creates an
# instance and does not define any of the --net and --no-nics input arguments.
# In this case Ganeti will create a NIC with a random MAC and set up according
# to the cluster level NIC parameters. The user may want to leave this NIC
# unconfigured (by leaving this option empty), perform "dhcp" or use one of the
# various IPv6 auto configuration methods. The supported IPv6 methods are:
# "dhcpv6" (Stateful DHCPv6), "slaac_dhcp" (Stateless DHCPv6) and "slaac"
# (Stateless Autoconfiguration). IPv4 and IPv6 configuration methods can be
# defined in conjunction using the plus (`+') sign. IPv4 must precede (e.g.:
# "dhcp+slaac_dhcp").
# DEFAULT_NIC_CONFIG="dhcp"
# UNATTEND: This variable overwrites the unattend.xml file used when deploying
# a Windows image. snf-image-helper will use its own unattend.xml file if this
# variable is empty.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment