~smoser/cloud-init/trunk.fix-networking

« back to all changes in this revision

Viewing changes to cloudinit/net/__init__.py

  • Committer: Scott Moser
  • Date: 2016-06-03 03:03:38 UTC
  • Revision ID: smoser@ubuntu.com-20160603030338-cvi1ixvh3gq2bbq6
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
970
970
    return read_sys_net(ifname, "address", enoent=False)
971
971
 
972
972
 
973
 
def get_ifname_mac_pairs():
974
 
    """Build a list of tuples (ifname, mac)"""
975
 
    return [(ifname, get_interface_mac(ifname)) for ifname in get_devicelist()]
976
 
 
 
973
def get_interfaces_by_mac(devs=None):
 
974
    """Build a dictionary of tuples {mac: name}"""
 
975
    if devs is None:
 
976
        devs = get_devicelist()
 
977
    ret = {}
 
978
    for name in devs:
 
979
        mac = get_interface_mac(name)
 
980
        # some devices may not have a mac (tun0)
 
981
        if mac:
 
982
            ret[mac] = name
 
983
    return ret
977
984
 
978
985
# vi: ts=4 expandtab syntax=python