Ubuntu Pastebin

Paste from smoser at Tue, 11 Apr 2017 19:40:15 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.
Download as text