summaryrefslogtreecommitdiff
path: root/cloudinit/net/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/net/__init__.py')
-rw-r--r--cloudinit/net/__init__.py50
1 files changed, 36 insertions, 14 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index e233149a..de65e7af 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -124,6 +124,15 @@ def master_is_bridge_or_bond(devname):
return (os.path.exists(bonding_path) or os.path.exists(bridge_path))
+def master_is_openvswitch(devname):
+ """Return a bool indicating if devname's master is openvswitch"""
+ master_path = get_master(devname)
+ if master_path is None:
+ return False
+ ovs_path = sys_dev_path(devname, path="upper_ovs-system")
+ return os.path.exists(ovs_path)
+
+
def is_netfailover(devname, driver=None):
""" netfailover driver uses 3 nics, master, primary and standby.
this returns True if the device is either the primary or standby
@@ -746,18 +755,22 @@ def get_ib_interface_hwaddr(ifname, ethernet_format):
return mac
-def get_interfaces_by_mac():
+def get_interfaces_by_mac(blacklist_drivers=None) -> dict:
if util.is_FreeBSD():
- return get_interfaces_by_mac_on_freebsd()
+ return get_interfaces_by_mac_on_freebsd(
+ blacklist_drivers=blacklist_drivers)
elif util.is_NetBSD():
- return get_interfaces_by_mac_on_netbsd()
+ return get_interfaces_by_mac_on_netbsd(
+ blacklist_drivers=blacklist_drivers)
elif util.is_OpenBSD():
- return get_interfaces_by_mac_on_openbsd()
+ return get_interfaces_by_mac_on_openbsd(
+ blacklist_drivers=blacklist_drivers)
else:
- return get_interfaces_by_mac_on_linux()
+ return get_interfaces_by_mac_on_linux(
+ blacklist_drivers=blacklist_drivers)
-def get_interfaces_by_mac_on_freebsd():
+def get_interfaces_by_mac_on_freebsd(blacklist_drivers=None) -> dict():
(out, _) = subp.subp(['ifconfig', '-a', 'ether'])
# flatten each interface block in a single line
@@ -784,7 +797,7 @@ def get_interfaces_by_mac_on_freebsd():
return results
-def get_interfaces_by_mac_on_netbsd():
+def get_interfaces_by_mac_on_netbsd(blacklist_drivers=None) -> dict():
ret = {}
re_field_match = (
r"(?P<ifname>\w+).*address:\s"
@@ -800,7 +813,7 @@ def get_interfaces_by_mac_on_netbsd():
return ret
-def get_interfaces_by_mac_on_openbsd():
+def get_interfaces_by_mac_on_openbsd(blacklist_drivers=None) -> dict():
ret = {}
re_field_match = (
r"(?P<ifname>\w+).*lladdr\s"
@@ -815,12 +828,13 @@ def get_interfaces_by_mac_on_openbsd():
return ret
-def get_interfaces_by_mac_on_linux():
+def get_interfaces_by_mac_on_linux(blacklist_drivers=None) -> dict:
"""Build a dictionary of tuples {mac: name}.
Bridges and any devices that have a 'stolen' mac are excluded."""
ret = {}
- for name, mac, _driver, _devid in get_interfaces():
+ for name, mac, _driver, _devid in get_interfaces(
+ blacklist_drivers=blacklist_drivers):
if mac in ret:
raise RuntimeError(
"duplicate mac found! both '%s' and '%s' have mac '%s'" %
@@ -838,11 +852,13 @@ def get_interfaces_by_mac_on_linux():
return ret
-def get_interfaces():
+def get_interfaces(blacklist_drivers=None) -> list:
"""Return list of interface tuples (name, mac, driver, device_id)
Bridges and any devices that have a 'stolen' mac are excluded."""
ret = []
+ if blacklist_drivers is None:
+ blacklist_drivers = []
devs = get_devicelist()
# 16 somewhat arbitrarily chosen. Normally a mac is 6 '00:' tokens.
zero_mac = ':'.join(('00',) * 16)
@@ -855,8 +871,10 @@ def get_interfaces():
continue
if is_bond(name):
continue
- if get_master(name) is not None and not master_is_bridge_or_bond(name):
- continue
+ if get_master(name) is not None:
+ if (not master_is_bridge_or_bond(name) and
+ not master_is_openvswitch(name)):
+ continue
if is_netfailover(name):
continue
mac = get_interface_mac(name)
@@ -866,7 +884,11 @@ def get_interfaces():
# skip nics that have no mac (00:00....)
if name != 'lo' and mac == zero_mac[:len(mac)]:
continue
- ret.append((name, mac, device_driver(name), device_devid(name)))
+ # skip nics that have drivers blacklisted
+ driver = device_driver(name)
+ if driver in blacklist_drivers:
+ continue
+ ret.append((name, mac, driver, device_devid(name)))
return ret