summaryrefslogtreecommitdiffstats
path: root/libexec/container
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2022-05-05 16:16:39 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2022-05-05 16:27:36 +0000
commitf8af295ca5fc25883f34a1bfed0c5f3d025560a0 (patch)
treea7d9a4183f877e1ad017cc4dca5b4f6f70b2874f /libexec/container
parentShowing all IP address for stopped containers in container list command. (diff)
downloadcompute-tools-f8af295ca5fc25883f34a1bfed0c5f3d025560a0.tar.xz
compute-tools-f8af295ca5fc25883f34a1bfed0c5f3d025560a0.zip
Supporting both ifupdown and systemd-networkd for the time being, depending on the existence of /etc/network/interfaces.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
Diffstat (limited to '')
-rwxr-xr-xlibexec/container/start36
-rwxr-xr-xlibexec/container/stop18
2 files changed, 50 insertions, 4 deletions
diff --git a/libexec/container/start b/libexec/container/start
index f67eb86..1b53628 100755
--- a/libexec/container/start
+++ b/libexec/container/start
@@ -191,6 +191,13 @@ case "${HOST_ARCHITECTURE}" in
;;
esac
+if systemctl status systemd-networkd > /dev/null 2>&1
+then
+ NETWORK_SUBSYSTEM="systemd-networkd"
+else
+ NETWORK_SUBSYSTEM="ifupdown"
+fi
+
case "${START}" in
start)
;;
@@ -390,7 +397,22 @@ then
if [ -n "${BRIDGE}" ] && [ -n "${INTERFACE}" ]
then
- mkdir -p /run/systemd/network
+ case "${NETWORK_SUBSYSTEM}" in
+ ifupdown)
+
+cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF
+allow-hotplug ${INTERFACE}
+iface ${INTERFACE} inet manual
+ pre-up ip link set ${INTERFACE} up
+ post-up ip link set ${INTERFACE} master ${BRIDGE}
+ pre-down ip link set ${INTERFACE} nomaster
+ post-down ip link set ${INTERFACE} down
+EOF
+
+ ;;
+
+ systemd-networkd)
+ mkdir -p /run/systemd/network
cat > "/run/systemd/network/${INTERFACE}.network" << EOF
[Match]
@@ -398,10 +420,18 @@ Name=${INTERFACE}
[Network]
Bridge=${BRIDGE}
+cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF
+allow-hotplug ${INTERFACE}
+iface ${INTERFACE} inet manual
+ pre-up ip link set ${INTERFACE} up
+ post-up ip link set ${INTERFACE} master ${BRIDGE}
+ pre-down ip link set ${INTERFACE} nomaster
+ post-down ip link set ${INTERFACE} down
EOF
- networkctl reload
-
+ networkctl reload
+ ;;
+ esac
else
echo "Warning bridge definition '${BRIDGE_DEFINITION}' not recognized (expected <bridge>:<interface>): Ignoring"
fi
diff --git a/libexec/container/stop b/libexec/container/stop
index 455f08c..cb85c8d 100755
--- a/libexec/container/stop
+++ b/libexec/container/stop
@@ -146,6 +146,13 @@ then
exit 1
fi
+if systemctl status systemd-networkd > /dev/null 2>&1
+then
+ NETWORK_SUBSYSTEM="systemd-networkd"
+else
+ NETWORK_SUBSYSTEM="ifupdown"
+fi
+
# Pre hooks
for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
do
@@ -220,7 +227,16 @@ case "${CLEAN}" in
for VETH in ${VETHS}
do
INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')"
- FILE="/run/systemd/network/${INTERFACE}.network"
+
+ case "${NETWORK_SUBSYSTEM}" in
+ ifupdown)
+ FILE="/etc/network/interfaces.d/${INTERFACE}"
+ ;;
+
+ systemd-networkd)
+ FILE="/run/systemd/network/${INTERFACE}.network"
+ ;;
+ esac
if [ -f "${FILE}" ]
then