Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addons: openvswitch: allow multiple ovs-ports + glob/regex #164

Merged
merged 1 commit into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions ifupdown2/addons/openvswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class openvswitch(Addon, moduleBase):
'help': 'Interfaces to be part of this ovs bridge.',
'validvals': ['<interface-list>'],
'required': False,
"multivalue": True,
"example": [
"ovs-ports swp1.100 swp2.100 swp3.100",
"ovs-ports glob swp1-3.100",
"ovs-ports regex (swp[1|2|3].100)"
]
},
'ovs-type': {
'help': 'ovs interface type',
Expand Down Expand Up @@ -87,10 +93,15 @@ def _is_ovs_bridge (self, ifaceobj):
return False

def _get_ovs_ports (self, ifaceobj):
ovs_ports = ifaceobj.get_attr_value_first('ovs-ports')
ovs_ports = []

for port in ifaceobj.get_attr_value('ovs-ports') or []:
ovs_ports.extend(port.split())

if ovs_ports:
return sorted (ovs_ports.split ())
return None
return self.parse_port_list(ifaceobj.name, ' '.join(ovs_ports))
else:
return None

def _get_running_ovs_ports (self, iface):
output = utils.exec_command("/usr/bin/ovs-vsctl list-ports %s" %iface)
Expand Down Expand Up @@ -152,6 +163,7 @@ def _addbridge (self, ifaceobj):
ovs_ports = self._get_ovs_ports(ifaceobj)
running_ovs_ports = self._get_running_ovs_ports(iface)

missingports = []
if running_ovs_ports is not None and ovs_ports is not None:
missingports = list(set(running_ovs_ports) - set(ovs_ports))

Expand Down