← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~utlemming/cloud-init:lp-1676908-nic_selection_for_meta_data into cloud-init:master

 

Ben Howard has proposed merging ~utlemming/cloud-init:lp-1676908-nic_selection_for_meta_data into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1676908 in cloud-init: "DigitalOcean network improvements"
  https://bugs.launchpad.net/cloud-init/+bug/1676908

For more details, see:
https://code.launchpad.net/~utlemming/cloud-init/+git/cloud-init-1/+merge/322385
-- 
Your team cloud init development team is requested to review the proposed merge of ~utlemming/cloud-init:lp-1676908-nic_selection_for_meta_data into cloud-init:master.
diff --git a/cloudinit/sources/helpers/digitalocean.py b/cloudinit/sources/helpers/digitalocean.py
index 72f7bde..3fbe83c 100644
--- a/cloudinit/sources/helpers/digitalocean.py
+++ b/cloudinit/sources/helpers/digitalocean.py
@@ -23,11 +23,17 @@ def assign_ipv4_link_local(nic=None):
     """
 
     if not nic:
-        for cdev in sorted(cloudnet.get_devicelist()):
+        cindex = -1
+        for cdev in cloudnet.get_devicelist():
             if cloudnet.is_physical(cdev):
-                nic = cdev
-                LOG.debug("assigned nic '%s' for link-local discovery", nic)
-                break
+                ifindex = cloudnet.read_sys_net_int(cdev, 'ifindex')
+                if (cindex == -1 or (
+                    cindex != -1 and ifindex < cindex)):
+                    msg = ("'%s' is a candidate for metadata discovery with "
+                           "an index of %s.")
+                    LOG.debug(msg % (cdev, ifindex))
+                    nic = cdev
+                    cindex = ifindex
 
     if not nic:
         raise RuntimeError("unable to find interfaces to access the"

References