07-18-2020 08:48 AM
Hi,
I'm working on a Python script to change ip ranges of MX's that are bound to a template.
def setmxipaddresses(p_apikey, p_shardurl, p_nwid, p_vlid):
try:
print (p_apikey, p_shardurl, p_nwid, p_vlid)
r = requests.put('https://%s/api/v0/networks/%s/vlans/%s' % (p_shardurl, p_nwid, p_vlid), data=json.dumps({'applianceIp':'192.168.1.2','subnet':'192.168.1.0/24'}), headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'})
print (r)
except:
printusertext('ERROR 11: Unable to contact Meraki cloud')
sys.exit(2)
if r.status_code != requests.codes.ok:
return ('null')
return('ok')
if arg_IP_address != 'null':
#print (getvlan (arg_apikey, shardurl, nwid))
setmxipaddresses(arg_apikey, shardurl, nwid, arg_IP_address)But is seems that there is something wrong as i'm getting a error 400 back but i cannot figure out what is wrong.
Solved! Go to Solution.
07-25-2020 09:46 AM
Got it to work now and i can change ip addresses on templates! Thank all for your help:
The issue was that i tried to changed it to a complete different ip range then configured on the template:
/24 from 172.16.0.0/8
when i do change it but in the given range it works. Also the JSON i used wasn't formed correctly.
def setmxipaddresses(p_apikey, p_shardurl, p_nwid, p_vlid):
try:
Data = {"applianceIp":"172.9.20.1","subnet":"172.9.20.0/24"}
print (p_apikey, p_shardurl, p_nwid, p_vlid)
r = requests.put('https://%s/api/v0/networks/%s/vlans/%s' % (p_shardurl, p_nwid, p_vlid), data=json.dumps(Data), headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'})
print (r)
except:
printusertext('ERROR 11: Unable to contact Meraki cloud')
sys.exit(2)
if r.status_code != requests.codes.ok:
return ('null')
return('ok')
07-18-2020 03:11 PM
So your MX are all bound to a template that includes the vlan setup, but you want to override that part of the template?
Pretty sure you can't:
https://documentation.meraki.com/Architectures_and_Best_Practices/Cisco_Meraki_Best_Practice_Design/Best_Practice_Design_-_MX_Security_and_SD-WAN/MX_Templates_Best_Practices Specifically: "If unique is chosen, each network bound to the template will get a unique subnet based on the configured options. The MX does not support local VLAN overrides on templates."
So you're getting a 400 Bad Request response because you're asking it to do something that you're not allowed to do, b/c the network is using a template that includes vlan setup.
By the way, I strongly encourage you to look into the available exceptions for the requests module instead of passing all errors the way you are. Unless you are deliberately passing a generic error and aren't concerned about why an attempt at a particular request failed.
07-20-2020 12:30 AM
Hi,
Thank you for the reply.
The ip addresses are unique per site and only want to change the ip range on the MX and not change the VLAN.
you cannot change the VLAN on a MX once it is bound to a template but i can change the ip range.
Is that possible or ?
07-20-2020 03:01 AM
I am pretty sure you cannot change the IP addresses when a site is bound to a template....
There for you need to unbind, but then you loose a lot of details of the site,...
Also wondering why you make your own definitions within python, simply use the meraki API and not use your own requests REST API calls and live is much easier.
07-20-2020 06:17 AM
Yes you can 😉
As i have done this many time
MX:MX
Template:
Template
07-20-2020 06:23 AM
@johanoosterwaal wrote:Yes you can 😉
As i have done this many time
In that case, are you sure your JSON is well-formed?
Also, are VLANs enabled on your network? I feel like I ran into mystery failures on non-templated MX networks, and the ultimate problem was that VLANs were not enabled. No enabled VLANs, no access to the VLAN calls. Might have changed though.
07-22-2020 05:40 AM
Well i think the JSON is well formed but i'm not sure.
maybe need help with that. do you have an example on this ?
On the MX and template there are 2 vlans enabled, vlan 100 and vlan 5.
07-22-2020 01:33 PM
07-25-2020 09:46 AM
Got it to work now and i can change ip addresses on templates! Thank all for your help:
The issue was that i tried to changed it to a complete different ip range then configured on the template:
/24 from 172.16.0.0/8
when i do change it but in the given range it works. Also the JSON i used wasn't formed correctly.
def setmxipaddresses(p_apikey, p_shardurl, p_nwid, p_vlid):
try:
Data = {"applianceIp":"172.9.20.1","subnet":"172.9.20.0/24"}
print (p_apikey, p_shardurl, p_nwid, p_vlid)
r = requests.put('https://%s/api/v0/networks/%s/vlans/%s' % (p_shardurl, p_nwid, p_vlid), data=json.dumps(Data), headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'})
print (r)
except:
printusertext('ERROR 11: Unable to contact Meraki cloud')
sys.exit(2)
if r.status_code != requests.codes.ok:
return ('null')
return('ok')
07-20-2020 06:18 AM
@Edgar-VO wrote:I am pretty sure you cannot change the IP addresses when a site is bound to a template....
There for you need to unbind, but then you loose a lot of details of the site,...
Also wondering why you make your own definitions within python, simply use the meraki API and not use your own requests REST API calls and live is much easier.
"Easier" is a matter of opinion. I use Python and the requests module because I use the requests module with REST APIs from multiple vendors, and it's a standard method. SDKs all have their own quirks.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide