forked from meraki/dashboard-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_ports.py
More file actions
135 lines (107 loc) · 6.45 KB
/
Copy pathswitch_ports.py
File metadata and controls
135 lines (107 loc) · 6.45 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
class SwitchPorts(object):
def __init__(self, session):
super(SwitchPorts, self).__init__()
self._session = session
def getDeviceSwitchPortStatuses(self, serial: str, **kwargs):
"""
**Return the status for all the ports of a switch**
https://developer.cisco.com/meraki/api/#!get-device-switch-port-statuses
- serial (string)
- t0 (string): The beginning of the timespan for the data. The maximum lookback period is 31 days from today.
- timespan (number): The timespan for which the information will be fetched. If specifying timespan, do not specify parameter t0. The value must be in seconds and be less than or equal to 31 days. The default is 1 day.
"""
kwargs.update(locals())
metadata = {
'tags': ['Switch ports'],
'operation': 'getDeviceSwitchPortStatuses',
}
resource = f'/devices/{serial}/switchPortStatuses'
query_params = ['t0', 'timespan']
params = {k: v for (k, v) in kwargs.items() if k in query_params}
return self._session.get(metadata, resource, params)
def getDeviceSwitchPortStatusesPackets(self, serial: str, **kwargs):
"""
**Return the packet counters for all the ports of a switch**
https://developer.cisco.com/meraki/api/#!get-device-switch-port-statuses-packets
- serial (string)
- t0 (string): The beginning of the timespan for the data. The maximum lookback period is 1 day from today.
- timespan (number): The timespan for which the information will be fetched. If specifying timespan, do not specify parameter t0. The value must be in seconds and be less than or equal to 1 day. The default is 1 day.
"""
kwargs.update(locals())
metadata = {
'tags': ['Switch ports'],
'operation': 'getDeviceSwitchPortStatusesPackets',
}
resource = f'/devices/{serial}/switchPortStatuses/packets'
query_params = ['t0', 'timespan']
params = {k: v for (k, v) in kwargs.items() if k in query_params}
return self._session.get(metadata, resource, params)
def getDeviceSwitchPorts(self, serial: str):
"""
**List the switch ports for a switch**
https://developer.cisco.com/meraki/api/#!get-device-switch-ports
- serial (string)
"""
metadata = {
'tags': ['Switch ports'],
'operation': 'getDeviceSwitchPorts',
}
resource = f'/devices/{serial}/switchPorts'
return self._session.get(metadata, resource)
def getDeviceSwitchPort(self, serial: str, number: str):
"""
**Return a switch port**
https://developer.cisco.com/meraki/api/#!get-device-switch-port
- serial (string)
- number (string)
"""
metadata = {
'tags': ['Switch ports'],
'operation': 'getDeviceSwitchPort',
}
resource = f'/devices/{serial}/switchPorts/{number}'
return self._session.get(metadata, resource)
def updateDeviceSwitchPort(self, serial: str, number: str, **kwargs):
"""
**Update a switch port**
https://developer.cisco.com/meraki/api/#!update-device-switch-port
- serial (string)
- number (string)
- name (string): The name of the switch port
- tags (string): The tags of the switch port
- enabled (boolean): The status of the switch port
- type (string): The type of the switch port ('trunk' or 'access')
- vlan (integer): The VLAN of the switch port. A null value will clear the value set for trunk ports.
- voiceVlan (integer): The voice VLAN of the switch port. Only applicable to access ports.
- allowedVlans (string): The VLANs allowed on the switch port. Only applicable to trunk ports.
- poeEnabled (boolean): The PoE status of the switch port
- isolationEnabled (boolean): The isolation status of the switch port
- rstpEnabled (boolean): The rapid spanning tree protocol status
- stpGuard (string): The state of the STP guard ('disabled', 'root guard', 'bpdu guard' or 'loop guard')
- accessPolicyNumber (integer): The number of the access policy of the switch port. Only applicable to access ports.
- linkNegotiation (string): The link speed for the switch port
- portScheduleId (string): The ID of the port schedule. A value of null will clear the port schedule.
- udld (string): The action to take when Unidirectional Link is detected (Alert only, Enforce). Default configuration is Alert only.
- macWhitelist (array): Only devices with MAC addresses specified in this list will have access to this port. Up to 20 MAC addresses can be defined. To disable MAC whitelist, set accessPolicyNumber to null.
- stickyMacWhitelist (array): The initial list of MAC addresses for sticky Mac whitelist. To reset Sticky MAC whitelist, set accessPolicyNumber to null.
- stickyMacWhitelistLimit (integer): The maximum number of MAC addresses for sticky MAC whitelist.
- stormControlEnabled (boolean): The storm control status of the switch port
"""
kwargs.update(locals())
if 'type' in kwargs:
options = ['trunk', 'access']
assert kwargs['type'] in options, f'''"type" cannot be "{kwargs['type']}", & must be set to one of: {options}'''
if 'stpGuard' in kwargs:
options = ['disabled', 'root guard', 'bpdu guard', 'loop guard']
assert kwargs['stpGuard'] in options, f'''"stpGuard" cannot be "{kwargs['stpGuard']}", & must be set to one of: {options}'''
if 'udld' in kwargs:
options = ['Alert only', 'Enforce']
assert kwargs['udld'] in options, f'''"udld" cannot be "{kwargs['udld']}", & must be set to one of: {options}'''
metadata = {
'tags': ['Switch ports'],
'operation': 'updateDeviceSwitchPort',
}
resource = f'/devices/{serial}/switchPorts/{number}'
body_params = ['name', 'tags', 'enabled', 'type', 'vlan', 'voiceVlan', 'allowedVlans', 'poeEnabled', 'isolationEnabled', 'rstpEnabled', 'stpGuard', 'accessPolicyNumber', 'linkNegotiation', 'portScheduleId', 'udld', 'macWhitelist', 'stickyMacWhitelist', 'stickyMacWhitelistLimit', 'stormControlEnabled']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.put(metadata, resource, payload)