UpdateVPNsettings API formatting error

Solved
nvrdone
Here to help

UpdateVPNsettings API formatting error

I have to be blind because there error I'm getting is that my ip address is not formatted correctly for the meraki module in python.  But it looks correct.

Yes i know i'm importing more then needed.

from meraki import meraki
from ipaddress import ip_address
import random
import requests
import json
import sys
import re
import warnings
import os
import csv

# Used to access Meraki API
import login
(API_KEY, ORG_ID, BASE_URL) = (login.api_key, login.org_id, login.base_url)

####Variables####
my_hub = '#####'
my_mode = 'spoke'
my_usevpn = 'True'

# Get the current list of networks
current_networks = meraki.getnetworklist(API_KEY, ORG_ID)

# Get the current networks' ID
network_id = [network['id'] for network in current_networks]
network_id.pop(1)

#Get VLANS
for line in network_id:
vlans = meraki.getvlans(API_KEY, line)
vpn = meraki.getvpnsettings(API_KEY, line)

#Get the VPN Subnets
vpn_subnet = [subnet['subnet'] for subnet in vlans]
for sub in vpn_subnet:

#Update VPN Settings
update_vpnsettings = meraki.updatevpnsettings(API_KEY, line, mode=my_mode, subnets=sub, usevpn=my_usevpn, hubnetworks=my_hub, defaultroute='False')
print(update_vpnsettings) 

    raise ValueError('Invalid Subnet IP Address {0} - Address must be formatted as #.#.#.#/#'.format(str(subnetip)))
ValueError: Invalid Subnet IP Address 1 - Address must be formatted as #.#.#.#/#

 

The issue is with the sub variable.  But that comes out formatted as x.x.x.x/x.  I have a hard time believing that someone way smarter then me screwed up when making the module.

 

Sub variable output

 

192.168.128.0/24
10.110.14.0/24
10.110.15.0/24
10.110.16.0/24
10.110.17.0/24
10.110.20.0/24
10.110.77.0/24
10.110.175.0/24
10.110.215.0/24

1 Accepted Solution
BrechtSchamp
Kind of a big deal

You'll probably want to beautify it by using more variables, but I just want to demonstrate the correct usage and particularly the variable types you need for it to be successful:

update_vpnsettings = meraki.updatevpnsettings(API_KEY, "N_987654321987654", mode='spoke', subnets=["10.255.255.0/24","10.10.0.0/24","10.15.0.0/24","10.25.0.0/16","10.5.0.0/24","10.28.0.0/16"] , usevpn=[True, True, False, True, True, True], hubnetworks=["N_123456789123456"], defaultroute=[False])

Note that it uses the actual bool variable type of Python so no quotes. Also for the hub(s) and whether to use them as default route two lists are expected.

View solution in original post

5 Replies 5
BrechtSchamp
Kind of a big deal

The API is expecting a list of all the subnets at once.

 

I believe the Meraki python library manages that by combining (zipping) two same-length lists in the updatevpnsettings method.

 

A list of subnets:

["192.168.128.0/24","10.110.14.0/24","10.110.15.0/24","10.110.16.0/24"]

A list of whether or not to include them in the VPN:

[True,False,True,False]

nvrdone
Here to help

I did see that part

 

(from meraki.py)

__comparelist(subnets, usevpn)

vpnsubnets = list(zip(subnets, usevpn))

 

in order to test if that was the problem I static set all the requirements of the function.  (subnets='10.10.10.10/24', usevpn = 'True') and still receive the same error.

 

Unless I'm mistaken this would give me the equal length list to satisfy this part.

 

Just for reference i ran just the updatevpnsettings function.  I did not run it through the for loops.

BrechtSchamp
Kind of a big deal

You'll probably want to beautify it by using more variables, but I just want to demonstrate the correct usage and particularly the variable types you need for it to be successful:

update_vpnsettings = meraki.updatevpnsettings(API_KEY, "N_987654321987654", mode='spoke', subnets=["10.255.255.0/24","10.10.0.0/24","10.15.0.0/24","10.25.0.0/16","10.5.0.0/24","10.28.0.0/16"] , usevpn=[True, True, False, True, True, True], hubnetworks=["N_123456789123456"], defaultroute=[False])

Note that it uses the actual bool variable type of Python so no quotes. Also for the hub(s) and whether to use them as default route two lists are expected.

nvrdone
Here to help

Thank you for this.  One last question, for future reference where would I find how these are suppose to be formatted, or is it just my green-ness?

BrechtSchamp
Kind of a big deal

You're welcome.

 

For the regular API's the documentation is the postman collection:

postman.meraki.com

 

For the Python library, I didn't see decent documentation that would have mentioned this. But I came to the correct code by looking at both what the API expects and what was in the source code of the python library. Then just testing. Unfortunately the errors aren't always very explanatory.

Get notified when there are additional replies to this discussion.