-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdot1x.py
More file actions
60 lines (51 loc) · 1.87 KB
/
Copy pathdot1x.py
File metadata and controls
60 lines (51 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
--------------------------------------------------------------------------------
------------------------- Mist API Python CLI Session --------------------------
Written by: Thomas Munzer (tmunzer@juniper.net)
Github : https://github.com/tmunzer/mistapi_python
This package is licensed under the MIT License.
--------------------------------------------------------------------------------
"""
from mistapi import APISession as _APISession
from mistapi.__logger import logger as LOGGER
from mistapi.api.v1.sites import devices
from mistapi.device_utils.__tools.__ws_wrapper import UtilResponse
def clear_sessions(
apissession: _APISession,
site_id: str,
device_id: str,
port_ids: list[str],
) -> UtilResponse:
"""
DEVICES: EX
Clears dot1x sessions on the specified ports of a switch (EX).
PARAMS
-----------
site_id : str
UUID of the site where the switch is located.
device_id : str
UUID of the switch to clear dot1x sessions on.
port_ids : list[str]
List of port IDs to clear dot1x sessions on.
RETURNS
-----------
UtilResponse
A UtilResponse object containing the API response and a list of raw messages received
from the WebSocket stream.
"""
body: dict[str, str | list | int] = {"ports": port_ids}
trigger = devices.clearAllLearnedMacsFromPortOnSwitch(
apissession,
site_id=site_id,
device_id=device_id,
body=body,
)
util_response = UtilResponse(trigger)
if trigger.status_code == 200:
LOGGER.info(trigger.data)
print(f"Clear learned MACs command triggered for device {device_id}")
else:
LOGGER.error(
f"Failed to trigger clear learned MACs command: {trigger.status_code} - {trigger.data}"
) # Give the clear learned MACs command a moment to take effect
return util_response