forked from meraki/dashboard-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevices.py
More file actions
218 lines (152 loc) · 8.28 KB
/
Copy pathdevices.py
File metadata and controls
218 lines (152 loc) · 8.28 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
class Devices(object):
def __init__(self, session):
super(Devices, self).__init__()
self._session = session
def getDevice(self, serial: str):
"""
**Return a single device**
https://developer.cisco.com/meraki/api-v1/#!get-device
- serial (string): (required)
"""
metadata = {
'tags': ['devices', 'configure'],
'operation': 'getDevice'
}
resource = f'/devices/{serial}'
return self._session.get(metadata, resource)
def updateDevice(self, serial: str, **kwargs):
"""
**Update the attributes of a device**
https://developer.cisco.com/meraki/api-v1/#!update-device
- serial (string): (required)
- name (string): The name of a device
- tags (array): The list of tags of a device
- lat (number): The latitude of a device
- lng (number): The longitude of a device
- address (string): The address of a device
- notes (string): The notes for the device. String. Limited to 255 characters.
- moveMapMarker (boolean): Whether or not to set the latitude and longitude of a device based on the new address. Only applies when lat and lng are not specified.
- switchProfileId (string): The ID of a switch profile to bind to the device (for available switch profiles, see the 'Switch Profiles' endpoint). Use null to unbind the switch device from the current profile. For a device to be bindable to a switch profile, it must (1) be a switch, and (2) belong to a network that is bound to a configuration template.
- floorPlanId (string): The floor plan to associate to this device. null disassociates the device from the floorplan.
"""
kwargs.update(locals())
metadata = {
'tags': ['devices', 'configure'],
'operation': 'updateDevice'
}
resource = f'/devices/{serial}'
body_params = ['name', 'tags', 'lat', 'lng', 'address', 'notes', 'moveMapMarker', 'switchProfileId', 'floorPlanId', ]
payload = {k.strip(): v for k, v in kwargs.items() if k.strip() in body_params}
return self._session.put(metadata, resource, payload)
def blinkDeviceLeds(self, serial: str, **kwargs):
"""
**Blink the LEDs on a device**
https://developer.cisco.com/meraki/api-v1/#!blink-device-leds
- serial (string): (required)
- duration (integer): The duration in seconds. Must be between 5 and 120. Default is 20 seconds
- period (integer): The period in milliseconds. Must be between 100 and 1000. Default is 160 milliseconds
- duty (integer): The duty cycle as the percent active. Must be between 10 and 90. Default is 50.
"""
kwargs.update(locals())
metadata = {
'tags': ['devices', 'liveTools'],
'operation': 'blinkDeviceLeds'
}
resource = f'/devices/{serial}/blinkLeds'
body_params = ['duration', 'period', 'duty', ]
payload = {k.strip(): v for k, v in kwargs.items() if k.strip() in body_params}
return self._session.post(metadata, resource, payload)
def getDeviceClients(self, serial: str, **kwargs):
"""
**List the clients of a device, up to a maximum of a month ago**
https://developer.cisco.com/meraki/api-v1/#!get-device-clients
- serial (string): (required)
- 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': ['devices', 'monitor', 'clients'],
'operation': 'getDeviceClients'
}
resource = f'/devices/{serial}/clients'
query_params = ['t0', 'timespan', ]
params = {k.strip(): v for k, v in kwargs.items() if k.strip() in query_params}
return self._session.get(metadata, resource, params)
def getDeviceLldpCdp(self, serial: str):
"""
**List LLDP and CDP information for a device**
https://developer.cisco.com/meraki/api-v1/#!get-device-lldp-cdp
- serial (string): (required)
"""
metadata = {
'tags': ['devices', 'monitor', 'lldpCdp'],
'operation': 'getDeviceLldpCdp'
}
resource = f'/devices/{serial}/lldpCdp'
return self._session.get(metadata, resource)
def getDeviceLossAndLatencyHistory(self, serial: str, ip: str, **kwargs):
"""
**Get the uplink loss percentage and latency in milliseconds, and goodput in kilobits per second for a wired network device.**
https://developer.cisco.com/meraki/api-v1/#!get-device-loss-and-latency-history
- serial (string): (required)
- ip (string): The destination IP used to obtain the requested stats. This is required.
- t0 (string): The beginning of the timespan for the data. The maximum lookback period is 365 days from today.
- t1 (string): The end of the timespan for the data. t1 can be a maximum of 31 days after t0.
- timespan (number): The timespan for which the information will be fetched. If specifying timespan, do not specify parameters t0 and t1. The value must be in seconds and be less than or equal to 31 days. The default is 1 day.
- resolution (integer): The time resolution in seconds for returned data. The valid resolutions are: 60, 600, 3600, 86400. The default is 60.
- uplink (string): The WAN uplink used to obtain the requested stats. Valid uplinks are wan1, wan2, cellular. The default is wan1.
"""
kwargs.update(locals())
if 'uplink' in kwargs:
options = ['wan1', 'wan2', 'cellular']
assert kwargs['uplink'] in options, f'''"uplink" cannot be "{kwargs['uplink']}", & must be set to one of: {options}'''
metadata = {
'tags': ['devices', 'monitor', 'lossAndLatencyHistory'],
'operation': 'getDeviceLossAndLatencyHistory'
}
resource = f'/devices/{serial}/lossAndLatencyHistory'
query_params = ['t0', 't1', 'timespan', 'resolution', 'uplink', 'ip', ]
params = {k.strip(): v for k, v in kwargs.items() if k.strip() in query_params}
return self._session.get(metadata, resource, params)
def getDeviceManagementInterface(self, serial: str):
"""
**Return the management interface settings for a device**
https://developer.cisco.com/meraki/api-v1/#!get-device-management-interface
- serial (string): (required)
"""
metadata = {
'tags': ['devices', 'configure', 'managementInterface'],
'operation': 'getDeviceManagementInterface'
}
resource = f'/devices/{serial}/managementInterface'
return self._session.get(metadata, resource)
def updateDeviceManagementInterface(self, serial: str, **kwargs):
"""
**Update the management interface settings for a device**
https://developer.cisco.com/meraki/api-v1/#!update-device-management-interface
- serial (string): (required)
- wan1 (object): WAN 1 settings
- wan2 (object): WAN 2 settings (only for MX devices)
"""
kwargs.update(locals())
metadata = {
'tags': ['devices', 'configure', 'managementInterface'],
'operation': 'updateDeviceManagementInterface'
}
resource = f'/devices/{serial}/managementInterface'
body_params = ['wan1', 'wan2', ]
payload = {k.strip(): v for k, v in kwargs.items() if k.strip() in body_params}
return self._session.put(metadata, resource, payload)
def rebootDevice(self, serial: str):
"""
**Reboot a device**
https://developer.cisco.com/meraki/api-v1/#!reboot-device
- serial (string): (required)
"""
metadata = {
'tags': ['devices', 'liveTools'],
'operation': 'rebootDevice'
}
resource = f'/devices/{serial}/reboot'
return self._session.post(metadata, resource)