Differentiate switch ports

Solved
WellyHartanto
Here to help

Differentiate switch ports

Hi,
 
I need to collect information on all switch ports in my organization (divided into several networks).
Based on this https://api.meraki.com/api/v1/devices/${deviceSerial}/switch/ports, I ran a test script against my 24-port switch.
However, it returns 30 data of ports, which to my understanding are the 24 ethernet ports, 4 SFP ports, and 2 stack ports.
But I'm stuck on finding out how to differentiate between the ethernet ports, SFP ports, and the stack ports as my requirements exclude the stack ports.
 
Anyone can help me with this?
Thank you!
1 Accepted Solution
sungod
Head in the Cloud

In some scripts I use a look-up table of switch-specific parameters that aren't accessible via the API (or weren't when the script was written) such as PoE capacity, you could do the same for ports, it only needs updating when a new switch model comes out.

 

The ports are returned with normal first, then trunk ports, then stack ports, if you only have MS1xx/2xx family switches (it can be more complicated for other MS series), you could use a rule...

 

If port count is 30 (24+4+2) or 54 (48+4+2), you know the last two are stack ports. The ones without stack ports will not have 30 or 54 ports.

 

View solution in original post

6 Replies 6
Amit_pal
Getting noticed

You will have to parse the data and only include Ethernet and SPF Ports ..

 

If you don't mind, can you please post the API call get request response here, i will try to write code for you

Hi Amit,

 

I can show you this with a very basic python script.

import meraki

# Defining your API key as a variable in source code is discouraged.
# This API key is for a read-only docs-specific environment.
# In your own code, use an environment variable as shown under the Usage section
# @ https://github.com/meraki/dashboard-api-python/

API_KEY = 'abcdasdasdsadasdasda12333333'

dashboard = meraki.DashboardAPI(API_KEY)

serial = 'Q2GW-XXXX-XXXX'

ports = dashboard.switch.getDeviceSwitchPorts(
    serial
)

print(len(ports)) #This will return 30 if we run it against a 24-port switch

for port in ports:
    print(port)

 

The port 29 and 30 information that fetched from above script is as simple as:

{'portId': '30', 'name': None, 'tags': ['sp_all'], 'enabled': True, 'poeEnabled': False, 'type': 'trunk', 'vlan': 1, 'voiceVlan': None, 'allowedVlans': 'all', 'isolationEnabled': False, 'rstpEnabled': True, 'stpGuard': 'disabled', 'linkNegotiation': 'Auto negotiate', 'portScheduleId': None, 'udld': 'Alert only', 'linkNegotiationCapabilities': ['Auto negotiate'], 'accessPolicyType': 'Open', 'daiTrusted': False, 'profile': {'enabled': False, 'id': '', 'iname': None}, 'stormControlEnabled': True}

 

Is there anything I can use if I want only ethernet and SFP ports?

Thank you!

Amit_pal
Getting noticed

for Port in Ports:
Count = 1
while Count < len(Ports)-1:
print(Port)
Count+=1

See if this works , if not please share get response for all 30 ports
sungod
Head in the Cloud

In some scripts I use a look-up table of switch-specific parameters that aren't accessible via the API (or weren't when the script was written) such as PoE capacity, you could do the same for ports, it only needs updating when a new switch model comes out.

 

The ports are returned with normal first, then trunk ports, then stack ports, if you only have MS1xx/2xx family switches (it can be more complicated for other MS series), you could use a rule...

 

If port count is 30 (24+4+2) or 54 (48+4+2), you know the last two are stack ports. The ones without stack ports will not have 30 or 54 ports.

 

Hi @sungod 

 

Indeed, the workaround will suffice my requirements, thank you!

 

But I still believe that somehow the API should provide the ability for us to differentiate the port types; there may be some scenarios on the usage.

Btw, could you please share your lookup table? I and the others may find it useful.

 

Here's one, the LUT is wrapped in a simple function, so calling poeb(model) returns the PoE budget.

 

Note in this script I want the PoE budget as a string, it's trivial to tweak to return a number instead.

 

 

def poeb(model):
    poebudgets = {
        "MS22P": 380,
        "MS42P": 380,
        "MS120-8LP": 67,
        "MS120-8FP": 124,
        "MS120-24P": 370,
        "MS120-48LP": 370,
        "MS120-48FP": 740,
        "MS125-24P": 370,
        "MS125-48LP": 370,
        "MS125-48FP": 740,
        "MS130-8P": 120,
        "MS130-8X": 120,
        "MS130-12X": 240,
        "MS130-24P": 370,
        "MS130-24X": 370,
        "MS130-48P": 740,
        "MS130-48X": 740,
        "MS130R-8P": 240,
        "MS210-24P": 370,
        "MS210-48LP": 370,
        "MS210-48FP": 740,
        "MS220-8P": 124,
        "MS220-24P": 370,
        "MS220-48LP": 370,
        "MS220-48FP": 740,
        "MS225-24P": 370,
        "MS225-48LP": 370,
        "MS225-48FP": 740,
        "MS250-24P": 370,
        "MS250-48LP": 370,
        "MS250-48FP": 740,
        "MS320-24P": 370,
        "MS320-48LP": 370,
        "MS320-48FP": 740,
        "MS350-24P": 370,
        "MS350-48LP": 370,
        "MS350-48FP": 740,
        "MS350-24X": 740,
        "MS355-24X": 740,
        "MS355-48X": 740,
        "MS355-24X2": 740,
        # the MS390 budget is based on the default primary PSU only, so assumes worst case scenario for estimating PoE headroom
        "MS390-24P": 445,
        "MS390-24U": 830,
        "MS390-24UX": 560,
        "MS390-48P": 437,
        "MS355-48U": 822,
        "MS390-48UX": 490,
        "MS390-48UX2": 645,
        # the C9300 budget is based on the default primary PSU only, so assumes worst case scenario for estimating PoE headroom
        "C9300-24P-M": 445,
        "C9300-24U-M": 830,
        "C9300-24UX-M": 560,
        "C9300-48P-M": 437,
        "C9300-48U-M": 822,
        "C9300-48UXM-M": 490,
        "C9300-48UN-M": 645,

    }
    if model in poebudgets:
        return str(poebudgets[model])
    else:
        return "0"

 

 

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.