Skip to content

Commit 235d7d0

Browse files
addons: ovs: translate altnames in config items to primary interface names
Enables using the `openvswitch` addon with altnames. Signed-off-by: Christoph Heiss <[email protected]>
1 parent 55b5f4e commit 235d7d0

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

ifupdown2/addons/openvswitch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _get_ovs_ports (self, ifaceobj):
103103
ovs_ports.extend(port.split())
104104

105105
if ovs_ports:
106+
ovs_ports = self.cache.link_translate_altnames(ovs_ports)
106107
return self.parse_port_list(ifaceobj.name, ' '.join(ovs_ports))
107108
else:
108109
return None

ifupdown2/addons/openvswitch_port.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,28 @@ def __init__ (self, *args, **kargs):
9494

9595
def _is_ovs_port (self, ifaceobj):
9696
ovstype = ifaceobj.get_attr_value_first ('ovs-type')
97-
ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
97+
ovsbridge = self._get_ovs_bridge(ifaceobj)
9898
if ovstype and ovsbridge:
9999
return True
100100
return False
101101

102+
def _get_ovs_bridge(self, ifaceobj):
103+
"""
104+
Returns the ifname of the `ovs-bridge` property. Translates altnames
105+
to the primary ifname if needed.
106+
:param ifaceobj: interface config object
107+
:return: `ovs-bridge` ifname
108+
"""
109+
ifname = ifaceobj.get_attr_value_first('ovs-bridge')
110+
if ifname:
111+
return self.cache.link_translate_altname(ifname)
112+
return None
113+
102114
def _get_bond_ifaces (self, ifaceobj):
103115
ovs_bonds = ifaceobj.get_attr_value_first ('ovs-bonds')
104116
if ovs_bonds:
105-
return sorted (ovs_bonds.split ())
117+
ovs_bonds = self.cache.link_translate_altnames(ovs_bonds.split())
118+
return sorted(ovs_bonds)
106119
return None
107120

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

130143
def _addport (self, ifaceobj):
131144
iface = ifaceobj.name
132-
ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
145+
ovsbridge = self._get_ovs_bridge(ifaceobj)
133146
ovsoptions = ifaceobj.get_attr_value_first ('ovs-options')
134147
ovstype = ifaceobj.get_attr_value_first ('ovs-type')
135-
ovsbonds = ifaceobj.get_attr_value_first ('ovs-bonds')
148+
149+
ovsbonds_list = self._get_bond_ifaces(ifaceobj)
150+
ovsbonds = ' '.join(ovsbonds_list) if ovsbonds_list else None
151+
136152
ovsextra = ifaceobj.get_attr_value('ovs-extra')
137153

138154
cmd_list = []
@@ -183,11 +199,10 @@ def _addport (self, ifaceobj):
183199

184200
#mtu
185201
ovsmtu = ifaceobj.get_attr_value_first ('ovs-mtu')
186-
ovsbonds_list = self._get_bond_ifaces(ifaceobj)
187202
if ovsmtu is not None:
188203
#we can't set mtu on bond fake interface, we apply it on slaves interfaces
189204
if ovstype == 'OVSBond' and ovsbonds_list is not None:
190-
for slave in ovsbonds_list:
205+
for slave in ovsbonds_list:
191206
cmd = "set Interface %s mtu_request=%s"%(slave,ovsmtu)
192207
cmd_list.append(cmd)
193208

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

208223
def _delport (self, ifaceobj):
209224
iface = ifaceobj.name
210-
ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
225+
ovsbridge = self._get_ovs_bridge(ifaceobj)
211226
cmd = "--if-exists del-port %s %s"%(ovsbridge, iface)
212227

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

220235
ifaceobj.link_privflags |= ifaceLinkPrivFlags.OPENVSWITCH
221236

222-
ovsbridge = ifaceobj.get_attr_value_first ('ovs-bridge')
237+
ovsbridge = self._get_ovs_bridge(ifaceobj)
223238
return [ovsbridge]
224239

225240
def _up (self, ifaceobj):

0 commit comments

Comments
 (0)