mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
addons: bond: add support for attribute aliases (bond-ports)
This features will allow attributes to have aliases. Our use case today is between bond-slaves and bridge-ports, which be a little confusing. It follows the kernel api and existing linux tools. Bonding driver calls them slaves and to the bridge driver they are ports. With NCLU we we would like to be more consistent. We will now also support "bond-ports"a Ticket: CM-12763 Reviewed By: Roopa Testing Done: $ ifquery -a -c auto bond0 iface bond0 [pass] bond-slaves swp1 [pass] auto bond1 iface bond1 [pass] bond-ports swp2 [pass] root@cel-redxp-06:~# ifquery -a -r auto bond0 iface bond0 bond-lacp-bypass-allow 0 bond-slaves swp1 bond-mode 802.3ad bond-use-carrier 1 bond-lacp-rate 1 bond-min-links 1 bond-miimon 100 bond-xmit-hash-policy layer3+4 auto bond1 iface bond1 bond-lacp-bypass-allow 0 bond-slaves swp2 bond-mode 802.3ad bond-use-carrier 1 bond-lacp-rate 1 bond-min-links 1 bond-miimon 100 bond-xmit-hash-policy layer3+4 Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
This commit is contained in:
@ -104,7 +104,8 @@ class bond(moduleBase):
|
||||
'validvals': ['<interface-list>'],
|
||||
'example' : ['bond-slaves swp1 swp2',
|
||||
'bond-slaves glob swp1-2',
|
||||
'bond-slaves regex (swp[1|2)']}}}
|
||||
'bond-slaves regex (swp[1|2)'],
|
||||
'aliases': ['bond-ports']}}}
|
||||
|
||||
_bond_mode_num = {'0': 'balance-rr',
|
||||
'1': 'active-backup',
|
||||
@ -139,8 +140,14 @@ class bond(moduleBase):
|
||||
self.ipcmd = None
|
||||
self.bondcmd = None
|
||||
|
||||
def get_bond_slaves(self, ifaceobj):
|
||||
slaves = ifaceobj.get_attr_value_first('bond-slaves')
|
||||
if not slaves:
|
||||
slaves = ifaceobj.get_attr_value_first('bond-ports')
|
||||
return slaves
|
||||
|
||||
def _is_bond(self, ifaceobj):
|
||||
if ifaceobj.get_attr_value_first('bond-slaves'):
|
||||
if self.get_bond_slaves(ifaceobj):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -150,8 +157,8 @@ class bond(moduleBase):
|
||||
if not self._is_bond(ifaceobj):
|
||||
return None
|
||||
slave_list = self.parse_port_list(ifaceobj.name,
|
||||
ifaceobj.get_attr_value_first(
|
||||
'bond-slaves'), ifacenames_all)
|
||||
self.get_bond_slaves(ifaceobj),
|
||||
ifacenames_all)
|
||||
ifaceobj.dependency_type = ifaceDependencyType.MASTER_SLAVE
|
||||
# Also save a copy for future use
|
||||
ifaceobj.priv_data = list(slave_list)
|
||||
@ -172,14 +179,14 @@ class bond(moduleBase):
|
||||
# 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')
|
||||
slaves = self.get_bond_slaves(ifaceobj)
|
||||
if slaves:
|
||||
return self.parse_port_list(ifaceobj.name, slaves)
|
||||
else:
|
||||
return None
|
||||
|
||||
def _is_clag_bond(self, ifaceobj):
|
||||
if ifaceobj.get_attr_value_first('bond-slaves'):
|
||||
if self.get_bond_slaves(ifaceobj):
|
||||
attrval = ifaceobj.get_attr_value_first('clag-id')
|
||||
if attrval and attrval != '0':
|
||||
return True
|
||||
@ -337,6 +344,7 @@ class bond(moduleBase):
|
||||
if 'bond-mode' in runningattrs:
|
||||
runningattrs['bond-mode'] = bond._get_num_bond_mode(runningattrs['bond-mode'])
|
||||
|
||||
bond_slaves = True
|
||||
for k in ifaceattrs:
|
||||
v = ifaceobj.get_attr_value_first(k)
|
||||
if not v:
|
||||
@ -344,6 +352,10 @@ class bond(moduleBase):
|
||||
if k == 'bond-slaves':
|
||||
slaves = self._get_slave_list(ifaceobj)
|
||||
continue
|
||||
elif k == 'bond-ports':
|
||||
bond_slaves = False
|
||||
slaves = self._get_slave_list(ifaceobj)
|
||||
continue
|
||||
rv = runningattrs.get(k)
|
||||
if not rv:
|
||||
ifaceobjcurr.update_config_with_status(k, 'None', 1)
|
||||
@ -370,7 +382,7 @@ class bond(moduleBase):
|
||||
if slaves[i] in runningslaves:
|
||||
ordered.append(slaves[i])
|
||||
slaves = ordered
|
||||
ifaceobjcurr.update_config_with_status('bond-slaves',
|
||||
ifaceobjcurr.update_config_with_status('bond-slaves' if bond_slaves else 'bond-ports',
|
||||
' '.join(slaves)
|
||||
if slaves else 'None', retslave)
|
||||
|
||||
|
@ -1134,6 +1134,11 @@ class ifupdownMain(ifupdownBase):
|
||||
self.logger.warn('attribute %s is deprecated.'
|
||||
%attrname)
|
||||
return True
|
||||
else:
|
||||
for key in attrsdict:
|
||||
if 'aliases' in attrsdict[key]:
|
||||
if attrname in attrsdict[key]['aliases']:
|
||||
return True
|
||||
except AttributeError:
|
||||
pass
|
||||
return False
|
||||
|
@ -311,6 +311,8 @@ class moduleBase(object):
|
||||
if not attrvals or attrvals.get('deprecated'):
|
||||
continue
|
||||
retattrs.append(attrname)
|
||||
if 'aliases' in attrvals:
|
||||
retattrs.extend(attrvals['aliases'])
|
||||
return retattrs
|
||||
except:
|
||||
return None
|
||||
|
Reference in New Issue
Block a user