Updating MX Ports using Python API

Solved
Edgar-VO
Building a reputation

Updating MX Ports using Python API

Hi there,

 

I have been browsing through the forum and saw one thread for this item, but not using the same code examples. i would like to change the MX VLAN ports using the Python meraki API. This is different than the solution posted here where they use the request/REST function and not the api. I get a 200 Ok but the changing have not been done. I am a bit clueless now how to parse all this..

 

I want to update port 3 with a VLAN setting

 

A piece of code :

 

 

pay_load = "{'enabled': True, 'type': 'access', 'dropUntaggedTraffic': False, 'vlan': 400, 'accessPolicy': 'open'}"
pay_load = json.dumps(pay_load)
result = dashboard.mx_vlan_ports.updateNetworkAppliancePort(def_network,"3",param=pay_load)
 
meraki: INFO > MX VLAN ports, updateNetworkAppliancePort - 200 OK
 
But unfortunately no change in port
I think the problem is in parsing the arguments, but i am not sure ...
 
Any ideas ?
 
 
 
 
 
1 Accepted Solution
BrechtSchamp
Kind of a big deal

Like this:

params = {
    "vlan":400,
    "accessPolicy":"open", 
    "enabled" : True,
    "type":"access",
    "dropUntaggedTraffic":False
}

dashboard.mx_vlan_ports.updateNetworkAppliancePort(def_network, 3, **params)

 

View solution in original post

9 Replies 9
damienleick
Getting noticed

Hi,

 

Just to be sure. MX is bind to templated network or not ?

Edgar-VO
Building a reputation

No,

 

The MX will be installed not using a template. I want to script a new and fresh installation

 

 

damienleick
Getting noticed

I'm not sure if is the problem but in the Documentation there is some underscore in the put request :

 

 

mx_vlan_ports_controller.update_network_appliance_port(collect)

ref: https://developer.cisco.com/meraki/api/#/python/api-endpoints/mx-vlan-ports/update-network-appliance...

 

Your one is :

 

dashboard.mx_vlan_ports.updateNetworkAppliancePort

Edgar-VO
Building a reputation

Dashboard is the session ID 

 

dashboard = meraki.DashboardAPI(api_key)
 
in the documentation they only work with the REST API and python request . I can do that as well of course :
 
url = base_url+"/networks/"+my_network_id+"/appliancePorts/3"
payload = json.dumps({"enabled": "true","type":"access","vlan":"400"})

headers = {
'X-Cisco-Meraki-API-Key': api_key,
'Content-Type': 'application/json'
}

response = requests.request("PUT", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
 
Then it works, but is not done using the official released meraki Python modules which you load with : import meraki
 
 
 
BrechtSchamp
Kind of a big deal

The function is actually expecting the parameters in a different way.

 

Try changing it to:

 

result = dashboard.mx_vlan_ports.updateNetworkAppliancePort(def_network,"3",vlan=400, accessPolicy="open", enabled = True, type="access",dropUntaggedTraffic=False)

 

Edgar-VO
Building a reputation

Okay,

 

We are almost there 😉  that part works, however i want to have that part in a variable which i can easily manipulate

vlan=400, accessPolicy="open", enabled = True, type="access",dropUntaggedTraffic=False

 

cause this does not work 

 

pay_load = 'enabled = True, type = "access", dropUntaggedTraffic = False, vlan = 400, accessPolicy = "open"'

 
result = dashboard.mx_vlan_ports.updateNetworkAppliancePort(def_network,"3",pay_load)
 
TypeError: updateNetworkAppliancePort() takes 3 positional arguments but 4 were given
 
BrechtSchamp
Kind of a big deal

Like this:

params = {
    "vlan":400,
    "accessPolicy":"open", 
    "enabled" : True,
    "type":"access",
    "dropUntaggedTraffic":False
}

dashboard.mx_vlan_ports.updateNetworkAppliancePort(def_network, 3, **params)

 

Edgar-VO
Building a reputation

That works, thanks... been looking for that some time (but were afraid to ask 😉 )

 

basically using a dict variable  and add/change values to it... Then the **params is setting a pointer to params values

 

Thnx for the help.... 

BrechtSchamp
Kind of a big deal

Yup kind of. In python terms it's called unpacking. If you want more information about it have a look here:

https://realpython.com/python-kwargs-and-args/#using-the-python-kwargs-variable-in-function-definiti...

Get notified when there are additional replies to this discussion.