From a9c2d6d3acc386fa10493469bb84267ff139b851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ospal=C3=BD?= Date: Tue, 31 Mar 2020 21:51:06 +0200 Subject: [PATCH 1/2] F OpenNebula/one#4439 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr OspalĂ˝ --- src/etc/one-context.d/loc-10-network##apk.one | 73 +++++++++++++------ 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/src/etc/one-context.d/loc-10-network##apk.one b/src/etc/one-context.d/loc-10-network##apk.one index e7b3b64..a8fac14 100755 --- a/src/etc/one-context.d/loc-10-network##apk.one +++ b/src/etc/one-context.d/loc-10-network##apk.one @@ -294,34 +294,65 @@ configure_network() deactivate_network() { . /etc/os-release - if [ $ID = "ubuntu" ]; then - IFACES=`/sbin/ifquery --list -a` - for i in $IFACES; do - if [ $i != 'lo' ]; then - /sbin/ifdown $i - /sbin/ip addr flush dev $i - fi - done - else - service networking stop - fi + case "$ID" in + 'ubuntu') + IFACES=$(/sbin/ifquery --list -a) + + for i in $IFACES; do + if [ $i != 'lo' ]; then + /sbin/ifdown $i + /sbin/ip addr flush dev $i + fi + done + ;; + 'alpine') + service networking stop || true + + #IFACES=$(ip a | \ + # sed -n 's#^[0-9]\+:[[:space:]]\+\([^:]\+\):[[:space:]].*#\1#p') + + # took from find_ifaces in the networking service + IFACES=$(\ + awk '$1 == "auto" { + for (i = 2; i <= NF; i = i + 1) printf("%s ", $i) + }' /etc/network/interfaces) + + for i in $IFACES; do + if [ $i != 'lo' ]; then + /sbin/ip link set dev $i down || true + /sbin/ip addr flush dev $i || true + fi + done + ;; + *) + service networking stop + ;; + esac } activate_network() { . /etc/os-release - if [ $ID = "ubuntu" ]; then - IFACES=`/sbin/ifquery --list -a` - for i in $IFACES; do - /sbin/ifup $i - done - else - service networking stop - sleep 1 - service networking start - fi + case "$ID" in + 'ubuntu') + IFACES=$(/sbin/ifquery --list -a) + + for i in $IFACES; do + /sbin/ifup $i + done + ;; + 'alpine') + deactivate_network + service networking start + ;; + *) + service networking stop + sleep 1 + service networking start + ;; + esac } [ $ACTION == "reconfigure" ] && deactivate_network From e455eae6cca863ad54d91c5974fa3fd1a597827e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ospal=C3=BD?= Date: Tue, 31 Mar 2020 21:51:45 +0200 Subject: [PATCH 2/2] F #196: add NIC recontextualization support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr OspalĂ˝ --- src/lib/udev/rules.d/65-context.rules##apk.one | 10 +++++++++- src/lib/udev/rules.d/65-context.rules##deb.one | 11 ++++++++++- .../udev/rules.d/65-context.rules##rpm.systemd.one | 10 +++++++++- src/lib/udev/rules.d/65-context.rules##rpm.sysv.one | 10 +++++++++- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/lib/udev/rules.d/65-context.rules##apk.one b/src/lib/udev/rules.d/65-context.rules##apk.one index 6da454a..7a3ae60 100644 --- a/src/lib/udev/rules.d/65-context.rules##apk.one +++ b/src/lib/udev/rules.d/65-context.rules##apk.one @@ -1,5 +1,13 @@ -# On NIC hogplug the delayed reconfiguration is triggered. +# On NIC hotplug the delayed reconfiguration is triggered. SUBSYSTEM=="net", ACTION=="add", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" +SUBSYSTEM=="net", ACTION=="add", \ + RUN+="/sbin/service one-context-reconfigure-delayed restart" + +# On NIC detach - workaround for the older OpenNebula versions <5.10.2 +SUBSYSTEM=="net", ACTION=="remove", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" +SUBSYSTEM=="net", ACTION=="remove", \ RUN+="/sbin/service one-context-reconfigure-delayed restart" # On CONTEXT CD-ROM change the immediate reconfiguration is triggered. diff --git a/src/lib/udev/rules.d/65-context.rules##deb.one b/src/lib/udev/rules.d/65-context.rules##deb.one index 52c6f8e..c310163 100644 --- a/src/lib/udev/rules.d/65-context.rules##deb.one +++ b/src/lib/udev/rules.d/65-context.rules##deb.one @@ -1,5 +1,14 @@ -# On NIC hogplug the delayed reconfiguration is triggered. +# On NIC hotplug the delayed reconfiguration is triggered. SUBSYSTEM=="net", ACTION=="add", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" +SUBSYSTEM=="net", ACTION=="add", \ + TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service", \ + RUN+="/usr/bin/timeout 5 /usr/sbin/service one-context-reconfigure-delayed start" + +# On NIC detach - workaround for the older OpenNebula versions <5.10.2 +SUBSYSTEM=="net", ACTION=="remove", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" +SUBSYSTEM=="net", ACTION=="remove", \ TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service", \ RUN+="/usr/bin/timeout 5 /usr/sbin/service one-context-reconfigure-delayed start" diff --git a/src/lib/udev/rules.d/65-context.rules##rpm.systemd.one b/src/lib/udev/rules.d/65-context.rules##rpm.systemd.one index 76f3aea..3c276ac 100644 --- a/src/lib/udev/rules.d/65-context.rules##rpm.systemd.one +++ b/src/lib/udev/rules.d/65-context.rules##rpm.systemd.one @@ -1,7 +1,15 @@ -# On NIC hogplug the delayed reconfiguration is triggered. +# On NIC hotplug the delayed reconfiguration is triggered. +SUBSYSTEM=="net", ACTION=="add", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" SUBSYSTEM=="net", ACTION=="add", \ TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service" +# On NIC detach - workaround for the older OpenNebula versions <5.10.2 +SUBSYSTEM=="net", ACTION=="remove", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" +SUBSYSTEM=="net", ACTION=="remove", \ + RUN+="/bin/systemctl --no-block start one-context-reconfigure-delayed.service" + # When CONTEXT CD-ROM is changed, it generates 2 events. This rule takes # every second event and triggers systemd service one-context-reconfigure. # This service also stops any existing delayed reconfiguration. diff --git a/src/lib/udev/rules.d/65-context.rules##rpm.sysv.one b/src/lib/udev/rules.d/65-context.rules##rpm.sysv.one index fae9e08..f9fb7cd 100644 --- a/src/lib/udev/rules.d/65-context.rules##rpm.sysv.one +++ b/src/lib/udev/rules.d/65-context.rules##rpm.sysv.one @@ -1,5 +1,13 @@ -# On NIC hogplug the delayed reconfiguration is triggered. +# On NIC hotplug the delayed reconfiguration is triggered. SUBSYSTEM=="net", ACTION=="add", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" +SUBSYSTEM=="net", ACTION=="add", \ + RUN+="/sbin/service one-context-reconfigure-delayed start" + +# On NIC detach - workaround for the older OpenNebula versions <5.10.2 +SUBSYSTEM=="net", ACTION=="remove", \ + RUN+="/bin/sh -c 'echo >> /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.network'" +SUBSYSTEM=="net", ACTION=="remove", \ RUN+="/sbin/service one-context-reconfigure-delayed start" # Handle disk resize