forked from meraki/dashboard-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetworks.py
More file actions
308 lines (232 loc) · 13.7 KB
/
Copy pathnetworks.py
File metadata and controls
308 lines (232 loc) · 13.7 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
class Networks(object):
def __init__(self, session):
super(Networks, self).__init__()
self._session = session
def getNetwork(self, networkId: str):
"""
**Return a network**
https://developer.cisco.com/meraki/api/#!get-network
- networkId (string)
"""
metadata = {
'tags': ['Networks'],
'operation': 'getNetwork',
}
resource = f'/networks/{networkId}'
return self._session.get(metadata, resource)
def updateNetwork(self, networkId: str, **kwargs):
"""
**Update a network**
https://developer.cisco.com/meraki/api/#!update-network
- networkId (string)
- name (string): The name of the network
- timeZone (string): The timezone of the network. For a list of allowed timezones, please see the 'TZ' column in the table in <a target='_blank' href='https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'>this article.</a>
- tags (string): A space-separated list of tags to be applied to the network
- disableMyMerakiCom (boolean): Disables the local device status pages (<a target='_blank' href='http://my.meraki.com/'>my.meraki.com, </a><a target='_blank' href='http://ap.meraki.com/'>ap.meraki.com, </a><a target='_blank' href='http://switch.meraki.com/'>switch.meraki.com, </a><a target='_blank' href='http://wired.meraki.com/'>wired.meraki.com</a>). Optional (defaults to false)
- disableRemoteStatusPage (boolean): Disables access to the device status page (<a target='_blank'>http://[device's LAN IP])</a>. Optional. Can only be set if disableMyMerakiCom is set to false
- enrollmentString (string): A unique identifier which can be used for device enrollment or easy access through the Meraki SM Registration page or the Self Service Portal. Please note that changing this field may cause existing bookmarks to break.
"""
kwargs.update(locals())
metadata = {
'tags': ['Networks'],
'operation': 'updateNetwork',
}
resource = f'/networks/{networkId}'
body_params = ['name', 'timeZone', 'tags', 'disableMyMerakiCom', 'disableRemoteStatusPage', 'enrollmentString']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.put(metadata, resource, payload)
def deleteNetwork(self, networkId: str):
"""
**Delete a network**
https://developer.cisco.com/meraki/api/#!delete-network
- networkId (string)
"""
metadata = {
'tags': ['Networks'],
'operation': 'deleteNetwork',
}
resource = f'/networks/{networkId}'
return self._session.delete(metadata, resource)
def getNetworkAccessPolicies(self, networkId: str):
"""
**List the access policies for this network. Only valid for MS networks.**
https://developer.cisco.com/meraki/api/#!get-network-access-policies
- networkId (string)
"""
metadata = {
'tags': ['Networks'],
'operation': 'getNetworkAccessPolicies',
}
resource = f'/networks/{networkId}/accessPolicies'
return self._session.get(metadata, resource)
def getNetworkAirMarshal(self, networkId: str, **kwargs):
"""
**List Air Marshal scan results from a network**
https://developer.cisco.com/meraki/api/#!get-network-air-marshal
- networkId (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 7 days.
"""
kwargs.update(locals())
metadata = {
'tags': ['Networks'],
'operation': 'getNetworkAirMarshal',
}
resource = f'/networks/{networkId}/airMarshal'
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 bindNetwork(self, networkId: str, configTemplateId: str, **kwargs):
"""
**Bind a network to a template.**
https://developer.cisco.com/meraki/api/#!bind-network
- networkId (string)
- configTemplateId (string): The ID of the template to which the network should be bound.
- autoBind (boolean): Optional boolean indicating whether the network's switches should automatically bind to profiles of the same model. Defaults to false if left unspecified. This option only affects switch networks and switch templates. Auto-bind is not valid unless the switch template has at least one profile and has at most one profile per switch model.
"""
kwargs.update(locals())
metadata = {
'tags': ['Networks'],
'operation': 'bindNetwork',
}
resource = f'/networks/{networkId}/bind'
body_params = ['configTemplateId', 'autoBind']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.post(metadata, resource, payload)
def getNetworkSiteToSiteVpn(self, networkId: str):
"""
**Return the site-to-site VPN settings of a network. Only valid for MX networks.**
https://developer.cisco.com/meraki/api/#!get-network-site-to-site-vpn
- networkId (string)
"""
metadata = {
'tags': ['Networks'],
'operation': 'getNetworkSiteToSiteVpn',
}
resource = f'/networks/{networkId}/siteToSiteVpn'
return self._session.get(metadata, resource)
def updateNetworkSiteToSiteVpn(self, networkId: str, mode: str, **kwargs):
"""
**Update the site-to-site VPN settings of a network. Only valid for MX networks in NAT mode.**
https://developer.cisco.com/meraki/api/#!update-network-site-to-site-vpn
- networkId (string)
- mode (string): The site-to-site VPN mode. Can be one of 'none', 'spoke' or 'hub'
- hubs (array): The list of VPN hubs, in order of preference. In spoke mode, at least 1 hub is required.
- subnets (array): The list of subnets and their VPN presence.
"""
kwargs.update(locals())
if 'mode' in kwargs:
options = ['none', 'spoke', 'hub']
assert kwargs['mode'] in options, f'''"mode" cannot be "{kwargs['mode']}", & must be set to one of: {options}'''
metadata = {
'tags': ['Networks'],
'operation': 'updateNetworkSiteToSiteVpn',
}
resource = f'/networks/{networkId}/siteToSiteVpn'
body_params = ['mode', 'hubs', 'subnets']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.put(metadata, resource, payload)
def splitNetwork(self, networkId: str):
"""
**Split a combined network into individual networks for each type of device**
https://developer.cisco.com/meraki/api/#!split-network
- networkId (string)
"""
metadata = {
'tags': ['Networks'],
'operation': 'splitNetwork',
}
resource = f'/networks/{networkId}/split'
return self._session.post(metadata, resource)
def getNetworkTraffic(self, networkId: str, **kwargs):
"""
** The traffic analysis data for this network.
<a href="https://documentation.meraki.com/MR/Monitoring_and_Reporting/Hostname_Visibility">Traffic Analysis with Hostname Visibility</a> must be enabled on the network.
**
https://developer.cisco.com/meraki/api/#!get-network-traffic
- networkId (string)
- t0 (string): The beginning of the timespan for the data. The maximum lookback period is 30 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 30 days.
- deviceType (string): Filter the data by device type: 'combined', 'wireless', 'switch' or 'appliance'. Defaults to 'combined'.
When using 'combined', for each rule the data will come from the device type with the most usage.
"""
kwargs.update(locals())
if 'deviceType' in kwargs:
options = ['combined', 'wireless', 'switch', 'appliance']
assert kwargs['deviceType'] in options, f'''"deviceType" cannot be "{kwargs['deviceType']}", & must be set to one of: {options}'''
metadata = {
'tags': ['Networks'],
'operation': 'getNetworkTraffic',
}
resource = f'/networks/{networkId}/traffic'
query_params = ['t0', 'timespan', 'deviceType']
params = {k: v for (k, v) in kwargs.items() if k in query_params}
return self._session.get(metadata, resource, params)
def unbindNetwork(self, networkId: str):
"""
**Unbind a network from a template.**
https://developer.cisco.com/meraki/api/#!unbind-network
- networkId (string)
"""
metadata = {
'tags': ['Networks'],
'operation': 'unbindNetwork',
}
resource = f'/networks/{networkId}/unbind'
return self._session.post(metadata, resource)
def getOrganizationNetworks(self, organizationId: str, **kwargs):
"""
**List the networks in an organization**
https://developer.cisco.com/meraki/api/#!get-organization-networks
- organizationId (string)
- configTemplateId (string): An optional parameter that is the ID of a config template. Will return all networks bound to that template.
"""
kwargs.update(locals())
metadata = {
'tags': ['Networks'],
'operation': 'getOrganizationNetworks',
}
resource = f'/organizations/{organizationId}/networks'
query_params = ['configTemplateId']
params = {k: v for (k, v) in kwargs.items() if k in query_params}
return self._session.get(metadata, resource, params)
def createOrganizationNetwork(self, organizationId: str, name: str, type: str, **kwargs):
"""
**Create a network**
https://developer.cisco.com/meraki/api/#!create-organization-network
- organizationId (string)
- name (string): The name of the new network
- type (string): The type of the new network. Valid types are wireless, appliance, switch, systemsManager, camera, cellularGateway, or a space-separated list of those for a combined network.
- tags (string): A space-separated list of tags to be applied to the network
- timeZone (string): The timezone of the network. For a list of allowed timezones, please see the 'TZ' column in the table in <a target='_blank' href='https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'>this article.</a>
- copyFromNetworkId (string): The ID of the network to copy configuration from. Other provided parameters will override the copied configuration, except type which must match this network's type exactly.
- disableMyMerakiCom (boolean): Disables the local device status pages (<a target='_blank' href='http://my.meraki.com/'>my.meraki.com, </a><a target='_blank' href='http://ap.meraki.com/'>ap.meraki.com, </a><a target='_blank' href='http://switch.meraki.com/'>switch.meraki.com, </a><a target='_blank' href='http://wired.meraki.com/'>wired.meraki.com</a>). Optional (defaults to false)
- disableRemoteStatusPage (boolean): Disables access to the device status page (<a target='_blank'>http://[device's LAN IP])</a>. Optional. Can only be set if disableMyMerakiCom is set to false
"""
kwargs.update(locals())
metadata = {
'tags': ['Networks'],
'operation': 'createOrganizationNetwork',
}
resource = f'/organizations/{organizationId}/networks'
body_params = ['name', 'type', 'tags', 'timeZone', 'copyFromNetworkId', 'disableMyMerakiCom', 'disableRemoteStatusPage']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.post(metadata, resource, payload)
def combineOrganizationNetworks(self, organizationId: str, name: str, networkIds: list, **kwargs):
"""
**Combine multiple networks into a single network**
https://developer.cisco.com/meraki/api/#!combine-organization-networks
- organizationId (string)
- name (string): The name of the combined network
- networkIds (array): A list of the network IDs that will be combined. If an ID of a combined network is included in this list, the other networks in the list will be grouped into that network
- enrollmentString (string): A unique identifier which can be used for device enrollment or easy access through the Meraki SM Registration page or the Self Service Portal. Please note that changing this field may cause existing bookmarks to break. All networks that are part of this combined network will have their enrollment string appended by '-network_type'. If left empty, all exisitng enrollment strings will be deleted.
"""
kwargs.update(locals())
metadata = {
'tags': ['Networks'],
'operation': 'combineOrganizationNetworks',
}
resource = f'/organizations/{organizationId}/networks/combine'
body_params = ['name', 'networkIds', 'enrollmentString']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.post(metadata, resource, payload)