stickyMacAllowList error must be an array

Solved
eroche
Getting noticed

stickyMacAllowList error must be an array

Having an issue with trying to update the stickyMacAllowList value. Doesn't matter if I leave it blank to try and remove the current mac address or if I add a valid mac (xx:xx:xx:xx:xx:xx) I keep getting the following error:

 

400 Bad Request, {'errors': ["'stickyMacAllowList' must be an array"]}

 

Below is my full code. Thanks in advance.

 

import meraki

import os

import time

import pprint

from colorama import init as colorama_init

from colorama import Fore, Back

from colorama import Style

import inquirer

from inquirer.themes import GreenPassion

import progressbar



def get_meraki_api_key():

    api_key = os.getenv('MERAKI_API_KEY')

    if not api_key:

        raise ValueError("No API key found. Please set the MERAKI_API_KEY enviroment variable.")

    return api_key







# Select Device    

sw_sn = 'my sn'

port = input ('\n' + 'What port would you like to update? (1,2...48): ')

print (Fore.BLUE,Style.BRIGHT +'\n' + 'Below is the current information for that port:  ' + '\n')

API_KEY = get_meraki_api_key()

dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)

serial = (sw_sn) 

port_id = (port)



response = dashboard.switch.getDeviceSwitchPort(serial, port_id)

    

fields = ['portId', 'name', 'enabled', 'poeEnabled', 'type', 'vlan', 'voiceVlan', 'allowedVlans', 'accessPolicyType','isolationEnabled', 'rstpEnabled', 'stpGuard', 'linkNegotiation']

    

for field in fields:

    print (f"{field}: {response[field]}")

        

# Update settings   

def update_values():



    print (Fore.YELLOW,Style.BRIGHT +'\n' + 'Please enter the updated values, which are Case-Sensitive:  ' + '\n')

    

    v_allowed = ""

    mac_allowed = ""

    sticky_mac_allowed = ""

    mac_allowed_limit = ""

    v_vlan = ""

    

    port_name = input ('\n' + 'Port Name:  ')

    enable = input ('Enable Port [True or False]:  ')

    port_type = input ('Port Type [trunk or access]:  ')

    d_vlan = input ('Data VLAN:  ')

    if port_type == ('access'):

        v_vlan = input ('Voice VLAN:  ')

    if port_type == ('trunk'):

        v_allowed = input ('Allowed VLANs [1,3 or 1-3 or All]: ')

    rstp_enabled = input ('RSTP Enable [True or False]:  ')

    stp_guard = input ('STP Guard [disabled, root guard, bpdu guard, loop guard]:  ')

    if port_type == ('access'):

        access_policy = input ('Access Policy [MAC allow list, Open, Sticky MAC allow list]:  ')

    if access_policy == ('MAC allow list'):

       mac_allowed = input ('MAC Address [xx:xx:xx:xx:xx:xx, xx:xx:xx:xx:xx:xx): ')

    if access_policy == ('Sticky MAC allow list'):

        sticky_mac_allowed = input ('MAC Address [xx:xx:xx:xx:xx:xx, xx:xx:xx:xx:xx:xx]: ')

        #mac_allowed_limit = input ('How many MAC Address Allowed: ') Commented until above fixed

    poe_enabled = input ('PoE Enabled [True or False]:  ')





    response_update = {}

    

    if port_name:

        response_update["name"] = port_name

    if enable:

        response_update["enabled"] = enable

    if port_type:

        response_update["type"] = port_type

    if d_vlan != '':

        response_update["vlan"] = d_vlan

    if v_vlan != '':

        response_update["voiceVlan"] = v_vlan

    if v_allowed == '0':

        response_update["allowedVlans"] = v_allowed

    if rstp_enabled:

        response_update["rstpEnabled"] = rstp_enabled

    if stp_guard:

        response_update["stpGuard"] = stp_guard

    if access_policy:

        response_update["accessPolicyType"] = access_policy

    if mac_allowed:

        response_update["macAllowList"] = mac_allowed

    if sticky_mac_allowed:

        response_update["stickyMacAllowList"] = sticky_mac_allowed

    if mac_allowed_limit != '':

        response_update["stickyMacAllowListLimit"]

    if poe_enabled:

        response_update["poeEnabled"] = poe_enabled

    



    fields = response_update

    

    print (Fore.WHITE,Style.BRIGHT + '\n' + 'Here are the values you entered')

    

    for field in fields:

        print (f"{field}: {response_update[field]}")

    

   

    validate = input ('\n' + 'Are all values correct [Y or N]:  ')

 



    if validate in {'Y', 'y'}:



        response = dashboard.switch.updateDeviceSwitchPort(serial, port_id,**response_update,)



        response = dashboard.switch.getDeviceSwitchPort(serial, port_id)



        fields = response_update



        print (Fore.GREEN,Style.BRIGHT + '\n' + 'Here are the New Settings: ' + '\n')



        for field in fields:

            print (f"{field}: {response_update[field]}")



        input  ('\n' + 'Press Enter to return to Main Menu: ')



        main_menu()



    elif validate in {'N', 'n'}:

        input (Fore.MAGENTA + Style.BRIGHT + '\n' + 'Darn, Ok lets try this again, press Enter: ')

        #clearconsole()

        print (Fore.BLUE,Style.BRIGHT +'\n' + 'Current Values:' + '\n')

            

        response = dashboard.switch.getDeviceSwitchPort(serial, port_id)

    

        fields = ['portId', 'name', 'enabled', 'poeEnabled', 'type', 'vlan', 'voiceVlan', 'allowedVlans', 'isolationEnabled', 'rstpEnabled', 'stpGuard', 'linkNegotiation']

    

        for field in fields:

            print (f"{field}: {response[field]}")

                

        update_values()

            

    else:

        print ('you need to select Y,y,N or n')

            

            

update_values()
1 Accepted Solution
sungod
Kind of a big deal

The error is because that variable needs to be a list, but you are using a simple variable.

 

As @PhilipDAth says, look at an example return data to see which are lists, or look at the API documentation, there is an example response.

 

I don't see any way for the inquirer library to return a list, you'll just get a string. So you'll need to parse the string into a list.

 

This might work...

m = input ('MAC Address, enter one or more separated by space xx:xx:xx:xx:xx:xx : ')
mac_allowed = list(m.split(" "))

 

View solution in original post

6 Replies 6
PhilipDAth
Kind of a big deal
Kind of a big deal

What I often do for these kinds of problems is create the configuration in the Dashboard, then "Get" the config - and see how the data is formatted.

PhilipDAth
Kind of a big deal
Kind of a big deal

Should this line:

mac_allowed = input ('MAC Address [xx:xx:xx:xx:xx:xx, xx:xx:xx:xx:xx:xx): ')

be?

mac_allowed = input ('MAC Address [xx:xx:xx:xx:xx:xx, xx:xx:xx:xx:xx:xx]: ')

 

sungod
Kind of a big deal

The error is because that variable needs to be a list, but you are using a simple variable.

 

As @PhilipDAth says, look at an example return data to see which are lists, or look at the API documentation, there is an example response.

 

I don't see any way for the inquirer library to return a list, you'll just get a string. So you'll need to parse the string into a list.

 

This might work...

m = input ('MAC Address, enter one or more separated by space xx:xx:xx:xx:xx:xx : ')
mac_allowed = list(m.split(" "))

 

eroche
Getting noticed

this worked thanks......one last question kind of with this topic.....can we clear the Sticky MAC Address through API, same task as clearing port security on a Cisco switch.

PhilipDAth
Kind of a big deal
Kind of a big deal

Not tested.  Try specifying an empty array.

eroche
Getting noticed

Yeah I thought I did that in the very very beginning but now trying that where I am at now it keeps failing with a error for the value not being a mac address.

 

I will just try it again from the basic script for that one thing and see what happens. Worse case I will just open another topic😉

Get notified when there are additional replies to this discussion.