diff --git a/docs/interface.rst b/docs/interface.rst index e8beabb2a6489037c1c93b3f8b73dd4f7a0f7c61..d99930e5bae113081966fc723141271a85fa5ab9 100644 --- a/docs/interface.rst +++ b/docs/interface.rst @@ -228,6 +228,12 @@ All image formats properties you want to write a custom configuration task check :ref:`Configuration Tasks Environment<configuration-tasks-environment>`. + * **NM_NETWORKING=bool** + If this property is defined with a yes value, the *ConfigureNetwork* task + will try to configure the Ganeti-provided NICs by creating Network Manager + configuration files, instead of using the distro-specific network + configuration mechanism (*ifupdown* for Debian, *ifcfg* for Red Hat, etc.). + * **EXCLUDE_ALL_TASKS=bool** If this property is defined with a yes value, the image will not be configured at all, during the deployment. This is really handy because it diff --git a/snf-image-helper/common.sh.in b/snf-image-helper/common.sh.in index 3918ccaf346f5bb96ce5e1cfca478afb352ae6f8..63ed0b17d49b6fd285eee9d1ca02010f793951ce 100644 --- a/snf-image-helper/common.sh.in +++ b/snf-image-helper/common.sh.in @@ -290,6 +290,26 @@ get_distro() { fi } +get_networking_tool() { + local root_dir distro tool + root_dir=$1 + + if check_yes_no SNF_IMAGE_PROPERTY_NM_NETWORKING; then + tool="nm" + else + distro=$(get_base_distro "$root_dir") + if [ "$distro" = debian ]; then + tool=ifupdown + elif [ "$distro" = redhat ]; then + tool=ifcfg + else + tool=$distro + fi + fi + + echo "@networkingdir@/$tool.sh" +} + get_partition_table() { local dev output dev="$1" diff --git a/snf-image-helper/networking/Makefile.am b/snf-image-helper/networking/Makefile.am index 0eb5973ea05b6be55e0d19657b7dd25198072674..db8b97081738cef6ebd69a02ee5384c2703f200a 100644 --- a/snf-image-helper/networking/Makefile.am +++ b/snf-image-helper/networking/Makefile.am @@ -1,6 +1,6 @@ networkingdir=$(libdir)/$(PACKAGE)/networking -dist_networking_SCRIPTS = debian.sh redhat.sh freebsd.sh openbsd.sh netbsd.sh +dist_networking_SCRIPTS = ifupdown.sh ifcfg.sh freebsd.sh openbsd.sh netbsd.sh nm.sh edit = sed \ -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ diff --git a/snf-image-helper/networking/redhat.sh.in b/snf-image-helper/networking/ifcfg.sh.in similarity index 100% rename from snf-image-helper/networking/redhat.sh.in rename to snf-image-helper/networking/ifcfg.sh.in diff --git a/snf-image-helper/networking/debian.sh.in b/snf-image-helper/networking/ifupdown.sh.in similarity index 100% rename from snf-image-helper/networking/debian.sh.in rename to snf-image-helper/networking/ifupdown.sh.in diff --git a/snf-image-helper/networking/nm.sh.in b/snf-image-helper/networking/nm.sh.in new file mode 100644 index 0000000000000000000000000000000000000000..3120950f0cd5666945e22c4d081ba3d0d5bab57d --- /dev/null +++ b/snf-image-helper/networking/nm.sh.in @@ -0,0 +1,86 @@ +#! /bin/bash + +# Copyright (C) 2016 GRNET S.A. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +# Script for configuring network manager connections + +set -e +. "@commondir@/common.sh" + +networking_opts "$@" + +SYSTEM_CONNECTIONS="$SNF_IMAGE_TARGET/etc/NetworkManager/system-connections/" + +if [ "$initialize" = yes ]; then + exit 0 +fi + +if [ "$finalize" = yes ]; then + exit 0 +fi + +if [ "$ipv4" = "none" ]; then + ipv4_section+="method=disabled" +elif [ "$ipv4" = "dhcp" ]; then + ipv4_section+="method=auto" +else + ipv4_section+="method=manual +address1=$IP/${SUBNET##*/}" + + if [ -n "$GATEWAY" ]; then + ipv4_section+=",$GATEWAY" + fi +fi + +if [ "$ipv6" != 'none' ]; then + ipv6_section="method=auto" +else + ipv6_section="method=disabled" +fi + +connection="$SYSTEM_CONNECTIONS/Wired connection $index" +cat > "$connection" <<EOF +[connection] +id=Wired connection $index +uuid=$(cat /proc/sys/kernel/random/uuid) +type=ethernet +autoconnect=true + +[ethernet] +mac-address=$MAC +mac-address-blacklist= + +[ipv4] +dns-search= +$ipv4_section + +[ipv6] +addr-gen-mode=eui64 +dns-search= +ip6-privacy=0 +$ipv6_section +EOF + +# For security, the 'keyfile' plugin that will read the connection files found +# under /etc/NetworkManager/system-connections will ignore files that are +# readable or writeable by any user or group other than 'root' since private +# keys and passphrases may be stored in plaintext inside the file. +chown 0:0 "$connection" +chmod 600 "$connection" + +# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : diff --git a/snf-image-helper/tasks/50ConfigureNetwork.in b/snf-image-helper/tasks/50ConfigureNetwork.in index 8ed86ec96b68e61224f853ebbd7f3ac9a22cb2bd..2f9e14fde56cc4b7aeb88f1ee72c4d555ce86a6c 100644 --- a/snf-image-helper/tasks/50ConfigureNetwork.in +++ b/snf-image-helper/tasks/50ConfigureNetwork.in @@ -42,17 +42,20 @@ fi # Check if the image overwrites the task check_if_overwritten -distro=$(get_base_distro "$SNF_IMAGE_TARGET") +networking_tool=$(get_networking_tool "$SNF_IMAGE_TARGET") -if [ ! -f "@networkingdir@/$distro.sh" ]; then +if [ ! -f "$networking_tool" ]; then warn "Don't know how to configure the network for this OS" exit 0 +else + echo "Using $networking_tool" fi export SNF_IMAGE_TARGET # Initialize the driver -"@networkingdir@/$distro.sh" -i +echo "Running: $networking_tool -i" +"$networking_tool" -i for index in $(seq 0 $((SNF_IMAGE_NIC_COUNT-1))); do dhcp=no @@ -129,12 +132,14 @@ for index in $(seq 0 $((SNF_IMAGE_NIC_COUNT-1))); do fi fi - "@networkingdir@/$distro.sh" $ARGS + echo "Running: $networking_tool $ARGS" + "$networking_tool" $ARGS done # Finalize the driver -"@networkingdir@/$distro.sh" -f +echo "Running: $networking_tool -f" +"$networking_tool" -f # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :