summaryrefslogtreecommitdiff
path: root/cloudinit/sources
diff options
context:
space:
mode:
authoreb3095 <45504889+eb3095@users.noreply.github.com>2022-01-19 18:51:42 -0500
committerGitHub <noreply@github.com>2022-01-19 16:51:42 -0700
commit69f9a7888ea770f4dc0454be91dea225bdd5957c (patch)
tree082f6c9f717158257aa1e92c5daf00358c019fd8 /cloudinit/sources
parent4c7d159c3efe39860d3c01bf680ba686b87adb77 (diff)
downloadvyos-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')
-rw-r--r--cloudinit/sources/DataSourceVultr.py6
-rw-r--r--cloudinit/sources/helpers/vultr.py40
2 files changed, 30 insertions, 16 deletions
diff --git a/cloudinit/sources/DataSourceVultr.py b/cloudinit/sources/DataSourceVultr.py
index 13f7c24d..8c2e82c2 100644
--- a/cloudinit/sources/DataSourceVultr.py
+++ b/cloudinit/sources/DataSourceVultr.py
@@ -48,8 +48,12 @@ class DataSourceVultr(sources.DataSource):
# Fetch metadata
self.metadata = self.get_metadata()
- self.metadata["instance-id"] = self.metadata["instanceid"]
+ self.metadata["instance-id"] = self.metadata["instance-v2-id"]
self.metadata["local-hostname"] = self.metadata["hostname"]
+ region = self.metadata["region"]["regioncode"]
+ if "countrycode" in self.metadata["region"]:
+ region = self.metadata["region"]["countrycode"]
+ self.metadata["region"] = region.lower()
self.userdata_raw = self.metadata["user-data"]
# Generate config and process data
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"):