summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNik Lutz <nik@netstyle.ch>2016-05-12 15:40:10 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2016-05-18 18:26:06 +0000
commitbc53e5a0e1a692200313d64ff0a1fd8d8b34ab4f (patch)
tree182218c80b551f28ec8109c8de324acef1dd026d
parentAdding veth name (cnt-debconf/network[0-9]/veth) configuration option to debc... (diff)
downloadcompute-tools-bc53e5a0e1a692200313d64ff0a1fd8d8b34ab4f.tar.xz
compute-tools-bc53e5a0e1a692200313d64ff0a1fd8d8b34ab4f.zip
Using systemd-nspawn '--network-veth-extra=' instead of '--network-veth' (prerequisite for multiple network interface support per container).
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
Diffstat (limited to '')
-rwxr-xr-xlib/container/create2
-rwxr-xr-xlib/container/start25
-rw-r--r--share/config/container.conf.in2
-rwxr-xr-xshare/scripts/debconf25
-rwxr-xr-xshare/scripts/debconf.d/0003-debconf4
5 files changed, 47 insertions, 11 deletions
diff --git a/lib/container/create b/lib/container/create
index fab9f5b..4d1d19b 100755
--- a/lib/container/create
+++ b/lib/container/create
@@ -135,7 +135,7 @@ sed -e "s|@CNT_AUTOSTART@|${CNT_AUTOSTART}|g" \
-e "s|@DIRECTORY@|${MACHINES}/${NAME}|g" \
-e "s|@DROP_CAPABILITY@|${DROP_CAPABILITY}|g" \
-e "s|@MACHINE@|${NAME}|g" \
- -e "s|@NETWORK_VETH@|yes|g" \
+ -e "s|@NETWORK_VETH_EXTRA@|${NETWORK_VETH_EXTRA}|g" \
-e "s|@NETWORK_BRIDGE@|br0|g" \
-e "s|@LINK_JOURNAL@|no|g" \
-e "s|@REGISTER@|yes|g" \
diff --git a/lib/container/start b/lib/container/start
index 8d5429b..fa717dd 100755
--- a/lib/container/start
+++ b/lib/container/start
@@ -197,15 +197,26 @@ then
;;
esac
- NETWORK_VETH="$(awk -F= '/^network-veth=/ { print $2 }' ${CONFIG}/${NAME}.conf || echo yes)"
+ NETWORK_VETH_EXTRA_CONF="$(awk -F= '/^network-veth-extra=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ NETWORK_VETH_EXTRA=""
- case "${NETWORK_VETH}" in
- yes)
- NETWORK_VETH="--network-veth"
+ case "${NETWORK_VETH_EXTRA_CONF}" in
+ "")
;;
*)
- NETWORK_VETH=""
+ for VETH in ${NETWORK_VETH_EXTRA_CONF}
+ do
+ NETWORK_VETH_EXTRA="${NETWORK_VETH_EXTRA} --network-veth-extra=${VETH}"
+ INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')"
+
+cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF
+iface ${INTERFACE} inet manual
+ pre-up ifconfig ${INTERFACE} up
+ post-down ifconfig ${INTERFACE} down
+EOF
+
+ done
;;
esac
@@ -301,11 +312,11 @@ fi
# Run
case "${SET_PROPERTY}" in
true)
- ${SETARCH} systemd-nspawn ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_BRIDGE} ${NETWORK_VETH} ${LINK_JOURNAL} ${REGISTER} & \
+ ${SETARCH} systemd-nspawn ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_BRIDGE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER} & \
systemctl --runtime set-property ${NAME} ${BLOCK_IO_DEVICE_WEIGHT} ${BLOCK_IO_READ_BANDWITH} ${BLOCK_IO_WEIGHT} ${BLOCK_IO_WRITE_BANDWITH} ${CPU_QUOTA} ${CPU_SHARES} ${MEMORY_LIMIT} ${TASKS_MAX}
;;
*)
- ${SETARCH} systemd-nspawn ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_BRIDGE} ${NETWORK_VETH} ${LINK_JOURNAL} ${REGISTER}
+ ${SETARCH} systemd-nspawn ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_BRIDGE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER}
;;
esac
diff --git a/share/config/container.conf.in b/share/config/container.conf.in
index fbf8078..f7d01be 100644
--- a/share/config/container.conf.in
+++ b/share/config/container.conf.in
@@ -8,7 +8,7 @@ capability=@CAPABILITY@
directory=@DIRECTORY@
drop-capability=@DROP_CAPABILITY@
machine=@MACHINE@
-network-veth=@NETWORK_VETH@
+network-veth-extra=@NETWORK_VETH_EXTRA@
network-bridge=@NETWORK_BRIDGE@
link-journal=@LINK_JOURNAL@
register=@REGISTER@
diff --git a/share/scripts/debconf b/share/scripts/debconf
index 28e95fd..24202b0 100755
--- a/share/scripts/debconf
+++ b/share/scripts/debconf
@@ -904,6 +904,29 @@ Commands ()
# config (FIXME)
sed -i -e "s|^network-bridge=.*|network-bridge=${NETWORK0_BRIDGE}|" "${CONFIG}/${NAME}.conf"
+ # maximum of 15 characters, prefix is 'veth-'
+ HOSTNAME_SHORT="$(echo ${NAME} | cut -c-8)"
+ HOST_INTERFACE_NAME="$(echo ${NETWORK0_VETH:-veth-${HOSTNAME_SHORT}-0})"
+
+ sed -i -e "s|^network-veth-extra=.*|network-veth-extra=${HOST_INTERFACE_NAME}:eth0|g" "${CONFIG}/${NAME}.conf"
+
+ for NUMBER in $(seq 1 ${NETWORK_NUMBER})
+ do
+ eval IPV4_METHOD="$`echo NETWORK${NUMBER}_IPV4_METHOD`"
+
+ if [ -z "${IPV4_METHOD}" ]
+ then
+ continue
+ fi
+
+ eval HOST_INTERFACE_NAME="$`echo NETWORK${NUMBER}_VETH`"
+
+ HOST_INTERFACE_NAME="$(echo ${HOST_INTERFACE_NAME:-veth-${HOSTNAME_SHORT}-${NUMBER}})"
+ CONTAINER_INTERFACE_NAME="eth${NUMBER}"
+
+ sed -i -e "/^register=.*/ a network-veth-extra=${HOST_INTERFACE_NAME}:${CONTAINER_INTERFACE_NAME}" "${CONFIG}/${NAME}.conf"
+ done
+
# Setting root password
echo root:${ROOT_PASSWORD} | chroot "${DIRECTORY}" chpasswd
@@ -932,6 +955,8 @@ SYSTEM="${MACHINES}/${NAME}"
Debconf
+export NAME
+
# Run debconf parts
for SCRIPT in /usr/share/container-tools/scripts/debconf.d/*
do
diff --git a/share/scripts/debconf.d/0003-debconf b/share/scripts/debconf.d/0003-debconf
index d1fd7e1..df14ef0 100755
--- a/share/scripts/debconf.d/0003-debconf
+++ b/share/scripts/debconf.d/0003-debconf
@@ -673,10 +673,10 @@ Network_defaults ()
# * respect pre-existing interfaces (or interfaces.d)
# * add support for bridges (make interface configuration more generic?)
- HOSTNAME_SHORT="$(echo ${NAME} | cut -c-9)"
+ HOSTNAME_SHORT="$(echo veth-$(echo ${NAME} | cut -c-8)-0)"
VETH_NAME="$(echo ${HOSTNAME_SHORT:-veth0})"
- NETWORK0_VETH="${NETWORK0_VETH:-VETH_NAME}"
+ NETWORK0_VETH="${NETWORK0_VETH:-$VETH_NAME}"
NETWORK0_BRIDGE="${NETWORK0_BRIDGE:-br0}"
NETWORK0_IPV4_METHOD="${NETWORK0_IPV4_METHOD:-dhcp}"
NETWORK0_IPV4_ADDRESS="${NETWORK0_IPV4_ADDRESS:-192.168.1.2}"