예제 #1
0
    def __parseInterfacesInLanscanOutput(self, output):
        '''str -> map(str, networking.Interface)

        # Expected format for HP-UX lanscan command --
        #0/0/0/1/0 0x00306E4989E7 0    UP    lan0 snap0       1    ETHER       Yes   119
        #0/0/12/0/0 0x00306E4C999B 1    UP    lan1 snap1       2    ETHER       Yes   119
        #0/0/14/0/0 0x00306E4A4773 2    UP    lan2 snap2       3    ETHER       Yes   119
        '''
        nameToInterface = {}

        #The first two lines are skipped because they contain output header
        for line in output.split('\n'):
            properties = line.strip().split()
            if len(properties) > 3:
                status = properties[3]
                # get only  live interfaces with valid hardware path
                if status.lower() == 'up':
                    hwPath = properties[0]
                    name = properties[4]
                    index = self.__getDevNameAndIndex(name)[1]
                    # check whether parsing is correct
                    try:
                        if index == int(properties[2]):
                            # strip 0x from the mac
                            macStr = properties[1]
                            mac = self.__parseLanscanMacString(macStr) or index
                            hpuxRole = _HpuxInterfaceRole(hardwarePath = hwPath)
                            nic = Interface(name = name, index = index, mac = mac)
                            if self.__getSystemVersion() in ['10.20']:
                                nic.serviceIndex = properties[6]
                            nic._addRole(hpuxRole)
                            nameToInterface[name] = nic
                    except:
                        logger.warnException('Wrong line format: %s' % line)
        return nameToInterface
예제 #2
0
    def __parseInterfacesInLanscanOutput(self, output):
        '''str -> map(str, networking.Interface)

        # Expected format for HP-UX lanscan command --
        #0/0/0/1/0 0x00306E4989E7 0    UP    lan0 snap0       1    ETHER       Yes   119
        #0/0/12/0/0 0x00306E4C999B 1    UP    lan1 snap1       2    ETHER       Yes   119
        #0/0/14/0/0 0x00306E4A4773 2    UP    lan2 snap2       3    ETHER       Yes   119
        '''
        nameToInterface = {}

        #The first two lines are skipped because they contain output header
        for line in output.split('\n'):
            properties = line.strip().split()
            if len(properties) > 3:
                status = properties[3]
                # get only  live interfaces with valid hardware path
                if status.lower() == 'up':
                    hwPath = properties[0]
                    name = properties[4]
                    index = self.__getDevNameAndIndex(name)[1]
                    # check whether parsing is correct
                    try:
                        if index == int(properties[2]):
                            # strip 0x from the mac
                            macStr = properties[1]
                            mac = self.__parseLanscanMacString(macStr) or index
                            hpuxRole = _HpuxInterfaceRole(hardwarePath=hwPath)
                            nic = Interface(name=name, index=index, mac=mac)
                            if self.__getSystemVersion() in ['10.20']:
                                nic.serviceIndex = properties[6]
                            nic._addRole(hpuxRole)
                            nameToInterface[name] = nic
                    except:
                        logger.warnException('Wrong line format: %s' % line)
        return nameToInterface