I put together a script to update a switchport through the API. There are times when all the port values do not have to updated so for the field I would like to leave blank then when the updates are submitted through dashboard.switch.updateDeviceSwitchPort, I would like for it skip it and not update. Is this possible? Here is the section of my code that is in questions:
# Update settings
def update_values():
print ('----------------------------------------------------------------' + Style.RESET_ALL)
print (Fore.YELLOW,Style.BRIGHT +'\n' + 'Please enter the updated values: ' + '\n')
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]: ')
access_policy = input ('Access Policy [Open, MAC Allowed, Stickey MAC MAC Allowed, Internal DOT1x]: ')
if access_policy == ('MAC Allowed'):
mac_allowed = input ('MAC Address [xx:xx:xx:xx:xx:xx, xx:xx:xx:xx:xx:xx): ')
if access_policy == ('Sticky MAC Allowed 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: ')
poe_enabled = input ('PoE Enabled [True or False]: ')
print ('\n' + 'Here are the values you entered')
print ('\n' + 'Port Name: ' + port_name + '\n' + 'Port Enabled: ' + enable + '\n' + 'Port Type: ' + port_type + '\n' + 'Data VLAN: ' + d_vlan + '\n' + 'Voice VLAN: ' + v_vlan + '\n'
+ 'VLANs Allowed: ' + v_allowed + 'RSTP: ' + rstp_enabled + '\n' + 'STP Guard: ' + stp_guard + '\n' + 'Access Policy: ' + access_policy + '\n' + 'MACs Aloowed: ' + mac_allowed + \n
'Sticky MACs Allowed: ' + sticky_mac_allowed + \n + 'MAC Allows Limit: ' mac_allowed_limit + \n + 'PoE Enabled: ' + poe_enabled)
validate = input ('\n' + 'Are all values correct [Y or N]: ')
if validate in {'Y', 'y'}:
response = dashboard.switch.updateDeviceSwitchPort(
serial, port_id,
name = port_name,
enabled = enable,
type = port_type,
vlan = d_vlan,
voiceVlan = v_vlan,
allowedVlans = v_allowed,
rstpEnables = rstp_enabled,
stpGuard = stp_guard,
accessPolicyType = access_policy,
macAllowedList = mac_allowed,
stickyMacAllowedList = sticky_mac_allowed,
stickyMacAllowListLimit = mac_allowed_limit,
poeEnabled = poe_enabled,
)
response = dashboard.switch.getDeviceSwitchPort(serial, port_id)
fields = ['portId', 'name', 'enabled', 'poeEnabled', 'type', 'vlan', 'voiceVlan', 'allowedVlans', 'isolationEnabled', 'rstpEnabled', 'stpGuard', 'accessPolicyType', 'macAllowedList', 'stickyMacAllowListLimit', 'linkNegotiation']
for field in fields:
print ('\n' + 'Here are the New Settings: ' + '\n')
print (f"{field}: {response[field]}")
input ('\n' + 'Press Enter to return to Main Menu: ')
main_menu()
elif validate in {'N', 'n'}:
input ('\n' + 'Darn, Ok lets try this again, press Enter: ')
clearconsole()
print ('\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()