diff --git a/cloudinit/sources/helpers/digitalocean.py b/cloudinit/sources/helpers/digitalocean.py
index 72f7bde4..ca3d1a46 100644
--- a/cloudinit/sources/helpers/digitalocean.py
+++ b/cloudinit/sources/helpers/digitalocean.py
@@ -23,11 +23,7 @@ def assign_ipv4_link_local(nic=None):
"""
if not nic:
- for cdev in sorted(cloudnet.get_devicelist()):
- if cloudnet.is_physical(cdev):
- nic = cdev
- LOG.debug("assigned nic '%s' for link-local discovery", nic)
- break
+ nic = get_link_local_nic()
if not nic:
raise RuntimeError("unable to find interfaces to access the"
@@ -57,6 +53,14 @@ def assign_ipv4_link_local(nic=None):
return nic
+def get_link_local_nic():
+ nics = [f for f in cloudnet.get_devicelist() if cloudnet.is_physical(f)]
+ if not nics:
+ LOG.warn("No nics found in get_link_local_nic()")
+ return None
+ return min(nics, key=lambda d: cloudnet.read_sys_net_int(d, 'ifindex'))
+
+
def del_ipv4_link_local(nic=None):
"""Remove the ip4LL address. While this is not necessary, the ip4LL
address is extraneous and confusing to users.