forked from meraki/dashboard-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvlans.py
More file actions
163 lines (127 loc) · 6.95 KB
/
Copy pathvlans.py
File metadata and controls
163 lines (127 loc) · 6.95 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
class VLANs(object):
def __init__(self, session):
super(VLANs, self).__init__()
self._session = session
def getNetworkVlans(self, networkId: str):
"""
**List the VLANs for an MX network**
https://developer.cisco.com/meraki/api/#!get-network-vlans
- networkId (string)
"""
metadata = {
'tags': ['VLANs'],
'operation': 'getNetworkVlans',
}
resource = f'/networks/{networkId}/vlans'
return self._session.get(metadata, resource)
def createNetworkVlan(self, networkId: str, id: str, name: str, subnet: str, applianceIp: str, **kwargs):
"""
**Add a VLAN**
https://developer.cisco.com/meraki/api/#!create-network-vlan
- networkId (string)
- id (string): The VLAN ID of the new VLAN (must be between 1 and 4094)
- name (string): The name of the new VLAN
- subnet (string): The subnet of the VLAN
- applianceIp (string): The local IP of the appliance on the VLAN
- groupPolicyId (string): The id of the desired group policy to apply to the VLAN
"""
kwargs.update(locals())
metadata = {
'tags': ['VLANs'],
'operation': 'createNetworkVlan',
}
resource = f'/networks/{networkId}/vlans'
body_params = ['id', 'name', 'subnet', 'applianceIp', 'groupPolicyId']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.post(metadata, resource, payload)
def getNetworkVlan(self, networkId: str, vlanId: str):
"""
**Return a VLAN**
https://developer.cisco.com/meraki/api/#!get-network-vlan
- networkId (string)
- vlanId (string)
"""
metadata = {
'tags': ['VLANs'],
'operation': 'getNetworkVlan',
}
resource = f'/networks/{networkId}/vlans/{vlanId}'
return self._session.get(metadata, resource)
def updateNetworkVlan(self, networkId: str, vlanId: str, **kwargs):
"""
**Update a VLAN**
https://developer.cisco.com/meraki/api/#!update-network-vlan
- networkId (string)
- vlanId (string)
- name (string): The name of the VLAN
- subnet (string): The subnet of the VLAN
- applianceIp (string): The local IP of the appliance on the VLAN
- groupPolicyId (string): The id of the desired group policy to apply to the VLAN
- vpnNatSubnet (string): The translated VPN subnet if VPN and VPN subnet translation are enabled on the VLAN
- dhcpHandling (string): The appliance's handling of DHCP requests on this VLAN. One of: 'Run a DHCP server', 'Relay DHCP to another server' or 'Do not respond to DHCP requests'
- dhcpRelayServerIps (array): The IPs of the DHCP servers that DHCP requests should be relayed to
- dhcpLeaseTime (string): The term of DHCP leases if the appliance is running a DHCP server on this VLAN. One of: '30 minutes', '1 hour', '4 hours', '12 hours', '1 day' or '1 week'
- dhcpBootOptionsEnabled (boolean): Use DHCP boot options specified in other properties
- dhcpBootNextServer (string): DHCP boot option to direct boot clients to the server to load the boot file from
- dhcpBootFilename (string): DHCP boot option for boot filename
- fixedIpAssignments (object): The DHCP fixed IP assignments on the VLAN. This should be an object that contains mappings from MAC addresses to objects that themselves each contain "ip" and "name" string fields. See the sample request/response for more details.
- reservedIpRanges (array): The DHCP reserved IP ranges on the VLAN
- dnsNameservers (string): The DNS nameservers used for DHCP responses, either "upstream_dns", "google_dns", "opendns", or a newline seperated string of IP addresses or domain names
- dhcpOptions (array): The list of DHCP options that will be included in DHCP responses. Each object in the list should have "code", "type", and "value" properties.
"""
kwargs.update(locals())
if 'dhcpHandling' in kwargs:
options = ['Run a DHCP server', 'Relay DHCP to another server', 'Do not respond to DHCP requests']
assert kwargs['dhcpHandling'] in options, f'''"dhcpHandling" cannot be "{kwargs['dhcpHandling']}", & must be set to one of: {options}'''
if 'dhcpLeaseTime' in kwargs:
options = ['30 minutes', '1 hour', '4 hours', '12 hours', '1 day', '1 week']
assert kwargs['dhcpLeaseTime'] in options, f'''"dhcpLeaseTime" cannot be "{kwargs['dhcpLeaseTime']}", & must be set to one of: {options}'''
metadata = {
'tags': ['VLANs'],
'operation': 'updateNetworkVlan',
}
resource = f'/networks/{networkId}/vlans/{vlanId}'
body_params = ['name', 'subnet', 'applianceIp', 'groupPolicyId', 'vpnNatSubnet', 'dhcpHandling', 'dhcpRelayServerIps', 'dhcpLeaseTime', 'dhcpBootOptionsEnabled', 'dhcpBootNextServer', 'dhcpBootFilename', 'fixedIpAssignments', 'reservedIpRanges', 'dnsNameservers', 'dhcpOptions']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.put(metadata, resource, payload)
def deleteNetworkVlan(self, networkId: str, vlanId: str):
"""
**Delete a VLAN from a network**
https://developer.cisco.com/meraki/api/#!delete-network-vlan
- networkId (string)
- vlanId (string)
"""
metadata = {
'tags': ['VLANs'],
'operation': 'deleteNetworkVlan',
}
resource = f'/networks/{networkId}/vlans/{vlanId}'
return self._session.delete(metadata, resource)
def getNetworkVlansEnabledState(self, networkId: str):
"""
**Returns the enabled status of VLANs for the network**
https://developer.cisco.com/meraki/api/#!get-network-vlans-enabled-state
- networkId (string)
"""
metadata = {
'tags': ['VLANs'],
'operation': 'getNetworkVlansEnabledState',
}
resource = f'/networks/{networkId}/vlansEnabledState'
return self._session.get(metadata, resource)
def updateNetworkVlansEnabledState(self, networkId: str, enabled: bool):
"""
**Enable/Disable VLANs for the given network**
https://developer.cisco.com/meraki/api/#!update-network-vlans-enabled-state
- networkId (string)
- enabled (boolean): Boolean indicating whether to enable (true) or disable (false) VLANs for the network
"""
kwargs = locals()
metadata = {
'tags': ['VLANs'],
'operation': 'updateNetworkVlansEnabledState',
}
resource = f'/networks/{networkId}/vlansEnabledState'
body_params = ['enabled']
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
return self._session.put(metadata, resource, payload)