1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00
Roopa Prabhu 84ca006f82 First phase checkin for new format for vlan aware bridge
Ticket: CM-3346
Reviewed By:
Testing Done: Sanity test + test new bridge format

There are a bunch of open issues with `vlan` interface handling.
Below is the format.

auto swp1
iface swp1
    bridge-access 300
    mstpctl-pathcost 0
    mstpctl-adminedge yes
    mstpctl-autoedge yes
    mstpctl-p2p yes
    mstpctl-bpduguard yes
    mstpctl-treeprio 64
    mstpctl-network yes
    mstpctl-bpdufilter yes

auto swp2
iface swp2
    bridge-vids 301
    bridge-pvid 302
    bridge-pathcost 10
    bridge-priority 10
    bridge-multicast-router 0
    bridge-multicast-fast-leave 1

auto br0
iface br0
    bridge-vlan-aware yes
    bridge-stp on
    bridge-ports swp1 swp2
    bridge-vids 2001

auto br0.2001
iface br0.2001
    address 10.0.14.2
    hwaddress 00:03:00:00:00:12
    address-virtual 00:00:5e:00:01:01 11.0.4.1/24

auto br0.2001
vlan br0.2001
    bridge-igmp-querier-src 172.16.101.1
2014-10-24 10:11:07 -07:00

98 lines
3.5 KiB
Python

#!/usr/bin/python
#
# Copyright 2014 Cumulus Networks, Inc. All rights reserved.
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
#
import subprocess
import ifupdownaddons
class usercmds(ifupdownaddons.modulebase.moduleBase):
""" ifupdown2 addon module to configure user specified commands """
_modinfo = {'mhelp' : 'user commands for interfaces',
'attrs' : {
'pre-up' :
{'help' : 'run command before bringing the interface up'},
'up' :
{'help' : 'run command at interface bring up'},
'post-up' :
{'help' : 'run command after interface bring up'},
'pre-down' :
{'help' : 'run command before bringing the interface down'},
'down' :
{'help' : 'run command at interface down'},
'post-down' :
{'help' : 'run command after bringing interface down'}}}
def _exec_user_cmd(self, cmd):
""" exec's commands using subprocess Popen
special wrapper using use closefds=True and shell=True
for user commands
"""
cmd_returncode = 0
try:
self.logger.info('executing %s' %cmd)
if self.DRYRUN:
return
ch = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT,
close_fds=True)
cmd_returncode = ch.wait()
cmdout = ch.communicate()[0]
except Exception, e:
raise Exception('failed to execute cmd \'%s\' (%s)'
%(cmd, str(e)))
if cmd_returncode != 0:
raise Exception(cmdout)
return cmdout
def _run_command(self, ifaceobj, op):
cmd_list = ifaceobj.get_attr_value(op)
if cmd_list:
for cmd in cmd_list:
self.logger.info('executing cmd \'%s\'' %cmd)
try:
self._exec_user_cmd(cmd)
except Exception, e:
if not self.ignore_error(str(e)):
self.logger.warn('%s: %s cmd \'%s\' failed (%s)'
%(ifaceobj.name, op, cmd, str(e).strip('\n')))
pass
_run_ops = {'pre-up' : _run_command,
'pre-down' : _run_command,
'up' : _run_command,
'post-up' : _run_command,
'down' : _run_command,
'post-down' : _run_command}
def get_ops(self):
""" returns list of ops supported by this module """
return self._run_ops.keys()
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
""" run user commands
Args:
**ifaceobj** (object): iface object
**operation** (str): list of ops
Kwargs:
**query_ifaceobj** (object): query check ifaceobject. This is only
valid when op is 'query-checkcurr'. It is an object same as
ifaceobj, but contains running attribute values and its config
status. The modules can use it to return queried running state
of interfaces. status is success if the running state is same
as user required state in ifaceobj. error otherwise.
"""
op_handler = self._run_ops.get(operation)
if not op_handler:
return
op_handler(self, ifaceobj, operation)