Skip to content

Commit

Permalink
Merge pull request #9 from ypconfig/fix-bond-mode
Browse files Browse the repository at this point in the history
Fix bond mode
  • Loading branch information
job committed May 31, 2018
2 parents 3772297 + 183ad1e commit e95e3d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions ypconfig/config.py
Expand Up @@ -207,11 +207,11 @@ def Interface(iface, iname):

if ret['type'] == 'bond':
try:
ret['bond_mode'] = BondMode(iface['bond-mode'])
ret['bond-mode'] = BondMode(iface['bond-mode'])
except ValueError as e:
raise e
except KeyError:
ret['bond_mode'] = 0
ret['bond-mode'] = 0

try:
if iface['miimon']:
Expand All @@ -221,7 +221,7 @@ def Interface(iface, iname):
except KeyError:
ret['miimon'] = 100

if ret['bond_mode'] == '802.3ad':
if ret['bond-mode'] == '802.3ad':
try:
ret['lacp_rate'] = LacpRate(iface['lacp_rate'])
except ValueError as e:
Expand Down
24 changes: 16 additions & 8 deletions ypconfig/netlink.py
Expand Up @@ -70,7 +70,7 @@ def GetNow():
bonddata = linfo.get_attr('IFLA_INFO_DATA')
this['type'] = 'bond'
this['miimon'] = bonddata.get_attr('IFLA_BOND_MIIMON')
this['bond_mode'] = bonddata.get_attr('IFLA_BOND_MODE')
this['bond-mode'] = bonddata.get_attr('IFLA_BOND_MODE')
ret[this['name']] = this
except Exception as e:
print(e)
Expand All @@ -96,12 +96,20 @@ def Commit(cur, new):
Delif(iface)

# These interfaces need to be created
toadd = list()
for iface in newif.difference(curif):
changed = True
if new[iface]['type'] == 'vlan':
Addvlan(new[iface])
elif new[iface]['type'] == 'bond':
if new[iface]['type'] == 'bond':
toadd.insert(0, iface)
elif new[iface]['type'] == 'vlan':
toadd.append(iface)

for iface in toadd:
changed = True
if new[iface]['type'] == 'bond':
Addbond(new[iface])
elif new[iface]['type'] == 'vlan':
Addvlan(new[iface])

# Processes changes in remaining interfaces
for iface in newif.intersection(curif):
Expand Down Expand Up @@ -158,7 +166,7 @@ def Commit(cur, new):
for slave in set(n[v]).difference(set(c[v])):
Addslave(iface, slave)
for slave in set(c[v]).difference(set(n[v])):
Removeslave(iface, slave)
Delslave(iface, slave)
elif v in ['vlanid', 'parent']:
Delif(iface)
Addvlan(new[iface])
Expand Down Expand Up @@ -211,7 +219,7 @@ def Addbond(vals):
print("Creating bond interface %s with %s" % (vals['name'], str(vals)))
global ip
iface = vals['name']
i = ip.create(kind='bond', ifname=iface, bond_mode=vals['bond_mode'], bond_miimon=vals['miimon'], reuse=True)
i = ip.create(kind='bond', ifname=iface, bond_mode=vals['bond-mode'], bond_miimon=vals['miimon'], reuse=True)
for child in vals['slaves']:
Ifmtu(child, vals['mtu'])
Addslave(iface, child)
Expand All @@ -231,6 +239,7 @@ def Addbond(vals):
def Addslave(iface, slave):
print("Adding interface %s as slave on %s" % (slave, iface))
global ip
Ifstate(slave, 'DOWN')
i = ip.interfaces[iface]
i.add_port(ip.interfaces[slave])
ip.commit()
Expand All @@ -239,7 +248,7 @@ def Delslave(iface, slave):
print("Removing interface %s as slave from %s" % (slave, iface))
global ip
i = ip.interfaces[iface]
i.del_port(ip.interfaces[slave])
i.del_port(slave)
ip.commit()

def Deladdr(iface, addr):
Expand All @@ -259,7 +268,6 @@ def Addaddr(iface, addr):
def Ifstate(iface, state):
print("Setting state of interface %s to %s" % (iface, state))
global ip
from pprint import pprint
i = ip.interfaces[iface]
if i['kind'] == 'vlan':
p = ip.interfaces[i['link']]
Expand Down

0 comments on commit e95e3d3

Please sign in to comment.