Format Output from Meraki module

eroche
Getting noticed

Format Output from Meraki module

Good afternoon!

 

I am very new with Python and Meraki API. I am using the Meraki module and I would like to take the output of say the current configuration of a switch port. Then take that data and make look a little easier on the eyes and only show fields that are being used. Here is what I currently

 

def menu_config_port():
      clearconsole()
      sw_sn = input ('\n' + 'Enter Switch Serial Number (xxxx-xxxx-xxxx): ')
      port = input ('\n' + 'What port would you like to update? (1,2...48):  ')
      print ('\n' + 'Below is the current information for that port: ' + '\n')
      API_KEY = <key>
      dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)
      serial = (sw_sn)
      port_id = (port)

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

      print(response)

 

Response

 

{'portId': '1', 'name': '02-289 Phone', 'tags': [], 'enabled': True, 'poeEnabled': True, 'type': 'access', 'vlan': 442, 'voiceVlan': 90, 'allowedVlans': 'all', 'isolationEnabled': False, 'rstpEnabled': True, 'stpGuard': 'bpdu guard', 'linkNegotiation': 'Auto negotiate', 'portScheduleId': None, 'udld': 'Alert only', 'linkNegotiationCapabilities': ['Auto negotiate', '1 Gigabit full duplex (forced)', '100 Megabit (auto)', '100 Megabit half duplex (forced)', '100 Megabit full duplex (forced)', '10 Megabit (auto)', '10 Megabit half duplex (forced)', '10 Megabit full duplex (forced)'], 'accessPolicyType': 'Sticky MAC allow list', 'stickyMacAllowList': ['00:04:F2:7F:63:91'], 'stickyMacAllowListLimit': 1, 'daiTrusted': False, 'profile': {'enabled': False, 'id': '755478837491400755', 'iname': 'Human Resources_N_755478837491408550'}, 'module': {'model': None}, 'mirror': {'mode': 'Not mirroring traffic'}}

 

 

Don't need all this data just certain ones and would like to list form.

 

portId: 1

name: 02-289 Phone

 

etc.....


Any help would be greatly appriciated!

 

Thanks in Advance!

2 Replies 2
alemabrahao
Kind of a big deal
Kind of a big deal

I sent you a private message.

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.
mlefebvre
Building a reputation

Assuming its the same fields you want every time, here's a simple way to do it:

response = dashboard.switch.getDeviceSwitchPort('####-####-####',1)
attribs = ['portId','name','tags','enabled','poeEnabled','type','vlan']
for _key, _value in response.items():
    if _key in attribs:
        print('{}: {}'.format(_key,_value))

would give you this

portId: 1
name: None
tags: []
enabled: True
poeEnabled: True
type: trunk
vlan: 1

Get notified when there are additional replies to this discussion.