summaryrefslogtreecommitdiff
path: root/cloudinit/net/__init__.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-06-02 23:03:38 -0400
committerScott Moser <smoser@ubuntu.com>2016-06-02 23:03:38 -0400
commit6bd7fbc35ac8726a8a0f422cd802d290c236bf3b (patch)
treeaf1a2311315106ab4fa0aeb1a3bfb4e76020808b /cloudinit/net/__init__.py
parent8ddfc28d055b610f592802e4c9fd4c3ede778918 (diff)
downloadvyos-cloud-init-6bd7fbc35ac8726a8a0f422cd802d290c236bf3b.tar.gz
vyos-cloud-init-6bd7fbc35ac8726a8a0f422cd802d290c236bf3b.zip
ConfigDrive: do not use 'id' on a link for the device name
'id' on a link in the openstack spec should be "Generic, generated ID". current implementation was to use the host's name for the host side nic. Which provided names like 'tap-adfasdffd'. We do not want to name devices like that as its quite unexpected and non user friendly. So here we use the system name for any nic that is present, but then require that the nics found also be present at the time of rendering. The end result is that if the system boots with net.ifnames=0 then it will get 'eth0' like names. and if it boots without net.ifnames then it will get enp0s1 like names.
Diffstat (limited to 'cloudinit/net/__init__.py')
-rw-r--r--cloudinit/net/__init__.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index 05152ead..f47053b2 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -970,9 +970,16 @@ def get_interface_mac(ifname):
return read_sys_net(ifname, "address", enoent=False)
-def get_ifname_mac_pairs():
- """Build a list of tuples (ifname, mac)"""
- return [(ifname, get_interface_mac(ifname)) for ifname in get_devicelist()]
-
+def get_interfaces_by_mac(devs=None):
+ """Build a dictionary of tuples {mac: name}"""
+ if devs is None:
+ devs = get_devicelist()
+ ret = {}
+ for name in devs:
+ mac = get_interface_mac(name)
+ # some devices may not have a mac (tun0)
+ if mac:
+ ret[mac] = name
+ return ret
# vi: ts=4 expandtab syntax=python