コード例 #1
0
def get_neighbor_list( recv_str ):

    # save the data to local array
    neighbor_list = []
    recv_tmp = ''
    tuple_count = 0
    recv_str_tail = 0

    # parse the recive message by cli type
    # init the data

    SystemName = 'System Name'
    SystemName_val = ''
    System_des = '  System description                : ' 
    Local_ifx = 'Local Intf'
    Local_ifx_val = ''
    Local_ifx_tail = ']\r\n'
    PortID = 'Port ID'
    PortID_val = ''
    Port_des = '  Port description                  :'
    Capability = 'Capability'
    Capability_val = ''
    
    Agingtime = 'Aging-time'
    Agingtime_val = ''
    Neighbor_index_val = ''
    ChassisID_type_val = ''
    ChassisID_val = ''
    
    while True:

        SystemName_val = switch_api.get_val_by_str(SystemName, System_des, recv_tmp)
        SystemName_val = SystemName_val[:-2]
        #print 'get_lldp_neighbor SystemName_val = %s \r\n' % SystemName_val,

        # get val message by search string in revice message
        Local_ifx_val = switch_api.get_val_by_str(Local_ifx, Local_ifx_tail, recv_tmp)
        if len(Local_ifx_val) == 0:
            print'get_lldp_neighbor can not find Local_ifx_val !\r\n'
        #print 'get_lldp_neighbor Local_ifx_val = %s \r\n' % Local_ifx_val,
    
        PortID_val = switch_api.get_val_by_str(PortID, Port_des, recv_tmp)
        PortID_val = PortID_val[:-2]
        #print 'get_lldp_neighbor PortID_val = %s \r\n' % PortID_val,

        recv_str = recv_str[recv_str_tail:-1]
        #print '\r\n#################################################### \r\n'
        #print 'get_lldp_neighbor recv_str 3 = %s \r\n' % recv_str,
        #print '\r\n#################################################### \r\n'
        #print 'get_lldp_neighbor recv_str_head = %d \r\n' % recv_str_tail,

        if len(Local_ifx_val) > 0:
            ifx = Local_ifx_val
        #print 'get_lldp_neighbor ifx = %s \r\n' % ifx,
        neighbor_tuple = (ifx, Neighbor_index_val, ChassisID_type_val, ChassisID_val)
        neighbor_list.insert( tuple_count, neighbor_tuple )
        tuple_count = tuple_count +1

        continue

    return neighbor_list
コード例 #2
0
def get_neighbor_list_details( recv_str ):

    # save the data to local array
    neighbor_list = []
    recv_tmp = ''
    tuple_count = 0
    recv_str_tail = 0

    # parse the recive message by cli type
    # init the data
    Local_ifx = 'LLDP neighbor-information of port ['
    Local_ifx_val = ''
    Local_ifx_tail = ']\r\n'
    
    Neighbor_index = 'Neighbor index                    : '
    Neighbor_index_val = ''

    Device_type = '  Device type                       : '
    
    ChassisID_type = '  Chassis ID type                   : '
    ChassisID_type_val = ''
    
    ChassisID = '  Chassis ID                        : '
    ChassisID_val = ''
    
    SystemName = '  System name                       : '
    SystemName_val = ''
    
    System_des = '  System description                : '
    
    PortID_type = '  Port ID type                      : '
    PortID_type_val = ''
    
    PortID = 'Port ID                           : '
    PortID_val = ''
    
    Port_des = '  Port description                  :'
    
    Port_VLANID = 'Port VLAN ID                      : '
    Port_VLANID_val = ''
    
    PPVID = '  Port and protocol VLAN ID(PPVID)  : '
    UnitEnd = '  Maximum frame Size                :'

    while True:

        ret = recv_str.find(UnitEnd)
        if ret == -1:
            break;
        recv_str_tail = ret + len(UnitEnd)
        recv_tmp = recv_str[0:recv_str_tail]
        # get val message by search string in revice message
        Local_ifx_val = switch_api.get_val_by_str(Local_ifx, Local_ifx_tail, recv_tmp)
        if len(Local_ifx_val) == 0:
            LOG.debug("get_lldp_neighbor can not find Local_ifx_val !")

        Neighbor_index_val = switch_api.get_val_by_str(Neighbor_index, Device_type, recv_tmp)
        if len(Neighbor_index_val) == 0:
            LOG.error("get_lldp_neighbor Neighbor_index_val not find = %s ",Neighbor_index_val)
            break
        Neighbor_index_val = Neighbor_index_val[:-2] 
    
        ChassisID_type_val = switch_api.get_val_by_str(ChassisID_type, ChassisID, recv_tmp)
        ChassisID_type_val = ChassisID_type_val[:-2]
    
        ChassisID_val = switch_api.get_val_by_str(ChassisID, SystemName, recv_tmp)
        ChassisID_val = ChassisID_val[:ChassisID_val.find('\r\n')]
    
        SystemName_val = switch_api.get_val_by_str(SystemName, System_des, recv_tmp)
        SystemName_val = SystemName_val[:-2]
    
        PortID_type_val = switch_api.get_val_by_str(PortID_type, PortID, recv_tmp)
        PortID_type_val = PortID_type_val[:PortID_type_val.find('\r\n')]
    
        PortID_val = switch_api.get_val_by_str(PortID, Port_des, recv_tmp)
        PortID_val = PortID_val[:PortID_val.find('\r\n')]
    
        Port_VLANID_val = switch_api.get_val_by_str(Port_VLANID, PPVID, recv_tmp)
        Port_VLANID_val = Port_VLANID_val[:-2]

        recv_str = recv_str[recv_str_tail:-1]
        LOG.debug("get_lldp_neighbor recv_str 3 = %s \r\n ",recv_str)

        if len(Local_ifx_val) > 0:
            ifx = Local_ifx_val
        neighbor_tuple = (ifx, Neighbor_index_val, PortID_type_val, PortID_val)
        neighbor_list.insert( tuple_count, neighbor_tuple )
        tuple_count = tuple_count +1
        LOG.debug("get_lldp_neighbor serach = %d times\r\n ",tuple_count)
        continue

    return neighbor_list