diff options
author | Ben Howard <bh@digitalocean.com> | 2017-04-11 16:01:03 -0600 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-04-12 12:38:59 -0400 |
commit | ff44056771416cb811879b13b97f88d8f2057071 (patch) | |
tree | 16288b5e1ba6399c690e81e7e1c4a3d945aa9290 /cloudinit/sources/helpers | |
parent | aab609104988b9d14572eb8fa1dd28a8156c0aea (diff) | |
download | vyos-cloud-init-ff44056771416cb811879b13b97f88d8f2057071.tar.gz vyos-cloud-init-ff44056771416cb811879b13b97f88d8f2057071.zip |
DigitalOcean: configure all NICs presented in meta-data.
Instead of only configuring 'public' and 'private' interfaces, we want
to configure any that has been defined in the meta-data. For legacy reasons,
the 'public' and 'private' interfaces are maintained as 'eth0' and 'eth1'
respectively.
This is part of bug 1676908 for general DigitalOcean datasource fixups.
Diffstat (limited to 'cloudinit/sources/helpers')
-rw-r--r-- | cloudinit/sources/helpers/digitalocean.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/cloudinit/sources/helpers/digitalocean.py b/cloudinit/sources/helpers/digitalocean.py index 6423c8ef..8a19c3bd 100644 --- a/cloudinit/sources/helpers/digitalocean.py +++ b/cloudinit/sources/helpers/digitalocean.py @@ -121,27 +121,31 @@ def convert_network_configuration(config, dns_servers): return subpart - all_nics = [] - for k in ('public', 'private'): - if k in config: - all_nics.extend(config[k]) - - macs_to_nics = cloudnet.get_interfaces_by_mac() nic_configs = [] + macs_to_nics = cloudnet.get_interfaces_by_mac() + LOG.debug("nic mapping: %s", macs_to_nics) - for nic in all_nics: + for n in config: + nic = config[n][0] + LOG.debug("considering %s", nic) mac_address = nic.get('mac') + if mac_address not in macs_to_nics: + raise RuntimeError("Did not find network interface on system " + "with mac '%s'. Cannot apply configuration: %s" + % (mac_address, nic)) + sysfs_name = macs_to_nics.get(mac_address) nic_type = nic.get('type', 'unknown') - # Note: the entry 'public' above contains a list, but - # the list will only ever have one nic inside it per digital ocean. - # If it ever had more than one nic, then this code would - # assign all 'public' the same name. - if_name = NIC_MAP.get(nic_type, sysfs_name) - LOG.debug("mapped %s interface to %s, assigning name of %s", - mac_address, sysfs_name, if_name) + if_name = NIC_MAP.get(nic_type, sysfs_name) + if if_name != sysfs_name: + LOG.debug("Found %s interface '%s' on '%s', assigned name of '%s'", + nic_type, mac_address, sysfs_name, if_name) + else: + msg = ("Found interface '%s' on '%s', which is not a public " + "or private interface. Using default system naming.") + LOG.debug(msg, mac_address, sysfs_name) ncfg = {'type': 'physical', 'mac_address': mac_address, |