Hi All
Attached is my code for a function to update port settings on a switch (dashboard.switch.updateDeviceSwitchPort). When I do a trunk port it keeps telling me it can't update the access policy of the port which I know that and I am not updating. The code is a little long sorry about that but if you can take a look and see if something stands out it would be much appreciated
# 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 = ""
sticky_allowed_limit = ""
rstp_enabled = "True"
stp_guard = "bpdu guard"
native_vlan = ""
d_vlan = ""
access_policy = ""
port_name = input ('\n' + 'Port Name: ')
enable = input ('Enable Port [True or False]: ')
port_type = input ('Port Type [trunk or access] required: ')
if port_type == ('access'):
d_vlan = input ('Data VLAN: ')
v_vlan = input ('Voice VLAN: ')
access_policy = input ('Access Policy [(O)pen, (S)ticky MAC ] required: ')
if access_policy == ('S'):
access_policy = 'Sticky MAC allow list'
mac_allowed_limit = input ('How many MAC Address Allowed: ')
if access_policy == ('O'):
access_policy = "Open"
if port_type == ('trunk'):
native_vlan = input ('Native VLAN: ')
v_allowed = input ('Allowed VLANs [1,3 or 1-3 or All]: ')
poe_enabled = input ('PoE Enabled [True or False]: ')
response_update = {}
if port_type == "access":
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 rstp_enabled:
response_update["rstpEnabled"] = rstp_enabled
if stp_guard:
response_update["stpGuard"] = stp_guard
if access_policy:
#response_update["accessPolicyType"] = access_policy
if sticky_mac_allowed:
response_update["stickyMacAllowList"] = sticky_mac_allowed
if mac_allowed_limit:
response_update["stickyMacAllowListLimit"] = mac_allowed_limit
if poe_enabled:
response_update["poeEnabled"] = poe_enabled
if port_type == "trunk":
if port_name:
response_update["name"] = port_name
if enable:
response_update["enabled"] = enable
if port_type:
response_update["type"] = port_type
if native_vlan:
response_update["vlan"] = native_vlan
if v_allowed:
response_update["allowedVlans"] = v_allowed
if rstp_enabled:
response_update["rstpEnabled"] = "True"
if stp_guard:
response_update["stpGuard"] = "disabled"
fields = response_update
clearconsole()
print (Fore.BLUE,Style.BRIGHT + '\n' + 'Here are the values you entered')
print ('\n')
for field in fields:
print (Fore.YELLOW + f"{field}: " + Fore.WHITE + f"{response_update[field]}")
validate = input ('\n' + 'Are all values correct [Y or N]: ')
if validate in {'Y', 'y'}:
clearconsole()
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'}:
clearconsole()
input (Fore.MAGENTA + Style.BRIGHT + '\n' + 'Darn, Ok lets try this again, press Enter: ')
#clearconsole()
print (Fore.YELLOW,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 or N!')
restart = input ('Hit Enter!')
if restart == "":
update_values()
update_values()
.