diff options
author | Ben Howard <bh@digitalocean.com> | 2017-04-11 12:38:11 -0600 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-04-12 12:44:55 -0400 |
commit | dad97585be0f30202a5a351800f20d4432b94694 (patch) | |
tree | ff71b63c8d16ccd1c4fd807068a9403f56e778d6 /cloudinit/sources | |
parent | ff44056771416cb811879b13b97f88d8f2057071 (diff) | |
download | vyos-cloud-init-dad97585be0f30202a5a351800f20d4432b94694.tar.gz vyos-cloud-init-dad97585be0f30202a5a351800f20d4432b94694.zip |
DigitalOcean: assign IPv4ll address to lowest indexed interface.
Previously the IPv4LL address for metadata discovery was assigned to the
first interfaces from an alphabetic sort. On DigitalOcean, the metadata
is only accessible from the first interface. This fixes a problem where the
IPv4LL address is bound to the wrong interface with snapshots.
This is part of general improvements to the DigitalOcean Datasource in
bug 1676908.
Diffstat (limited to 'cloudinit/sources')
-rw-r--r-- | cloudinit/sources/helpers/digitalocean.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/cloudinit/sources/helpers/digitalocean.py b/cloudinit/sources/helpers/digitalocean.py index 8a19c3bd..257989e8 100644 --- a/cloudinit/sources/helpers/digitalocean.py +++ b/cloudinit/sources/helpers/digitalocean.py @@ -23,11 +23,8 @@ 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() + LOG.debug("selected interface '%s' for reading metadata", nic) if not nic: raise RuntimeError("unable to find interfaces to access the" @@ -57,6 +54,13 @@ 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: + 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. |