Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ifupdown2/addons/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def __init__(self, *args, **kargs):
except Exception as e:
self.logger.info("bond: error while loading bonding module: %s" % str(e))

# get_ifindex() always returns the primary ifname, so no need for translating
self._bond_attr_ifquery_check_translate_func[Link.IFLA_BOND_PRIMARY] = self.cache.get_ifindex
self._bond_attr_set_list = self._bond_attr_set_list + (('bond-primary', Link.IFLA_BOND_PRIMARY, self.cache.get_ifindex),)

Expand All @@ -292,7 +293,7 @@ def __init__(self, *args, **kargs):

def get_bond_slaves(self, ifaceobj):
# bond-ports aliases should be translated to bond-slaves
return ifaceobj.get_attr_value_first('bond-slaves')
return self.cache.link_translate_altname(ifaceobj.get_attr_value_first('bond-slaves'))

def _is_bond(self, ifaceobj):
# at first link_kind is not set but once ifupdownmain
Expand Down
14 changes: 0 additions & 14 deletions ifupdown2/addons/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,20 +1133,6 @@ def get_dependent_ifacenames_running(self, ifaceobj):
return None
return self.cache.get_slaves(ifaceobj.name)

def _get_bridge_port_list(self, ifaceobj):

# port list is also available in the previously
# parsed dependent list. Use that if available, instead
# of parsing port expr again
port_list = ifaceobj.lowerifaces
if port_list:
return port_list
ports = self._get_ifaceobj_bridge_ports(ifaceobj)
if ports:
return self.parse_port_list(ifaceobj.name, ports)
else:
return None

def _get_bridge_port_list_user_ordered(self, ifaceobj):
# When enslaving bridge-ports we need to return the exact user
# configured bridge ports list (bridge will inherit the mac of the
Expand Down
1 change: 1 addition & 0 deletions ifupdown2/addons/openvswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def _get_ovs_ports (self, ifaceobj):
ovs_ports.extend(port.split())

if ovs_ports:
ovs_ports = self.cache.link_translate_altnames(ovs_ports)
return self.parse_port_list(ifaceobj.name, ' '.join(ovs_ports))
else:
return None
Expand Down
31 changes: 23 additions & 8 deletions ifupdown2/addons/openvswitch_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,28 @@ def __init__ (self, *args, **kargs):

def _is_ovs_port (self, ifaceobj):
ovstype = ifaceobj.get_attr_value_first ('ovs-type')
ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
ovsbridge = self._get_ovs_bridge(ifaceobj)
if ovstype and ovsbridge:
return True
return False

def _get_ovs_bridge(self, ifaceobj):
"""
Returns the ifname of the `ovs-bridge` property. Translates altnames
to the primary ifname if needed.
:param ifaceobj: interface config object
:return: `ovs-bridge` ifname
"""
ifname = ifaceobj.get_attr_value_first('ovs-bridge')
if ifname:
return self.cache.link_translate_altname(ifname)
return None

def _get_bond_ifaces (self, ifaceobj):
ovs_bonds = ifaceobj.get_attr_value_first ('ovs-bonds')
if ovs_bonds:
return sorted (ovs_bonds.split ())
ovs_bonds = self.cache.link_translate_altnames(ovs_bonds.split())
return sorted(ovs_bonds)
return None

def _ovs_vsctl(self, ifaceobj, cmdlist):
Expand All @@ -129,10 +142,13 @@ def _ovs_vsctl(self, ifaceobj, cmdlist):

def _addport (self, ifaceobj):
iface = ifaceobj.name
ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
ovsbridge = self._get_ovs_bridge(ifaceobj)
ovsoptions = ifaceobj.get_attr_value_first ('ovs-options')
ovstype = ifaceobj.get_attr_value_first ('ovs-type')
ovsbonds = ifaceobj.get_attr_value_first ('ovs-bonds')

ovsbonds_list = self._get_bond_ifaces(ifaceobj)
ovsbonds = ' '.join(ovsbonds_list) if ovsbonds_list else None

ovsextra = ifaceobj.get_attr_value('ovs-extra')

cmd_list = []
Expand Down Expand Up @@ -183,11 +199,10 @@ def _addport (self, ifaceobj):

#mtu
ovsmtu = ifaceobj.get_attr_value_first ('ovs-mtu')
ovsbonds_list = self._get_bond_ifaces(ifaceobj)
if ovsmtu is not None:
#we can't set mtu on bond fake interface, we apply it on slaves interfaces
if ovstype == 'OVSBond' and ovsbonds_list is not None:
for slave in ovsbonds_list:
for slave in ovsbonds_list:
cmd = "set Interface %s mtu_request=%s"%(slave,ovsmtu)
cmd_list.append(cmd)

Expand All @@ -207,7 +222,7 @@ def _addport (self, ifaceobj):

def _delport (self, ifaceobj):
iface = ifaceobj.name
ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
ovsbridge = self._get_ovs_bridge(ifaceobj)
cmd = "--if-exists del-port %s %s"%(ovsbridge, iface)

self._ovs_vsctl(ifaceobj, [cmd])
Expand All @@ -219,7 +234,7 @@ def get_dependent_ifacenames(self, ifaceobj, ifacenames_all=None, old_ifaceobjs=

ifaceobj.link_privflags |= ifaceLinkPrivFlags.OPENVSWITCH

ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
ovsbridge = self._get_ovs_bridge(ifaceobj)
return [ovsbridge]

def _up (self, ifaceobj):
Expand Down
15 changes: 12 additions & 3 deletions ifupdown2/addons/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,17 @@ def __init__(self, *args, **kargs):
Addon.__init__(self)
moduleBase.__init__(self, *args, **kargs)

def _get_vlan_raw_device_first(self, ifaceobj):
"""
Returns the ifname of the `vlan-raw-device` property. Translates
altnames to the primary ifname if needed.
:param ifaceobj: interface config object
:return: `vlan-raw-device` ifname
"""
return self.cache.link_translate_altname(ifaceobj.get_attr_value_first('vlan-raw-device'))

def _is_vlan_device(self, ifaceobj):
vlan_raw_device = ifaceobj.get_attr_value_first('vlan-raw-device')
vlan_raw_device = self._get_vlan_raw_device_first(ifaceobj)
if vlan_raw_device:
return True
elif '.' in ifaceobj.name:
Expand Down Expand Up @@ -176,7 +185,7 @@ def _up(self, ifaceobj):
vlan_exists = self.cache.link_exists(ifaceobj.name)

if vlan_exists:
user_vlan_raw_device = ifaceobj.get_attr_value_first('vlan-raw-device')
user_vlan_raw_device = self._get_vlan_raw_device_first(ifaceobj)
cached_vlan_raw_device = self.cache.get_lower_device_ifname(ifname)

if cached_vlan_raw_device and user_vlan_raw_device and cached_vlan_raw_device != user_vlan_raw_device:
Expand Down Expand Up @@ -239,7 +248,7 @@ def _query_check(self, ifaceobj, ifaceobjcurr):
ifaceobjcurr.update_config_with_status(
'vlan-raw-device',
cached_vlan_raw_device,
cached_vlan_raw_device != ifaceobj.get_attr_value_first('vlan-raw-device')
cached_vlan_raw_device != self._get_vlan_raw_device_first(ifaceobj)
)

#
Expand Down
23 changes: 17 additions & 6 deletions ifupdown2/ifupdown/ifupdownmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def log_error(self, str):
pass

def link_exists(self, ifacename):
return os.path.exists('/sys/class/net/%s' %ifacename)
return self.netlink.link_exists(ifacename)

def __init__(self, config={}, args=None,
daemon=False, force=False, dryrun=False, nowait=False,
Expand Down Expand Up @@ -498,28 +498,36 @@ def create_n_save_ifaceobj(self, ifacename, priv_flags=None,
increfcnt=False):
""" creates a iface object and adds it to the iface dictionary """
ifaceobj = iface()
ifaceobj.name = ifacename
ifaceobj.name = self.netlink.link_translate_altname(ifacename)
ifaceobj.priv_flags = priv_flags
ifaceobj.auto = True
if not self._link_master_slave:
ifaceobj.link_type = ifaceLinkType.LINK_NA
if increfcnt:
ifaceobj.inc_refcnt()

self.ifaceobjdict[ifacename] = [ifaceobj]
for altname in self.netlink.link_get_altnames(ifacename):
self.ifaceobjdict[ifacename] = [ifaceobj]

return ifaceobj

def create_n_save_ifaceobjcurr(self, ifaceobj):
""" creates a copy of iface object and adds it to the iface
dict containing current iface objects
"""
ifaceobjcurr = iface()
ifaceobjcurr.name = ifaceobj.name
ifaceobjcurr.name = self.netlink.link_translate_altname(ifaceobj.name)
ifaceobjcurr.type = ifaceobj.type
ifaceobjcurr.lowerifaces = ifaceobj.lowerifaces
ifaceobjcurr.priv_flags = copy.deepcopy(ifaceobj.priv_flags)
ifaceobjcurr.auto = ifaceobj.auto

self.ifaceobjcurrdict.setdefault(ifaceobj.name,
[]).append(ifaceobjcurr)
for altname in self.netlink.link_get_altnames(ifaceobj.name):
self.ifaceobjcurrdict.setdefault(altname, []).append(ifaceobjcurr)

return ifaceobjcurr

def get_ifaceobjcurr(self, ifacename, idx=0):
Expand Down Expand Up @@ -722,7 +730,7 @@ def query_lowerifaces(self, ifaceobj, ops, ifacenames, old_ifaceobjs):
self.logger.warning("%s: %s: error getting dependent interfaces (%s)" % (ifaceobj.name, module, str(e)))
dlist = None
if dlist: ret_dlist.extend(dlist)
return list(set(ret_dlist))
return self.netlink.link_translate_altnames(list(set(ret_dlist)))

def query_upperifaces(self, ifaceobj, ops, ifacenames, type=None):
""" Gets iface upperifaces by calling into respective modules """
Expand All @@ -746,7 +754,7 @@ def query_upperifaces(self, ifaceobj, ops, ifacenames, type=None):
ulist = None
pass
if ulist: ret_ulist.extend(ulist)
return list(set(ret_ulist))
return self.netlink.link_translate_altnames(list(set(ret_ulist)))

def _remove_circular_veth_dependencies(self, ifaceobj, dlist):
# if ifaceobj isn't a veth link, ignore it.
Expand Down Expand Up @@ -1879,7 +1887,10 @@ def check_running_configuration(self, filtered_ifacenames, all=False):
auto = False
break

if not ifupdownflags.flags.DRYRUN and auto and not os.path.exists("/sys/class/net/%s" % ifname) and not self._is_ifaceobj_bridge_vlan(ifaceobj_list):
if (not ifupdownflags.flags.DRYRUN
and auto
and not self.link_exists(ifname)
and not self._is_ifaceobj_bridge_vlan(ifaceobj_list)):
self.logger.warning("%s: interface not recognized - please check interface configuration" % ifname)

def _is_ifaceobj_bridge_vlan(self, ifaceobj_list):
Expand Down
9 changes: 5 additions & 4 deletions ifupdown2/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def __check_l3vni_bridge(self, ifaceobj):
and len(self._get_ifaceobj_bridge_ports(ifaceobj, as_list=True)) == 1:
ifaceobj.link_privflags |= ifaceLinkPrivFlags.BRIDGE_l3VNI

@staticmethod
def _get_ifaceobj_bridge_ports(ifaceobj, as_list=False):
def _get_ifaceobj_bridge_ports(self, ifaceobj, as_list=False):
bridge_ports = []

for brport in ifaceobj.get_attr_value('bridge-ports') or []:
if brport != 'none':
bridge_ports.extend(brport.split())
bridge_ports = self.cache.link_translate_altnames(bridge_ports)

if as_list:
return bridge_ports
Expand All @@ -185,14 +185,15 @@ def _get_bridge_port_list(self, ifaceobj):
# of parsing port expr again
port_list = ifaceobj.lowerifaces
if port_list:
return port_list
return self.cache.link_translate_altnames(port_list)

ports = self._get_ifaceobj_bridge_ports(ifaceobj)
if ports:
# _get_ifaceobj_bridge_ports() already translates altnames
return self.parse_port_list(ifaceobj.name, ports)
else:
return None


class AddonWithIpBlackList(Addon):
try:
ip_blacklist = [ipnetwork.IPNetwork(ip).ip for ip in policymanager.policymanager_api.get_module_globals(
Expand Down
Loading