diff options
| author | eb3095 <45504889+eb3095@users.noreply.github.com> | 2022-01-19 18:51:42 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-19 16:51:42 -0700 | 
| commit | 69f9a7888ea770f4dc0454be91dea225bdd5957c (patch) | |
| tree | 082f6c9f717158257aa1e92c5daf00358c019fd8 /cloudinit/sources/helpers | |
| parent | 4c7d159c3efe39860d3c01bf680ba686b87adb77 (diff) | |
| download | vyos-cloud-init-69f9a7888ea770f4dc0454be91dea225bdd5957c.tar.gz vyos-cloud-init-69f9a7888ea770f4dc0454be91dea225bdd5957c.zip | |
Seek interfaces, skip dummy interface, fix region codes (#1192)
We were seeing issues where if anything showed up before the
expected first adapter, booting could fail. This switches to seeking
for a working interface to handle edge cases.
Also fixes region code handling.
Diffstat (limited to 'cloudinit/sources/helpers')
| -rw-r--r-- | cloudinit/sources/helpers/vultr.py | 40 | 
1 files changed, 25 insertions, 15 deletions
| diff --git a/cloudinit/sources/helpers/vultr.py b/cloudinit/sources/helpers/vultr.py index eb504eba..9848f8fd 100644 --- a/cloudinit/sources/helpers/vultr.py +++ b/cloudinit/sources/helpers/vultr.py @@ -16,23 +16,33 @@ LOG = log.getLogger(__name__)  @lru_cache()  def get_metadata(url, timeout, retries, sec_between, agent): -    # Bring up interface -    try: -        with EphemeralDHCPv4(connectivity_url_data={"url": url}): -            # Set metadata route -            set_route() - -            # Fetch the metadata -            v1 = read_metadata(url, timeout, retries, sec_between, agent) -    except (NoDHCPLeaseError) as exc: -        LOG.error("Bailing, DHCP Exception: %s", exc) -        raise - -    return json.loads(v1) +    # Bring up interface (and try untill one works) +    exception = RuntimeError("Failed to DHCP") + +    # Seek iface with DHCP +    for iface in net.get_interfaces(): +        # Skip dummy interfaces +        if "dummy" in iface[0]: +            continue +        try: +            with EphemeralDHCPv4( +                iface=iface[0], connectivity_url_data={"url": url} +            ): +                # Set metadata route +                set_route(iface[0]) + +                # Fetch the metadata +                v1 = read_metadata(url, timeout, retries, sec_between, agent) +        except (NoDHCPLeaseError) as exc: +            LOG.error("DHCP Exception: %s", exc) +            exception = exc + +        return json.loads(v1) +    raise exception  # Set route for metadata -def set_route(): +def set_route(iface):      # Get routes, confirm entry does not exist      routes = netinfo.route_info() @@ -67,7 +77,7 @@ def set_route():                  "add",                  "169.254.169.254/32",                  "dev", -                net.find_fallback_nic(), +                iface,              ]          )      elif subp.which("route"): | 
