Skip to content

Commit

Permalink
Merge pull request #261 from vilnitsky/lacp_force_up
Browse files Browse the repository at this point in the history
support lacp force up in juniper switches
  • Loading branch information
fbouliane authored May 25, 2022
2 parents 8e48641 + 76d0e6f commit a886479
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 13 deletions.
8 changes: 8 additions & 0 deletions netman/adapters/switches/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ def unset_interface_auto_negotiation_state(self, interface_id):
self.real_switch.unset_interface_auto_negotiation_state(interface_id)
self.interfaces_cache[interface_id].auto_negotiation = None

def set_interface_lacp_force_up(self, interface_id):
self.real_switch.set_interface_lacp_force_up(interface_id)
self.interfaces_cache[interface_id].force_up = True

def unset_interface_lacp_force_up(self, interface_id):
self.real_switch.unset_interface_lacp_force_up(interface_id)
self.interfaces_cache[interface_id].force_up = None

def add_bond(self, number):
self.real_switch.add_bond(number)
self.bonds_cache.refresh_items.add(number)
Expand Down
42 changes: 42 additions & 0 deletions netman/adapters/switches/juniper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,46 @@ def unset_interface_auto_negotiation_state(self, interface_id):

self._push_interface_update(interface_id, update)

def set_interface_lacp_force_up(self, interface_id):
content = to_ele("""
<interface>
<name>{0}</name>
</interface>
""".format(interface_id))
content.append(to_ele("""
<ether-options>
<ieee-802.3ad>
<lacp>
<force-up/>
</lacp>
</ieee-802.3ad>
</ether-options>
"""))
update = Update()
update.add_interface(content)

self._push_interface_update(interface_id, update)

def unset_interface_lacp_force_up(self, interface_id):
content = to_ele("""
<interface>
<name>{0}</name>
</interface>
""".format(interface_id))
content.append(
to_ele("""
<ether-options>
<ieee-802.3ad>
<lacp operation=\"delete\"></lacp>
</ieee-802.3ad>
</ether-options>
""")
)
update = Update()
update.add_interface(content)

self._push_interface_update(interface_id, update)

def reset_interface(self, interface_id):
content = to_ele("""
<interface operation=\"delete\">
Expand Down Expand Up @@ -738,6 +778,8 @@ def fill_interface_from_node(self, interface, interface_node, config):
interface.auto_negotiation = True
elif first(interface_node.xpath('ether-options/no-auto-negotiation')) is not None:
interface.auto_negotiation = False
if first(interface_node.xpath('ether-options/ieee-802.3ad/lacp/force-up')) is not None:
interface.force_up = True
return interface

def node_to_interface(self, interface_node, config):
Expand Down
6 changes: 6 additions & 0 deletions netman/adapters/switches/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ def set_interface_auto_negotiation_state(self, interface_id, state):
def unset_interface_auto_negotiation_state(self, interface_id):
self.delete("/interfaces/" + interface_id + '/auto-negotiation')

def set_interface_lacp_force_up(self, interface_id):
self.put("/interfaces/" + interface_id + '/lacp-force-up')

def unset_interface_lacp_force_up(self, interface_id):
self.delete("/interfaces/" + interface_id + '/lacp-force-up')

def add_bond(self, number):
self.post("/bonds", data={'number': number})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"trunk_native_vlan": null,
"trunk_vlans": [],
"auto_negotiation": null,
"mtu": 1500
"mtu": 1500,
"force_up": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"trunk_native_vlan": null,
"trunk_vlans": [],
"auto_negotiation": null,
"mtu": 1500
"mtu": 1500,
"force_up": null
}
},
{
Expand All @@ -35,7 +36,8 @@
3002
],
"auto_negotiation": null,
"mtu": null
"mtu": null,
"force_up": null
}
},
{
Expand All @@ -55,7 +57,8 @@
3002
],
"auto_negotiation": null,
"mtu": null
"mtu": null,
"force_up": null
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"trunk_native_vlan": 2999,
"trunk_vlans": [3000, 3001, 3002],
"auto_negotiation": null,
"mtu": 1500
}
"mtu": 1500,
"force_up": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"trunk_native_vlan": 2999,
"trunk_vlans": [3000, 3001, 3002],
"auto_negotiation": null,
"mtu": 1500
"mtu": 1500,
"force_up": null
},
{
"name": "FastEthernet0/3",
Expand All @@ -19,7 +20,8 @@
"trunk_native_vlan": null,
"trunk_vlans": [],
"auto_negotiation": null,
"mtu": null
"mtu": null,
"force_up": null
},
{
"name": "GigabitEthernet0/6",
Expand All @@ -30,7 +32,8 @@
"trunk_native_vlan": 2999,
"trunk_vlans": [3000, 3001, 3002],
"auto_negotiation": true,
"mtu": null
"mtu": null,
"force_up": null
},
{
"name": "GigabitEthernet0/8",
Expand All @@ -41,6 +44,7 @@
"trunk_native_vlan": null,
"trunk_vlans": [],
"auto_negotiation": false,
"mtu": null
"mtu": null,
"force_up": null
}
]
5 changes: 3 additions & 2 deletions netman/api/objects/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def to_api(self, interface):
base_interface.to_api(interface),
name=interface.name,
bond_master=interface.bond_master,
auto_negotiation=interface.auto_negotiation
auto_negotiation=interface.auto_negotiation,
force_up=interface.force_up
)

def to_core(self, serialized):
params = dict(vars(base_interface.to_core(serialized)))
params.update(sub_dict(serialized, 'name', 'bond_master', 'auto_negotiation'))
params.update(sub_dict(serialized, 'name', 'bond_master', 'auto_negotiation', 'force_up'))
return Interface(**params)


Expand Down
27 changes: 27 additions & 0 deletions netman/api/switch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def hook_to(self, server):
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/lldp', view_func=self.set_interface_lldp_state, methods=['PUT'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/auto-negotiation', view_func=self.set_interface_auto_negotiation_state, methods=['PUT'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/auto-negotiation', view_func=self.unset_interface_auto_negotiation_state, methods=['DELETE'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/lacp-force-up', view_func=self.set_interface_lacp_force_up, methods=['PUT'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/lacp-force-up', view_func=self.unset_interface_lacp_force_up, methods=['DELETE'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/mtu', view_func=self.set_interface_mtu, methods=['PUT'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/mtu', view_func=self.unset_interface_mtu, methods=['DELETE'])
server.add_url_rule('/switches/<hostname>/bonds', view_func=self.get_bonds, methods=['GET'])
Expand Down Expand Up @@ -500,6 +502,31 @@ def unset_interface_auto_negotiation_state(self, switch, interface_id):
switch.unset_interface_auto_negotiation_state(interface_id)
return 204, None

@to_response
@resource(Switch, Interface)
def set_interface_lacp_force_up(self, switch, interface_id):
"""
Sets lacp force_up state of an interface
:arg str hostname: Hostname or IP of the switch
:arg str interface_id: Interface name (ex. ``FastEthernet0/1``, ``ethernet1/11``)
"""
switch.set_interface_lacp_force_up(interface_id)
return 204, None

@to_response
@resource(Switch, Interface)
def unset_interface_lacp_force_up(self, switch, interface_id):
"""
Unsets lacp force_up state of an interface
:arg str hostname: Hostname or IP of the switch
:arg str interface_id: Interface name (ex. ``FastEthernet0/1``, ``ethernet1/11``)
"""

switch.unset_interface_lacp_force_up(interface_id)
return 204, None

@to_response
@content(is_int)
@resource(Switch, Interface)
Expand Down
3 changes: 2 additions & 1 deletion netman/core/objects/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def __init__(self, shutdown=None, port_mode=None, access_vlan=None,


class Interface(BaseInterface):
def __init__(self, name=None, bond_master=None, auto_negotiation=None, **interface):
def __init__(self, name=None, bond_master=None, auto_negotiation=None, force_up=None, **interface):
super(Interface, self).__init__(**interface)
self.name = name
self.bond_master = bond_master
self.auto_negotiation = auto_negotiation
self.force_up = force_up
8 changes: 8 additions & 0 deletions netman/core/objects/switch_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def set_interface_auto_negotiation_state(self, interface_id, negotiation_state):
def unset_interface_auto_negotiation_state(self, interface_id):
pass

@not_implemented
def set_interface_lacp_force_up(self, interface_id):
pass

@not_implemented
def unset_interface_lacp_force_up(self, interface_id):
pass

@not_implemented
def set_interface_native_vlan(self, interface_id, vlan):
pass
Expand Down
1 change: 1 addition & 0 deletions tests/adapters/switches/remote_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ def test_get_interface(self):
assert_that(interface.access_vlan, equal_to(None))
assert_that(interface.trunk_native_vlan, equal_to(2999))
assert_that(interface.trunk_vlans, equal_to([3000, 3001, 3002]))
assert_that(interface.force_up, equal_to(None))

def test_get_nonexistent_interface_raises(self):
self.requests_mock.should_receive("get").once().with_args(
Expand Down

0 comments on commit a886479

Please sign in to comment.