summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"):