2014-10-09 16:02:46 -07:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright 2014 Cumulus Networks, Inc. All rights reserved.
|
|
|
|
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
|
|
|
#
|
|
|
|
|
|
|
|
from sets import Set
|
|
|
|
from ifupdown.iface import *
|
|
|
|
import ifupdownaddons
|
|
|
|
from ifupdownaddons.modulebase import moduleBase
|
2015-07-22 18:38:07 -04:00
|
|
|
from ifupdownaddons.bondutil import bondutil
|
2014-10-09 16:02:46 -07:00
|
|
|
from ifupdownaddons.iproute2 import iproute2
|
2014-11-12 10:51:07 -08:00
|
|
|
import ifupdown.rtnetlink_api as rtnetlink_api
|
2015-07-22 18:38:07 -04:00
|
|
|
import ifupdown.policymanager as policymanager
|
2016-04-14 14:45:47 -07:00
|
|
|
import ifupdown.ifupdownflags as ifupdownflags
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2015-07-22 18:38:07 -04:00
|
|
|
class bond(moduleBase):
|
2014-10-09 16:02:46 -07:00
|
|
|
""" ifupdown2 addon module to configure bond interfaces """
|
|
|
|
_modinfo = { 'mhelp' : 'bond configuration module',
|
|
|
|
'attrs' : {
|
|
|
|
'bond-use-carrier':
|
|
|
|
{'help' : 'bond use carrier',
|
|
|
|
'validvals' : ['0', '1'],
|
|
|
|
'default' : '1',
|
|
|
|
'example': ['bond-use-carrier 1']},
|
|
|
|
'bond-num-grat-arp':
|
|
|
|
{'help' : 'bond use carrier',
|
|
|
|
'validrange' : ['0', '255'],
|
|
|
|
'default' : '1',
|
|
|
|
'example' : ['bond-num-grat-arp 1']},
|
|
|
|
'bond-num-unsol-na' :
|
|
|
|
{'help' : 'bond slave devices',
|
|
|
|
'validrange' : ['0', '255'],
|
|
|
|
'default' : '1',
|
|
|
|
'example' : ['bond-num-unsol-na 1']},
|
|
|
|
'bond-xmit-hash-policy' :
|
|
|
|
{'help' : 'bond slave devices',
|
|
|
|
'validvals' : ['layer2', 'layer3+4', 'layer2+3'],
|
|
|
|
'default' : 'layer2',
|
|
|
|
'example' : ['bond-xmit-hash-policy layer2']},
|
|
|
|
'bond-miimon' :
|
|
|
|
{'help' : 'bond miimon',
|
|
|
|
'validrange' : ['0', '255'],
|
|
|
|
'default' : '0',
|
|
|
|
'example' : ['bond-miimon 0']},
|
|
|
|
'bond-mode' :
|
|
|
|
{'help' : 'bond mode',
|
|
|
|
'validvals' : ['balance-rr', 'active-backup',
|
|
|
|
'balance-xor', 'broadcast', '802.3ad',
|
|
|
|
'balance-tlb', 'balance-alb'],
|
|
|
|
'default' : 'balance-rr',
|
|
|
|
'example' : ['bond-mode 802.3ad']},
|
|
|
|
'bond-lacp-rate':
|
2014-10-28 16:10:00 -07:00
|
|
|
{'help' : 'bond lacp rate',
|
2014-10-09 16:02:46 -07:00
|
|
|
'validvals' : ['0', '1'],
|
|
|
|
'default' : '0',
|
|
|
|
'example' : ['bond-lacp-rate 0']},
|
|
|
|
'bond-min-links':
|
|
|
|
{'help' : 'bond min links',
|
|
|
|
'default' : '0',
|
|
|
|
'example' : ['bond-min-links 0']},
|
|
|
|
'bond-ad-sys-priority':
|
|
|
|
{'help' : '802.3ad system priority',
|
|
|
|
'default' : '65535',
|
2016-03-03 16:39:59 -08:00
|
|
|
'example' : ['bond-ad-sys-priority 65535'],
|
|
|
|
'deprecated' : True,
|
|
|
|
'new-attribute' : 'bond-ad-actor-sys-prio'},
|
|
|
|
'bond-ad-actor-sys-prio':
|
|
|
|
{'help' : '802.3ad system priority',
|
|
|
|
'default' : '65535',
|
|
|
|
'example' : ['bond-ad-actor-sys-prio 65535']},
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-ad-sys-mac-addr':
|
|
|
|
{'help' : '802.3ad system mac address',
|
|
|
|
'default' : '00:00:00:00:00:00',
|
2016-03-03 16:39:59 -08:00
|
|
|
'example' : ['bond-ad-sys-mac-addr 00:00:00:00:00:00'],
|
|
|
|
'deprecated' : True,
|
|
|
|
'new-attribute' : 'bond-ad-actor-system'},
|
|
|
|
'bond-ad-actor-system':
|
|
|
|
{'help' : '802.3ad system mac address',
|
|
|
|
'default' : '00:00:00:00:00:00',
|
|
|
|
'example' : ['bond-ad-actor-system 00:00:00:00:00:00'],},
|
2016-02-26 07:29:45 -08:00
|
|
|
'bond-lacp-bypass-allow':
|
|
|
|
{'help' : 'allow lacp bypass',
|
2014-10-09 16:02:46 -07:00
|
|
|
'validvals' : ['0', '1'],
|
|
|
|
'default' : '0',
|
2016-02-26 07:29:45 -08:00
|
|
|
'example' : ['bond-lacp-bypass-allow 0']},
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-slaves' :
|
|
|
|
{'help' : 'bond slaves',
|
|
|
|
'required' : True,
|
|
|
|
'example' : ['bond-slaves swp1 swp2',
|
|
|
|
'bond-slaves glob swp1-2',
|
2014-12-29 11:48:45 -08:00
|
|
|
'bond-slaves regex (swp[1|2)']}}}
|
2014-10-09 16:02:46 -07:00
|
|
|
|
|
|
|
def __init__(self, *args, **kargs):
|
|
|
|
ifupdownaddons.modulebase.moduleBase.__init__(self, *args, **kargs)
|
|
|
|
self.ipcmd = None
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd = None
|
2014-10-09 16:02:46 -07:00
|
|
|
|
|
|
|
def _is_bond(self, ifaceobj):
|
|
|
|
if ifaceobj.get_attr_value_first('bond-slaves'):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_dependent_ifacenames(self, ifaceobj, ifacenames_all=None):
|
|
|
|
""" Returns list of interfaces dependent on ifaceobj """
|
|
|
|
|
|
|
|
if not self._is_bond(ifaceobj):
|
|
|
|
return None
|
2015-11-15 21:27:07 -08:00
|
|
|
slave_list = self.parse_port_list(ifaceobj.name,
|
|
|
|
ifaceobj.get_attr_value_first(
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-slaves'), ifacenames_all)
|
2015-04-03 21:24:25 -07:00
|
|
|
ifaceobj.dependency_type = ifaceDependencyType.MASTER_SLAVE
|
2014-10-09 16:02:46 -07:00
|
|
|
# Also save a copy for future use
|
|
|
|
ifaceobj.priv_data = list(slave_list)
|
2015-02-18 08:03:07 -08:00
|
|
|
if ifaceobj.link_type != ifaceLinkType.LINK_NA:
|
2014-12-17 12:39:38 -08:00
|
|
|
ifaceobj.link_type = ifaceLinkType.LINK_MASTER
|
2015-06-02 20:35:08 -04:00
|
|
|
ifaceobj.link_kind |= ifaceLinkKind.BOND
|
|
|
|
ifaceobj.role |= ifaceRole.MASTER
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
return slave_list
|
|
|
|
|
|
|
|
def get_dependent_ifacenames_running(self, ifaceobj):
|
|
|
|
self._init_command_handlers()
|
2015-07-22 18:38:07 -04:00
|
|
|
return self.bondcmd.get_slaves(ifaceobj.name)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
|
|
|
def _get_slave_list(self, ifaceobj):
|
|
|
|
""" Returns slave list present in ifaceobj config """
|
|
|
|
|
|
|
|
# If priv data already has slave list use that first.
|
|
|
|
if ifaceobj.priv_data:
|
|
|
|
return ifaceobj.priv_data
|
|
|
|
slaves = ifaceobj.get_attr_value_first('bond-slaves')
|
|
|
|
if slaves:
|
2015-11-15 21:27:07 -08:00
|
|
|
return self.parse_port_list(ifaceobj.name, slaves)
|
2014-10-09 16:02:46 -07:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2016-02-10 10:46:11 -08:00
|
|
|
def _is_clag_bond(self, ifaceobj):
|
|
|
|
if ifaceobj.get_attr_value_first('bond-slaves'):
|
|
|
|
attrval = ifaceobj.get_attr_value_first('clag-id')
|
|
|
|
if attrval and attrval != '0':
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
def fetch_attr(self, ifaceobj, attrname):
|
|
|
|
attrval = ifaceobj.get_attr_value_first(attrname)
|
2015-07-22 18:38:07 -04:00
|
|
|
# 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)
|
2014-10-09 16:02:46 -07:00
|
|
|
if attrval:
|
|
|
|
msg = ('%s: invalid value %s for attr %s.'
|
|
|
|
%(ifaceobj.name, attrval, attrname))
|
|
|
|
optiondict = self.get_mod_attr(attrname)
|
|
|
|
if not optiondict:
|
|
|
|
return None
|
|
|
|
validvals = optiondict.get('validvals')
|
|
|
|
if validvals and attrval not in validvals:
|
|
|
|
raise Exception(msg + ' Valid values are %s' %str(validvals))
|
|
|
|
validrange = optiondict.get('validrange')
|
|
|
|
if validrange:
|
|
|
|
if (int(attrval) < int(validrange[0]) or
|
|
|
|
int(attrval) > int(validrange[1])):
|
|
|
|
raise Exception(msg + ' Valid range is [%s,%s]'
|
|
|
|
%(validrange[0], validrange[1]))
|
2015-01-02 18:20:15 -08:00
|
|
|
if attrname == 'bond-mode' and attrval == '802.3ad':
|
|
|
|
dattrname = 'bond-min-links'
|
|
|
|
min_links = ifaceobj.get_attr_value_first(dattrname)
|
ifupdown2: Allow lacp parameters to be set on 802.3ad bonds
Ticket: CM-10437
Reviewed By: CCR-4480
Testing Done: Created a bond and made sure it's lacp_rate could be set fast or
slow wioth or without specifying the mode.
The current code assumes that for a bond to be in 802.3ad mode the "bond-mode"
parameter has to be specified in the list of bond attributes being set. Only
then will ifupdown2 allow the lacp_rate and lacp_bypass attributes to be set.
But since we have changed the default mode to be 802.3ad, the mode attribute no
longer needs to be specified for a bond to be in 802.3ad mode.
So, instead of doing a check for the configuration attributes to determine the
mode, the linkinfo cache is checked. And the cache is refreshed, just in case
the mode attribute has been specified and just previously been set. The order in
which the attributes are set is fixed for bonds, and the mode is always set
prior to the lacp_rate and lacp_bypass attributes.
Also, while testing this I noticed another assumption about the default value of
an attribute: min_links. A warning is displayed when min_links is not specified
or set to 0, and the mode is set to 802.3ad. Well, now that the default for
min_links is 1 it doesn't have to be specified, even if the mode is set to
802.3ad. So ifupdown2 checks the current state of min_links if it is not
specified as one of the attibutes. If it is 0, either by being specified as an
attribute or not being specified but having that value, and the mode is set to
802.3ad, a warning is displayed.
And there was this other little problem where if a bond already existed in the
linkcache it wouldn't be refreshed, even if the refresh=True parameter was
specified in the _bond_linkinfo_fill function.
2016-04-14 16:03:06 -07:00
|
|
|
if not min_links:
|
|
|
|
min_links = self.bondcmd.get_min_links(ifaceobj.name)
|
|
|
|
if min_links == '0':
|
|
|
|
self.logger.warn('%s: attribute %s'
|
2015-01-02 18:20:15 -08:00
|
|
|
%(ifaceobj.name, dattrname) +
|
ifupdown2: Allow lacp parameters to be set on 802.3ad bonds
Ticket: CM-10437
Reviewed By: CCR-4480
Testing Done: Created a bond and made sure it's lacp_rate could be set fast or
slow wioth or without specifying the mode.
The current code assumes that for a bond to be in 802.3ad mode the "bond-mode"
parameter has to be specified in the list of bond attributes being set. Only
then will ifupdown2 allow the lacp_rate and lacp_bypass attributes to be set.
But since we have changed the default mode to be 802.3ad, the mode attribute no
longer needs to be specified for a bond to be in 802.3ad mode.
So, instead of doing a check for the configuration attributes to determine the
mode, the linkinfo cache is checked. And the cache is refreshed, just in case
the mode attribute has been specified and just previously been set. The order in
which the attributes are set is fixed for bonds, and the mode is always set
prior to the lacp_rate and lacp_bypass attributes.
Also, while testing this I noticed another assumption about the default value of
an attribute: min_links. A warning is displayed when min_links is not specified
or set to 0, and the mode is set to 802.3ad. Well, now that the default for
min_links is 1 it doesn't have to be specified, even if the mode is set to
802.3ad. So ifupdown2 checks the current state of min_links if it is not
specified as one of the attibutes. If it is 0, either by being specified as an
attribute or not being specified but having that value, and the mode is set to
802.3ad, a warning is displayed.
And there was this other little problem where if a bond already existed in the
linkcache it wouldn't be refreshed, even if the refresh=True parameter was
specified in the _bond_linkinfo_fill function.
2016-04-14 16:03:06 -07:00
|
|
|
' is set to \'0\'')
|
2015-07-22 18:38:07 -04:00
|
|
|
elif policy_default_val:
|
|
|
|
return policy_default_val
|
2014-10-09 16:02:46 -07:00
|
|
|
return attrval
|
|
|
|
|
|
|
|
def _apply_master_settings(self, ifaceobj):
|
|
|
|
have_attrs_to_set = 0
|
2014-12-08 22:59:41 -08:00
|
|
|
linkup = False
|
2015-07-22 18:38:07 -04:00
|
|
|
bondcmd_attrmap = OrderedDict([('bond-mode' , 'mode'),
|
2014-10-09 16:02:46 -07:00
|
|
|
('bond-miimon' , 'miimon'),
|
|
|
|
('bond-use-carrier', 'use_carrier'),
|
|
|
|
('bond-lacp-rate' , 'lacp_rate'),
|
|
|
|
('bond-xmit-hash-policy' , 'xmit_hash_policy'),
|
|
|
|
('bond-min-links' , 'min_links'),
|
|
|
|
('bond-num-grat-arp' , 'num_grat_arp'),
|
|
|
|
('bond-num-unsol-na' , 'num_unsol_na'),
|
2016-03-03 16:39:59 -08:00
|
|
|
('bond-ad-sys-mac-addr' , 'ad_actor_system'),
|
|
|
|
('bond-ad-actor-system' , 'ad_actor_system'),
|
|
|
|
('bond-ad-sys-priority' , 'ad_actor_sys_prio'),
|
|
|
|
('bond-ad-actor-sys-prio' , 'ad_actor_sys_prio'),
|
2016-02-26 07:29:45 -08:00
|
|
|
('bond-lacp-bypass-allow', 'lacp_bypass')])
|
2014-12-08 22:59:41 -08:00
|
|
|
linkup = self.ipcmd.is_link_up(ifaceobj.name)
|
2014-10-09 16:02:46 -07:00
|
|
|
try:
|
|
|
|
# order of attributes set matters for bond, so
|
|
|
|
# construct the list sequentially
|
|
|
|
attrstoset = OrderedDict()
|
2015-07-22 18:38:07 -04:00
|
|
|
for k, dstk in bondcmd_attrmap.items():
|
2014-10-09 16:02:46 -07:00
|
|
|
v = self.fetch_attr(ifaceobj, k)
|
|
|
|
if v:
|
|
|
|
attrstoset[dstk] = v
|
|
|
|
if not attrstoset:
|
|
|
|
return
|
|
|
|
have_attrs_to_set = 1
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.set_attrs(ifaceobj.name, attrstoset,
|
2014-12-08 22:59:41 -08:00
|
|
|
self.ipcmd.link_down if linkup else None)
|
2014-10-09 16:02:46 -07:00
|
|
|
except:
|
|
|
|
raise
|
|
|
|
finally:
|
2014-12-08 22:59:41 -08:00
|
|
|
if have_attrs_to_set and linkup:
|
2014-10-09 16:02:46 -07:00
|
|
|
self.ipcmd.link_up(ifaceobj.name)
|
|
|
|
|
|
|
|
def _add_slaves(self, ifaceobj):
|
|
|
|
runningslaves = []
|
|
|
|
|
|
|
|
slaves = self._get_slave_list(ifaceobj)
|
|
|
|
if not slaves:
|
|
|
|
self.logger.debug('%s: no slaves found' %ifaceobj.name)
|
|
|
|
return
|
|
|
|
|
2016-04-14 14:45:47 -07:00
|
|
|
if not ifupdownflags.flags.PERFMODE:
|
2015-07-22 18:38:07 -04:00
|
|
|
runningslaves = self.bondcmd.get_slaves(ifaceobj.name);
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2016-02-10 10:46:11 -08:00
|
|
|
clag_bond = self._is_clag_bond(ifaceobj)
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
for slave in Set(slaves).difference(Set(runningslaves)):
|
2016-04-14 14:45:47 -07:00
|
|
|
if (not ifupdownflags.flags.PERFMODE and
|
|
|
|
not self.ipcmd.link_exists(slave)):
|
2016-05-15 13:28:10 -07:00
|
|
|
self.log_error('%s: skipping slave %s, does not exist'
|
|
|
|
%(ifaceobj.name, slave), ifaceobj,
|
|
|
|
raise_error=False)
|
2015-02-10 11:17:00 -08:00
|
|
|
continue
|
2014-12-17 12:39:38 -08:00
|
|
|
link_up = False
|
2014-12-08 22:59:41 -08:00
|
|
|
if self.ipcmd.is_link_up(slave):
|
|
|
|
rtnetlink_api.rtnl_api.link_set(slave, "down")
|
2014-12-17 12:39:38 -08:00
|
|
|
link_up = True
|
2016-02-10 10:46:11 -08:00
|
|
|
# If clag bond place the slave in a protodown state; clagd
|
|
|
|
# will protoup it when it is ready
|
|
|
|
if clag_bond:
|
2016-03-10 02:04:48 +01:00
|
|
|
try:
|
|
|
|
rtnetlink_api.rtnl_api.link_set_protodown(slave, "on")
|
|
|
|
except Exception, e:
|
|
|
|
self.logger.error('%s: %s: clag bond, switching slave protodown state on: %s'
|
|
|
|
%(ifaceobj.name, slave, str(e)))
|
2014-12-08 17:15:57 -08:00
|
|
|
self.ipcmd.link_set(slave, 'master', ifaceobj.name)
|
2015-02-18 08:03:07 -08:00
|
|
|
if link_up or ifaceobj.link_type != ifaceLinkType.LINK_NA:
|
2015-02-25 13:45:37 -08:00
|
|
|
try:
|
|
|
|
rtnetlink_api.rtnl_api.link_set(slave, "up")
|
|
|
|
except Exception, e:
|
|
|
|
self.logger.debug('%s: %s: link set up (%s)'
|
|
|
|
%(ifaceobj.name, slave, str(e)))
|
|
|
|
pass
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2015-05-14 23:00:57 -07:00
|
|
|
if runningslaves:
|
2016-02-10 10:46:11 -08:00
|
|
|
for s in runningslaves:
|
|
|
|
if s not in slaves:
|
|
|
|
self.bondcmd.remove_slave(ifaceobj.name, s)
|
|
|
|
if clag_bond:
|
2016-03-10 02:04:48 +01:00
|
|
|
try:
|
|
|
|
rtnetlink_api.rtnl_api.link_set_protodown(s, "off")
|
|
|
|
except Exception, e:
|
|
|
|
self.logger.error('%s: %s: clag bond, switching slave protodown state off: %s'
|
|
|
|
%(ifaceobj.name, s, str(e)))
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
def _up(self, ifaceobj):
|
|
|
|
try:
|
|
|
|
if not self.ipcmd.link_exists(ifaceobj.name):
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.create_bond(ifaceobj.name)
|
2014-10-09 16:02:46 -07:00
|
|
|
self._apply_master_settings(ifaceobj)
|
|
|
|
self._add_slaves(ifaceobj)
|
2014-11-12 10:51:07 -08:00
|
|
|
if ifaceobj.addr_method == 'manual':
|
|
|
|
rtnetlink_api.rtnl_api.link_set(ifaceobj.name, "up")
|
2014-10-09 16:02:46 -07:00
|
|
|
except Exception, e:
|
2016-05-15 13:28:10 -07:00
|
|
|
self.log_error(str(e), ifaceobj)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
|
|
|
def _down(self, ifaceobj):
|
|
|
|
try:
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.delete_bond(ifaceobj.name)
|
2014-10-09 16:02:46 -07:00
|
|
|
except Exception, e:
|
|
|
|
self.log_warn(str(e))
|
|
|
|
|
|
|
|
def _query_check(self, ifaceobj, ifaceobjcurr):
|
|
|
|
slaves = None
|
|
|
|
|
2015-07-22 18:38:07 -04:00
|
|
|
if not self.bondcmd.bond_exists(ifaceobj.name):
|
2014-10-09 16:02:46 -07:00
|
|
|
self.logger.debug('bond iface %s' %ifaceobj.name +
|
|
|
|
' does not exist')
|
|
|
|
return
|
|
|
|
|
|
|
|
ifaceattrs = self.dict_key_subset(ifaceobj.config,
|
|
|
|
self.get_mod_attrs())
|
|
|
|
if not ifaceattrs: return
|
|
|
|
runningattrs = self._query_running_attrs(ifaceobj.name)
|
2014-12-12 22:56:29 -08:00
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
for k in ifaceattrs:
|
|
|
|
v = ifaceobj.get_attr_value_first(k)
|
|
|
|
if not v:
|
|
|
|
continue
|
|
|
|
if k == 'bond-slaves':
|
2014-10-28 16:10:00 -07:00
|
|
|
slaves = self._get_slave_list(ifaceobj)
|
2014-10-09 16:02:46 -07:00
|
|
|
continue
|
|
|
|
rv = runningattrs.get(k)
|
|
|
|
if not rv:
|
|
|
|
ifaceobjcurr.update_config_with_status(k, 'None', 1)
|
|
|
|
else:
|
|
|
|
ifaceobjcurr.update_config_with_status(k, rv,
|
|
|
|
1 if v != rv else 0)
|
|
|
|
runningslaves = runningattrs.get('bond-slaves')
|
|
|
|
if not slaves and not runningslaves:
|
|
|
|
return
|
|
|
|
retslave = 1
|
|
|
|
if slaves and runningslaves:
|
|
|
|
if slaves and runningslaves:
|
|
|
|
difference = set(slaves).symmetric_difference(runningslaves)
|
|
|
|
if not difference:
|
|
|
|
retslave = 0
|
|
|
|
ifaceobjcurr.update_config_with_status('bond-slaves',
|
|
|
|
' '.join(runningslaves)
|
|
|
|
if runningslaves else 'None', retslave)
|
|
|
|
|
|
|
|
def _query_running_attrs(self, bondname):
|
|
|
|
bondattrs = {'bond-mode' :
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.get_mode(bondname),
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-miimon' :
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.get_miimon(bondname),
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-use-carrier' :
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.get_use_carrier(bondname),
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-lacp-rate' :
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.get_lacp_rate(bondname),
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-min-links' :
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.get_min_links(bondname),
|
2016-03-03 16:39:59 -08:00
|
|
|
'bond-ad-actor-system' :
|
|
|
|
self.bondcmd.get_ad_actor_system(bondname),
|
|
|
|
'bond-ad-actor-sys-prio' :
|
|
|
|
self.bondcmd.get_ad_actor_sys_prio(bondname),
|
2014-10-09 16:02:46 -07:00
|
|
|
'bond-xmit-hash-policy' :
|
2015-07-22 18:38:07 -04:00
|
|
|
self.bondcmd.get_xmit_hash_policy(bondname),
|
2014-12-12 22:56:29 -08:00
|
|
|
'bond-lacp-bypass-allow' :
|
2016-03-03 16:39:59 -08:00
|
|
|
self.bondcmd.get_lacp_bypass_allow(bondname),
|
|
|
|
'bond-num-unsol-na' :
|
|
|
|
self.bondcmd.get_num_unsol_na(bondname),
|
|
|
|
'bond-num-grat-arp' :
|
|
|
|
self.bondcmd.get_num_grat_arp(bondname)}
|
2015-07-22 18:38:07 -04:00
|
|
|
slaves = self.bondcmd.get_slaves(bondname)
|
2014-10-09 16:02:46 -07:00
|
|
|
if slaves:
|
|
|
|
bondattrs['bond-slaves'] = slaves
|
|
|
|
return bondattrs
|
|
|
|
|
|
|
|
def _query_running(self, ifaceobjrunning):
|
2015-07-22 18:38:07 -04:00
|
|
|
if not self.bondcmd.bond_exists(ifaceobjrunning.name):
|
2014-10-09 16:02:46 -07:00
|
|
|
return
|
|
|
|
bondattrs = self._query_running_attrs(ifaceobjrunning.name)
|
|
|
|
if bondattrs.get('bond-slaves'):
|
|
|
|
bondattrs['bond-slaves'] = ' '.join(bondattrs.get('bond-slaves'))
|
|
|
|
[ifaceobjrunning.update_config(k, v)
|
|
|
|
for k, v in bondattrs.items()
|
|
|
|
if v and v != self.get_mod_subattr(k, 'default')]
|
|
|
|
|
|
|
|
_run_ops = {'pre-up' : _up,
|
|
|
|
'post-down' : _down,
|
|
|
|
'query-running' : _query_running,
|
|
|
|
'query-checkcurr' : _query_check}
|
|
|
|
|
|
|
|
def get_ops(self):
|
|
|
|
""" returns list of ops supported by this module """
|
|
|
|
return self._run_ops.keys()
|
|
|
|
|
|
|
|
def _init_command_handlers(self):
|
|
|
|
if not self.ipcmd:
|
2016-04-14 14:45:47 -07:00
|
|
|
self.ipcmd = iproute2()
|
2015-07-22 18:38:07 -04:00
|
|
|
if not self.bondcmd:
|
2016-04-14 14:45:47 -07:00
|
|
|
self.bondcmd = bondutil()
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2014-10-24 10:11:07 -07:00
|
|
|
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
2014-10-09 16:02:46 -07:00
|
|
|
""" run bond configuration on the interface object passed as argument
|
|
|
|
|
|
|
|
Args:
|
|
|
|
**ifaceobj** (object): iface object
|
|
|
|
|
|
|
|
**operation** (str): any of 'pre-up', 'post-down', 'query-checkcurr',
|
|
|
|
'query-running'
|
|
|
|
|
|
|
|
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
|
|
|
|
if operation != 'query-running' and not self._is_bond(ifaceobj):
|
|
|
|
return
|
|
|
|
self._init_command_handlers()
|
|
|
|
if operation == 'query-checkcurr':
|
|
|
|
op_handler(self, ifaceobj, query_ifaceobj)
|
|
|
|
else:
|
|
|
|
op_handler(self, ifaceobj)
|