← Back to team overview

vmbuilder team mailing list archive

[Merge] lp:~chad.smith/vmbuilder/jenkins_kvm_azure_netplan_hotplug into lp:~ubuntu-on-ec2/vmbuilder/jenkins_kvm

 

Chad Smith has proposed merging lp:~chad.smith/vmbuilder/jenkins_kvm_azure_netplan_hotplug into lp:~ubuntu-on-ec2/vmbuilder/jenkins_kvm.

Commit message:
Update Azure's nic hotplug script to use netplan if available instead of ENI
  
Also avoid appending unnecessary include directives in
/etc/network/interfaces on netplan-enabled systems.


Requested reviews:
  VMBuilder (vmbuilder)

For more details, see:
https://code.launchpad.net/~chad.smith/vmbuilder/jenkins_kvm_azure_netplan_hotplug/+merge/347212

WIP: I think I targeted the wrong branch, will resubmit tomorrow
diff should be http://paste.ubuntu.com/p/Kx8YrXv7cp/


Azure images deliver a script /usr/local/sbin/ephemeral_eth.sh which is called from udev add rules on nic hotplug events for nics named eth[1-9]*. This script was created when netplan wasn't a 'thing' and, as such, only cared about /etc/network/interfaces.

In Bionic and later, cloud-init writes a fallback interface config in /etc/netplan/50-cloud-init.yaml configuration dhcp on eth0 as a primary/mandatory NIC (optional: false). So boot will wait on that device to come up.

This changeset adds a test whether netplan command exists in ephemeral_eth.sh:
  - If netplan is present, a separate /etc/netplan/90-hotplug-<nicname>.yaml will be generated for each network device eth[1-9]n* that is attached after cloud-init's initial network configuration.
  - After the netplan yaml is created, call 'netplan apply' to bring up that device with dchp. The netplan config will specify that these nics are "optional: true" so that subsequent boots will not wait on them to come up in case they are subsequently detached.

Attaching nics in Azure is done through their UI or API. The attaching/detaching operation in Azure requires an instance to be stopped before attach/detach and started after the operation.

  Potental gap:
     There is no attempt to clean up old netplan yaml files, or to designate a new primary/mandatory nic because this original hotplug script didn't deal with udev rules for hotplug removal of nics (via Azure network interface detachment).
     This could present a minor issue if eth1 is attached (and optional by design) and eth0 gets detached. In that case, systemd may still wait for eth0 to come up because of the mandatory eth0 definition in /etc/netplan/50-cloud-init.yaml.
-- 
Your team VMBuilder is requested to review the proposed merge of lp:~chad.smith/vmbuilder/jenkins_kvm_azure_netplan_hotplug into lp:~ubuntu-on-ec2/vmbuilder/jenkins_kvm.
=== modified file 'templates/img-extra-nets.tmpl'
--- templates/img-extra-nets.tmpl	2017-08-22 19:29:36 +0000
+++ templates/img-extra-nets.tmpl	2018-05-31 14:58:36 +0000
@@ -5,6 +5,7 @@
 # vi: ts=4 noexpandtab syntax=sh
 
 int_d="/run/network/interfaces.ephemeral.d"
+netp_d="/etc/netplan"
 
 function config_upstart {
     # Give an upstart job for defining a secondary interface
@@ -52,6 +53,29 @@
 
 INTERFACE=\$1
 net_int_d="${int_d}"
+netplan_d="${netp_d}"
+
+
+function configure_nic_netplan {
+    # Write separate netplan yaml for each hot-plugged interface
+    if [ -e \${netplan_d}/90-hotplug-\${INTERFACE}.yaml ]; then
+        return
+    fi
+    cat << EOM > \${netplan_d}/90-hotplug-\${INTERFACE}.yaml
+# Added by \$0 due to udev nic hotplug event
+network:
+    version: 2
+    ethernets:
+        \${INTERFACE}:
+            dhcp4: true
+            match:
+              driver: hv_netvsc
+              name: \${INTERFACE}
+            optional: true
+EOM
+    netplan apply
+}
+
 
 function configure_nic {
     # Ensure \${net_int_d} exists on the ephemeral mount
@@ -69,8 +93,11 @@
     eth0) #skip, this is static
         ;;
     eth*)
-        if [ ! -e \${net_int_d}/\${INTERFACE}.cfg ]
-        then
+        command -v netplan > /dev/null
+        if [ \$? -eq 0 ]; then
+            # netplan is present
+            configure_nic_netplan
+        elif [ ! -e \${net_int_d}/\${INTERFACE}.cfg ]; then
             configure_nic
         fi
         ;;
@@ -97,8 +124,9 @@
         ;;
 esac
 
-# Add the network ephemeral mount...
-cat << EOF >> ${mp}/etc/network/interfaces
+# Add the network ephemeral mount... only on non-netplan images
+if [ -e ${mp}/usr/sbin/netplan ]; then
+    cat << EOF >> ${mp}/etc/network/interfaces
 
 # Read the dynamically created configurations from tmpfs mount. If you want a static
 # configuration, disable the line below. However, you will have to manually configure
@@ -107,6 +135,7 @@
 source ${int_d}/*.cfg
 
 EOF
+fi
 
 # END NICS
 ##################


Follow ups