diff options
Diffstat (limited to 'cloudinit/sources/helpers/vultr.py')
-rw-r--r-- | cloudinit/sources/helpers/vultr.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/cloudinit/sources/helpers/vultr.py b/cloudinit/sources/helpers/vultr.py index de2d0eb0..836108d4 100644 --- a/cloudinit/sources/helpers/vultr.py +++ b/cloudinit/sources/helpers/vultr.py @@ -37,7 +37,9 @@ def get_metadata(url, timeout, retries, sec_between, agent, tmp_dir=None): # Fetch the metadata v1 = read_metadata(url, timeout, retries, sec_between, agent) - return json.loads(v1) + metadata = json.loads(v1) + refactor_metadata(metadata) + return metadata except ( NoDHCPLeaseError, subp.ProcessExecutionError, @@ -49,6 +51,16 @@ def get_metadata(url, timeout, retries, sec_between, agent, tmp_dir=None): raise exception +# Refactor metadata into acceptable format +def refactor_metadata(metadata): + metadata["instance-id"] = metadata["instance-v2-id"] + metadata["local-hostname"] = metadata["hostname"] + region = metadata["region"]["regioncode"] + if "countrycode" in metadata["region"]: + region = metadata["region"]["countrycode"] + metadata["region"] = region.lower() + + # Get interface list, sort, and clean def get_interface_list(): ifaces = [] @@ -264,17 +276,17 @@ def generate_interface_additional_addresses(interface, netcfg): # Make required adjustments to the network configs provided -def add_interface_names(interfaces): - for interface in interfaces: - interface_name = get_interface_name(interface["mac"]) +def add_interface_names(netcfg): + for interface in netcfg["config"]: + if interface["type"] != "physical": + continue + interface_name = get_interface_name(interface["mac_address"]) if not interface_name: raise RuntimeError( "Interface: %s could not be found on the system" - % interface["mac"] + % interface["mac_address"] ) interface["name"] = interface_name - return interfaces - # vi: ts=4 expandtab |