-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy path01_get_device_ports.py
executable file
·32 lines (26 loc) · 1.08 KB
/
01_get_device_ports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
from login import login
DEVICES=["212.1.10.1", ]
def get_ports(apic, deviceId):
print (deviceId)
ports = apic.interface.getInterfaceByDeviceId(deviceId=deviceId)
return [ p for p in ports.response if p.interfaceType == "Physical"]
def get_port_count(apic, uuid):
ports = get_ports(apic, uuid)
up = len([ p for p in ports if p.status == "up"])
return up, len(ports)
def apic_port_report(apic):
for deviceip in DEVICES:
network_device = apic.networkdevice.getNetworkDeviceByIp(ipAddress=deviceip)
active_ports, total_ports = get_port_count(apic, network_device.response.id)
print('{ip:<16s} {name:<16s} {serial:12s} {active_ports:n} {total_ports:n}'.format(
ip=network_device.response.managementIpAddress,
name=network_device.response.hostname,
serial=network_device.response.serialNumber,
active_ports=active_ports,
total_ports=total_ports
))
if __name__ == "__main__":
# connect to APIC using the login module
apic = login()
apic_port_report(apic)