mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Allow customer set bond defaults for CL with ifupdown2
Ticket: CM-6723 Reviewed By: roopa Testing Done: unit tested and testifupdown2 test suite This patch installs bond interface defaults in /etc/network/ifupdown2/policy.d/bond_defaults.json and allows users to modify this file. Users can then leave out these bond attributes in their configs to save typing and space. It also changes the ifenslave and ifenslaveutil module to bond and bondutil, respectively to be consistent with other modules (and also because customers think of "bond" interfaces not "ifenslave" interfaces.) For example, the default file installed looks like the following: { "README": "This file is user generated and modifiable.", "bond": { "defaults": { "bond-mode": "802.3ad", "bond-miimon": "100", "bond-use-carrier": "1", "bond-lacp-rate": "0", "bond-min-links": "1", "bond-xmic-hash-policy": "layer3+4" } } } Please enter the commit message for your changes. Lines starting
This commit is contained in:
@@ -8,11 +8,12 @@ from sets import Set
|
|||||||
from ifupdown.iface import *
|
from ifupdown.iface import *
|
||||||
import ifupdownaddons
|
import ifupdownaddons
|
||||||
from ifupdownaddons.modulebase import moduleBase
|
from ifupdownaddons.modulebase import moduleBase
|
||||||
from ifupdownaddons.ifenslaveutil import ifenslaveutil
|
from ifupdownaddons.bondutil import bondutil
|
||||||
from ifupdownaddons.iproute2 import iproute2
|
from ifupdownaddons.iproute2 import iproute2
|
||||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||||
|
import ifupdown.policymanager as policymanager
|
||||||
|
|
||||||
class ifenslave(moduleBase):
|
class bond(moduleBase):
|
||||||
""" ifupdown2 addon module to configure bond interfaces """
|
""" ifupdown2 addon module to configure bond interfaces """
|
||||||
_modinfo = { 'mhelp' : 'bond configuration module',
|
_modinfo = { 'mhelp' : 'bond configuration module',
|
||||||
'attrs' : {
|
'attrs' : {
|
||||||
@@ -109,7 +110,7 @@ class ifenslave(moduleBase):
|
|||||||
def __init__(self, *args, **kargs):
|
def __init__(self, *args, **kargs):
|
||||||
ifupdownaddons.modulebase.moduleBase.__init__(self, *args, **kargs)
|
ifupdownaddons.modulebase.moduleBase.__init__(self, *args, **kargs)
|
||||||
self.ipcmd = None
|
self.ipcmd = None
|
||||||
self.ifenslavecmd = None
|
self.bondcmd = None
|
||||||
|
|
||||||
def _is_bond(self, ifaceobj):
|
def _is_bond(self, ifaceobj):
|
||||||
if ifaceobj.get_attr_value_first('bond-slaves'):
|
if ifaceobj.get_attr_value_first('bond-slaves'):
|
||||||
@@ -135,7 +136,7 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
def get_dependent_ifacenames_running(self, ifaceobj):
|
def get_dependent_ifacenames_running(self, ifaceobj):
|
||||||
self._init_command_handlers()
|
self._init_command_handlers()
|
||||||
return self.ifenslavecmd.get_slaves(ifaceobj.name)
|
return self.bondcmd.get_slaves(ifaceobj.name)
|
||||||
|
|
||||||
def _get_slave_list(self, ifaceobj):
|
def _get_slave_list(self, ifaceobj):
|
||||||
""" Returns slave list present in ifaceobj config """
|
""" Returns slave list present in ifaceobj config """
|
||||||
@@ -151,6 +152,12 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
def fetch_attr(self, ifaceobj, attrname):
|
def fetch_attr(self, ifaceobj, attrname):
|
||||||
attrval = ifaceobj.get_attr_value_first(attrname)
|
attrval = ifaceobj.get_attr_value_first(attrname)
|
||||||
|
# grab the defaults from the policy file in case the
|
||||||
|
# user did not specify something.
|
||||||
|
policy_default_val = policymanager.policymanager_api.\
|
||||||
|
get_iface_default(module_name=self.__class__.__name__,
|
||||||
|
ifname=ifaceobj.name,
|
||||||
|
attr=attrname)
|
||||||
if attrval:
|
if attrval:
|
||||||
msg = ('%s: invalid value %s for attr %s.'
|
msg = ('%s: invalid value %s for attr %s.'
|
||||||
%(ifaceobj.name, attrval, attrname))
|
%(ifaceobj.name, attrval, attrname))
|
||||||
@@ -173,6 +180,8 @@ class ifenslave(moduleBase):
|
|||||||
self.logger.warn('%s: required attribute %s'
|
self.logger.warn('%s: required attribute %s'
|
||||||
%(ifaceobj.name, dattrname) +
|
%(ifaceobj.name, dattrname) +
|
||||||
' not present or set to \'0\'')
|
' not present or set to \'0\'')
|
||||||
|
elif policy_default_val:
|
||||||
|
return policy_default_val
|
||||||
elif attrname in ['bond-lacp-bypass-allow', 'bond-lacp-bypass-all-active', 'bond-lacp-bypass-period']:
|
elif attrname in ['bond-lacp-bypass-allow', 'bond-lacp-bypass-all-active', 'bond-lacp-bypass-period']:
|
||||||
# For some attrs, set default values
|
# For some attrs, set default values
|
||||||
optiondict = self.get_mod_attr(attrname)
|
optiondict = self.get_mod_attr(attrname)
|
||||||
@@ -183,7 +192,7 @@ class ifenslave(moduleBase):
|
|||||||
def _apply_master_settings(self, ifaceobj):
|
def _apply_master_settings(self, ifaceobj):
|
||||||
have_attrs_to_set = 0
|
have_attrs_to_set = 0
|
||||||
linkup = False
|
linkup = False
|
||||||
ifenslavecmd_attrmap = OrderedDict([('bond-mode' , 'mode'),
|
bondcmd_attrmap = OrderedDict([('bond-mode' , 'mode'),
|
||||||
('bond-miimon' , 'miimon'),
|
('bond-miimon' , 'miimon'),
|
||||||
('bond-use-carrier', 'use_carrier'),
|
('bond-use-carrier', 'use_carrier'),
|
||||||
('bond-lacp-rate' , 'lacp_rate'),
|
('bond-lacp-rate' , 'lacp_rate'),
|
||||||
@@ -203,14 +212,14 @@ class ifenslave(moduleBase):
|
|||||||
# order of attributes set matters for bond, so
|
# order of attributes set matters for bond, so
|
||||||
# construct the list sequentially
|
# construct the list sequentially
|
||||||
attrstoset = OrderedDict()
|
attrstoset = OrderedDict()
|
||||||
for k, dstk in ifenslavecmd_attrmap.items():
|
for k, dstk in bondcmd_attrmap.items():
|
||||||
v = self.fetch_attr(ifaceobj, k)
|
v = self.fetch_attr(ifaceobj, k)
|
||||||
if v:
|
if v:
|
||||||
attrstoset[dstk] = v
|
attrstoset[dstk] = v
|
||||||
if not attrstoset:
|
if not attrstoset:
|
||||||
return
|
return
|
||||||
have_attrs_to_set = 1
|
have_attrs_to_set = 1
|
||||||
self.ifenslavecmd.set_attrs(ifaceobj.name, attrstoset,
|
self.bondcmd.set_attrs(ifaceobj.name, attrstoset,
|
||||||
self.ipcmd.link_down if linkup else None)
|
self.ipcmd.link_down if linkup else None)
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
@@ -227,7 +236,7 @@ class ifenslave(moduleBase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not self.PERFMODE:
|
if not self.PERFMODE:
|
||||||
runningslaves = self.ifenslavecmd.get_slaves(ifaceobj.name);
|
runningslaves = self.bondcmd.get_slaves(ifaceobj.name);
|
||||||
|
|
||||||
for slave in Set(slaves).difference(Set(runningslaves)):
|
for slave in Set(slaves).difference(Set(runningslaves)):
|
||||||
if not self.PERFMODE and not self.ipcmd.link_exists(slave):
|
if not self.PERFMODE and not self.ipcmd.link_exists(slave):
|
||||||
@@ -249,16 +258,16 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
if runningslaves:
|
if runningslaves:
|
||||||
# Delete active slaves not in the new slave list
|
# Delete active slaves not in the new slave list
|
||||||
[ self.ifenslavecmd.remove_slave(ifaceobj.name, s)
|
[ self.bondcmd.remove_slave(ifaceobj.name, s)
|
||||||
for s in runningslaves if s not in slaves ]
|
for s in runningslaves if s not in slaves ]
|
||||||
|
|
||||||
def _set_clag_enable(self, ifaceobj):
|
def _set_clag_enable(self, ifaceobj):
|
||||||
attrval = ifaceobj.get_attr_value_first('clag-id')
|
attrval = ifaceobj.get_attr_value_first('clag-id')
|
||||||
attrval = attrval if attrval else '0'
|
attrval = attrval if attrval else '0'
|
||||||
self.ifenslavecmd.set_clag_enable(ifaceobj.name, attrval)
|
self.bondcmd.set_clag_enable(ifaceobj.name, attrval)
|
||||||
|
|
||||||
def _apply_slaves_lacp_bypass_prio(self, ifaceobj):
|
def _apply_slaves_lacp_bypass_prio(self, ifaceobj):
|
||||||
slaves = self.ifenslavecmd.get_slaves(ifaceobj.name)
|
slaves = self.bondcmd.get_slaves(ifaceobj.name)
|
||||||
if not slaves:
|
if not slaves:
|
||||||
return
|
return
|
||||||
attrval = ifaceobj.get_attrs_value_first(['bond-lacp-bypass-priority',
|
attrval = ifaceobj.get_attrs_value_first(['bond-lacp-bypass-priority',
|
||||||
@@ -277,7 +286,7 @@ class ifenslave(moduleBase):
|
|||||||
%(ifaceobj.name, port))
|
%(ifaceobj.name, port))
|
||||||
continue
|
continue
|
||||||
slaves.remove(port)
|
slaves.remove(port)
|
||||||
self.ifenslavecmd.set_lacp_fallback_priority(
|
self.bondcmd.set_lacp_fallback_priority(
|
||||||
ifaceobj.name, port, val)
|
ifaceobj.name, port, val)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log_warn('%s: failed to set lacp_fallback_priority %s (%s)'
|
self.log_warn('%s: failed to set lacp_fallback_priority %s (%s)'
|
||||||
@@ -285,7 +294,7 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
for p in slaves:
|
for p in slaves:
|
||||||
try:
|
try:
|
||||||
self.ifenslavecmd.set_lacp_fallback_priority(ifaceobj.name, p, '0')
|
self.bondcmd.set_lacp_fallback_priority(ifaceobj.name, p, '0')
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log_warn('%s: failed to clear lacp_bypass_priority %s (%s)'
|
self.log_warn('%s: failed to clear lacp_bypass_priority %s (%s)'
|
||||||
%(ifaceobj.name, p, str(e)))
|
%(ifaceobj.name, p, str(e)))
|
||||||
@@ -294,7 +303,7 @@ class ifenslave(moduleBase):
|
|||||||
def _up(self, ifaceobj):
|
def _up(self, ifaceobj):
|
||||||
try:
|
try:
|
||||||
if not self.ipcmd.link_exists(ifaceobj.name):
|
if not self.ipcmd.link_exists(ifaceobj.name):
|
||||||
self.ifenslavecmd.create_bond(ifaceobj.name)
|
self.bondcmd.create_bond(ifaceobj.name)
|
||||||
self._apply_master_settings(ifaceobj)
|
self._apply_master_settings(ifaceobj)
|
||||||
# clag_enable has to happen before the slaves are added to the bond
|
# clag_enable has to happen before the slaves are added to the bond
|
||||||
self._set_clag_enable(ifaceobj)
|
self._set_clag_enable(ifaceobj)
|
||||||
@@ -307,14 +316,14 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
def _down(self, ifaceobj):
|
def _down(self, ifaceobj):
|
||||||
try:
|
try:
|
||||||
self.ifenslavecmd.delete_bond(ifaceobj.name)
|
self.bondcmd.delete_bond(ifaceobj.name)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log_warn(str(e))
|
self.log_warn(str(e))
|
||||||
|
|
||||||
def _query_check(self, ifaceobj, ifaceobjcurr):
|
def _query_check(self, ifaceobj, ifaceobjcurr):
|
||||||
slaves = None
|
slaves = None
|
||||||
|
|
||||||
if not self.ifenslavecmd.bond_exists(ifaceobj.name):
|
if not self.bondcmd.bond_exists(ifaceobj.name):
|
||||||
self.logger.debug('bond iface %s' %ifaceobj.name +
|
self.logger.debug('bond iface %s' %ifaceobj.name +
|
||||||
' does not exist')
|
' does not exist')
|
||||||
return
|
return
|
||||||
@@ -367,36 +376,36 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
def _query_running_attrs(self, bondname):
|
def _query_running_attrs(self, bondname):
|
||||||
bondattrs = {'bond-mode' :
|
bondattrs = {'bond-mode' :
|
||||||
self.ifenslavecmd.get_mode(bondname),
|
self.bondcmd.get_mode(bondname),
|
||||||
'bond-miimon' :
|
'bond-miimon' :
|
||||||
self.ifenslavecmd.get_miimon(bondname),
|
self.bondcmd.get_miimon(bondname),
|
||||||
'bond-use-carrier' :
|
'bond-use-carrier' :
|
||||||
self.ifenslavecmd.get_use_carrier(bondname),
|
self.bondcmd.get_use_carrier(bondname),
|
||||||
'bond-lacp-rate' :
|
'bond-lacp-rate' :
|
||||||
self.ifenslavecmd.get_lacp_rate(bondname),
|
self.bondcmd.get_lacp_rate(bondname),
|
||||||
'bond-min-links' :
|
'bond-min-links' :
|
||||||
self.ifenslavecmd.get_min_links(bondname),
|
self.bondcmd.get_min_links(bondname),
|
||||||
'bond-ad-sys-mac-addr' :
|
'bond-ad-sys-mac-addr' :
|
||||||
self.ifenslavecmd.get_ad_sys_mac_addr(bondname),
|
self.bondcmd.get_ad_sys_mac_addr(bondname),
|
||||||
'bond-ad-sys-priority' :
|
'bond-ad-sys-priority' :
|
||||||
self.ifenslavecmd.get_ad_sys_priority(bondname),
|
self.bondcmd.get_ad_sys_priority(bondname),
|
||||||
'bond-xmit-hash-policy' :
|
'bond-xmit-hash-policy' :
|
||||||
self.ifenslavecmd.get_xmit_hash_policy(bondname),
|
self.bondcmd.get_xmit_hash_policy(bondname),
|
||||||
'bond-lacp-bypass-allow' :
|
'bond-lacp-bypass-allow' :
|
||||||
self.ifenslavecmd.get_lacp_fallback_allow(bondname),
|
self.bondcmd.get_lacp_fallback_allow(bondname),
|
||||||
'bond-lacp-bypass-period' :
|
'bond-lacp-bypass-period' :
|
||||||
self.ifenslavecmd.get_lacp_fallback_period(bondname),
|
self.bondcmd.get_lacp_fallback_period(bondname),
|
||||||
'bond-lacp-bypass-priority' :
|
'bond-lacp-bypass-priority' :
|
||||||
self.ifenslavecmd.get_lacp_fallback_priority(bondname),
|
self.bondcmd.get_lacp_fallback_priority(bondname),
|
||||||
'bond-lacp-bypass-all-active' :
|
'bond-lacp-bypass-all-active' :
|
||||||
self.ifenslavecmd.get_lacp_fallback_all_active(bondname)}
|
self.bondcmd.get_lacp_fallback_all_active(bondname)}
|
||||||
slaves = self.ifenslavecmd.get_slaves(bondname)
|
slaves = self.bondcmd.get_slaves(bondname)
|
||||||
if slaves:
|
if slaves:
|
||||||
bondattrs['bond-slaves'] = slaves
|
bondattrs['bond-slaves'] = slaves
|
||||||
return bondattrs
|
return bondattrs
|
||||||
|
|
||||||
def _query_running(self, ifaceobjrunning):
|
def _query_running(self, ifaceobjrunning):
|
||||||
if not self.ifenslavecmd.bond_exists(ifaceobjrunning.name):
|
if not self.bondcmd.bond_exists(ifaceobjrunning.name):
|
||||||
return
|
return
|
||||||
bondattrs = self._query_running_attrs(ifaceobjrunning.name)
|
bondattrs = self._query_running_attrs(ifaceobjrunning.name)
|
||||||
if bondattrs.get('bond-slaves'):
|
if bondattrs.get('bond-slaves'):
|
||||||
@@ -418,8 +427,8 @@ class ifenslave(moduleBase):
|
|||||||
flags = self.get_flags()
|
flags = self.get_flags()
|
||||||
if not self.ipcmd:
|
if not self.ipcmd:
|
||||||
self.ipcmd = iproute2(**flags)
|
self.ipcmd = iproute2(**flags)
|
||||||
if not self.ifenslavecmd:
|
if not self.bondcmd:
|
||||||
self.ifenslavecmd = ifenslaveutil(**flags)
|
self.bondcmd = bondutil(**flags)
|
||||||
|
|
||||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||||
""" run bond configuration on the interface object passed as argument
|
""" run bond configuration on the interface object passed as argument
|
@@ -1,4 +1,4 @@
|
|||||||
pre-up,ifenslave
|
pre-up,bond
|
||||||
pre-up,vlan
|
pre-up,vlan
|
||||||
pre-up,vxlan
|
pre-up,vxlan
|
||||||
pre-up,clagd
|
pre-up,clagd
|
||||||
@@ -27,5 +27,5 @@ post-down,bridgevlan
|
|||||||
post-down,bridge
|
post-down,bridge
|
||||||
post-down,vxlan
|
post-down,vxlan
|
||||||
post-down,vlan
|
post-down,vlan
|
||||||
post-down,ifenslave
|
post-down,bond
|
||||||
post-down,usercmds
|
post-down,usercmds
|
||||||
|
@@ -32,12 +32,12 @@ ethtool
|
|||||||
|
|
||||||
.. autoclass:: ethtool
|
.. autoclass:: ethtool
|
||||||
|
|
||||||
ifenslave
|
bond
|
||||||
=========
|
====
|
||||||
|
|
||||||
.. automodule:: ifenslave
|
.. automodule:: bond
|
||||||
|
|
||||||
.. autoclass:: ifenslave
|
.. autoclass:: bond
|
||||||
|
|
||||||
mstpctl
|
mstpctl
|
||||||
=======
|
=======
|
||||||
|
@@ -15,15 +15,15 @@ Helper module to work with bridgeutil commands
|
|||||||
|
|
||||||
.. autoclass:: brctl
|
.. autoclass:: brctl
|
||||||
|
|
||||||
ifenslaveutil
|
bondutil
|
||||||
=============
|
========
|
||||||
|
|
||||||
Helper module to interact with linux api to create bonds.
|
Helper module to interact with linux api to create bonds.
|
||||||
Currently this is via sysfs.
|
Currently this is via sysfs.
|
||||||
|
|
||||||
.. automodule:: ifenslaveutil
|
.. automodule:: bondutil
|
||||||
|
|
||||||
.. autoclass:: ifenslaveutil
|
.. autoclass:: bondutil
|
||||||
|
|
||||||
dhclient
|
dhclient
|
||||||
========
|
========
|
||||||
|
@@ -11,7 +11,7 @@ from utilsbase import *
|
|||||||
from iproute2 import *
|
from iproute2 import *
|
||||||
from cache import *
|
from cache import *
|
||||||
|
|
||||||
class ifenslaveutil(utilsBase):
|
class bondutil(utilsBase):
|
||||||
""" This class contains methods to interact with linux kernel bond
|
""" This class contains methods to interact with linux kernel bond
|
||||||
related interfaces """
|
related interfaces """
|
||||||
|
|
||||||
@@ -80,9 +80,9 @@ class ifenslaveutil(utilsBase):
|
|||||||
if self.DRYRUN:
|
if self.DRYRUN:
|
||||||
return None
|
return None
|
||||||
if self.CACHE:
|
if self.CACHE:
|
||||||
if not ifenslaveutil._cache_fill_done:
|
if not bondutil._cache_fill_done:
|
||||||
self._bond_linkinfo_fill_all()
|
self._bond_linkinfo_fill_all()
|
||||||
ifenslaveutil._cache_fill_done = True
|
bondutil._cache_fill_done = True
|
||||||
return linkCache.get_attr(attrlist)
|
return linkCache.get_attr(attrlist)
|
||||||
if not refresh:
|
if not refresh:
|
||||||
return linkCache.get_attr(attrlist)
|
return linkCache.get_attr(attrlist)
|
@@ -15,7 +15,7 @@ from ifupdown.iface import *
|
|||||||
#from ifupdownaddons.dhclient import *
|
#from ifupdownaddons.dhclient import *
|
||||||
#from ifupdownaddons.bridgeutils import *
|
#from ifupdownaddons.bridgeutils import *
|
||||||
#from ifupdownaddons.mstpctlutil import *
|
#from ifupdownaddons.mstpctlutil import *
|
||||||
#from ifupdownaddons.ifenslaveutil import *
|
#from ifupdownaddons.bondutil import *
|
||||||
|
|
||||||
class moduleBase(object):
|
class moduleBase(object):
|
||||||
""" Base class for ifupdown addon modules
|
""" Base class for ifupdown addon modules
|
||||||
|
@@ -968,7 +968,7 @@ EXAMPLES
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
**ifenslave**: bond configuration module
|
**bond**: bond configuration module
|
||||||
|
|
||||||
|
|
||||||
**bond-use-carrier**
|
**bond-use-carrier**
|
||||||
|
2
setup.py
2
setup.py
@@ -34,7 +34,7 @@ setup(name='ifupdown2',
|
|||||||
'docs/examples/vlan_aware_bridges/interfaces.with_clag']),
|
'docs/examples/vlan_aware_bridges/interfaces.with_clag']),
|
||||||
('/etc/bash_completion.d/', ['completion/ifup']),
|
('/etc/bash_completion.d/', ['completion/ifup']),
|
||||||
('/usr/share/ifupdownaddons/', ['addons/bridge.py',
|
('/usr/share/ifupdownaddons/', ['addons/bridge.py',
|
||||||
'addons/ifenslave.py', 'addons/vlan.py',
|
'addons/bond.py', 'addons/vlan.py',
|
||||||
'addons/mstpctl.py', 'addons/address.py',
|
'addons/mstpctl.py', 'addons/address.py',
|
||||||
'addons/dhcp.py', 'addons/usercmds.py',
|
'addons/dhcp.py', 'addons/usercmds.py',
|
||||||
'addons/ethtool.py', 'addons/loopback.py',
|
'addons/ethtool.py', 'addons/loopback.py',
|
||||||
|
Reference in New Issue
Block a user