Skip to content
Advertisement

I would like to check physical ports redunducy check with python

  1. would like to check physical network ports with python scripts

  2. ports information as following, Python scripts can check if ServerID has 2 or more physical network lines to differents network devices.

ServerID,NetworkID,Port name

Server_1,NW_1,ge-0/0/8

Server_2,NW_2,ge-0/0/5

Server_3,NW_3,Ethernet7/15

Server_4,NW4,ae4

Server_4,NW4,ge-2/2/0

Server_4,NW4,ge-2/2/1

Server_4,NW4,ge-2/2/2

Server_4,NW4,ge-2/3/0

Server_4,NW4,ge-2/3/1

Server_10,NW5,ae4

Server_10,NW5,ge-2/2/0

Server_10,NW5,ge-2/2/1

Server_10,NW5,ge-2/2/2

Server_10,NW5,ge-2/3/0

Server_10,NW5,ge-2/3/1

Server_16,NW6,ae5

Server_16,NW6,ge-2/2/3

Server_16,NW6,ge-2/2/4

Server_16,NW6,ge-2/2/5

Server_16,NW6,ge-2/3/2

Server_16,NW6,ge-2/3/3

Server_22,NW7,ae5

Server_22,NW7,ge-2/2/3

Server_22,NW7,ge-2/2/4

Server_22,NW7,ge-2/2/5

Server_22,NW7,ge-2/3/2

Server_22,NW7,ge-2/3/3

Server_28,NW8,ge-8/0/0

Server_28,NW9,ge-8/0/0

Server_30,NW10,ge-0/0/2

Server_30,NW11,ge-0/0/3

Server_32,NW12,ge8

Server_32,NW13,ge-0/0/2

Server_34,NW13,ge-0/0/3

Server_35,NW14,Ethernet1/3

Server_35,NW14,Ethernet1/4

Server_35,NW14,Ethernet1/5

Server_35,NW14,Ethernet1/6

Server_35,NW14,port-channel2

Server_35,NW15,xg16

Server_41,NW16,Ethernet1/3

Server_41,NW16,Ethernet1/4

Server_41,NW16,Ethernet1/5

Server_41,NW16,Ethernet1/6

Server_41,NW16,port-channel2

Server_41,NW17,xg16

Server_16,NW6,ae5

Server_16,NW6,ge-2/2/3

Server_16,NW6,ge-2/2/4

Server_16,NW6,ge-2/2/5

Server_16,NW6,ge-2/3/2

Server_16,NW6,ge-2/3/3 Server_22,NW7,ae5

Server_22,NW7,ge-2/2/3

Server_22,NW7,ge-2/2/4

Server_22,NW7,ge-2/2/5

Server_22,NW7,ge-2/3/2

Server_22,NW7,ge-2/3/3

Server_28,NW8,ge-8/0/0

Server_28,NW9,ge-8/0/0

Server_30,NW10,ge-0/0/2

Server_30,NW11,ge-0/0/3

Server_32,NW12,ge8

Server_32,NW13,ge-0/0/2

Server_34,NW13,ge-0/0/3

Server_35,NW14,Ethernet1/3

Server_35,NW14,Ethernet1/4

Server_35,NW14,Ethernet1/5

Server_35,NW14,Ethernet1/6

Server_35,NW14,port-channel2

Server_35,NW15,xg16

Server_41,NW16,Ethernet1/3

Server_41,NW16,Ethernet1/4

Server_41,NW16,Ethernet1/5

Server_41,NW16,Ethernet1/6

Server_41,NW16,port-channel2

Server_41,NW17,xg16

  1. I have already tried with -1)-2) etc. but cannot filter out single-line connected servers. -1) df.set_index([‘ServerID’, ‘NetwroID’]) -2) df.groupby([‘ServerID’, ‘NetwroID’])

  2. expected results

=> following servers aren’t redundant with more 2 physical lines and network devices.

Server_1,NW_1,ge-0/0/8

Server_2,NW_2,ge-0/0/5

Server_3,NW_3,Ethernet7/15

Server_41,NW16,Ethernet1/3

Server_41,NW16,Ethernet1/4

Server_41,NW16,Ethernet1/5

Server_41,NW16,Ethernet1/6

Server_41,NW16,port-channel2

Server_41,NW17,xg16

  1. any good idea would be appreciated.

code
import pandas as pd

df = pd.read_csv(‘ports_analysis_example.cvs’)

df_groupby_1=df.groupby([‘Server_ID’,’Network_ID’]).count()

df_groupby_1

I would like to print out redundant problematic servers from following DataFrame.

Server_ID Network_ID Port_name

Server_1 NW1 1

Server_10 NW5 6

Server_16 NW6 6

Server_2 NW2 1

Server_22 NW7 6

Server_28 NW8 1 redundant network

        NW9 1

Server_3 NW3 1

Server_30 NW10 1 redundant network

        NW11    1

Server_32 NW12 1 redundant network

        NW13    1

Server_34 NW13 1

Server_35 NW14 5

        NW15    1

Server_4 NW4 6

Server_41 NW16 5

        NW17    1

Advertisement

Answer

import pandas as pd

import csv 

df = pd.read_csv('all_port_connections_informaion_0819_csv.csv', encoding = 'cp949')

ports_analysis=df.set_index(['connected_serverID','serverID','ports'], drop=False)

csv_data=open('all_port_connections_informaion_0819_csv.csv')

data=csv.reader(csv_data)

nets = {}

k_list = []

print(k_list)

for line in data:

    key = line[8],line[4]

    if key not in nets:
        nets[key] = set()
    nets[key].add( line[0] )

for k, v in nets.items():

    if len(v) <2:
        if k == ("connected_serverID", "ports") :
            #print(k, "single nets:", v)
            continue
        k_list.extend([k])

printout_k_list = [k_list[i][0] for i in range(len(k_list))]

seted_printout_klist=list(set(printout_k_list))

writer = pd.ExcelWriter('improved_nets_singled_device.xlsx')
ports_analysis.loc[(seted_printout_klist[i] for i in range(len(seted_printout_klist)))].to_excel(writer, 'Sheet1')
writer.save()
Advertisement