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
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
def discoverLinkAggregations(self, aixNetworking=None): ''' Discover networking related to link aggregations topology only list(networking.Interfaces) or None -> networking.UnixNetworking''' logger.debug("Discover Link Aggregation interfaces") aixNetworking = aixNetworking or UnixNetworking() nics = self.discoverAvailableInterfaces() nameToNic = {} map(lambda nic, nameToNic=nameToNic: nameToNic.update({nic.name: nic}), nics) # filter only link aggregations linkAggregations = filter( lambda nic: str(nic.description).lower().count("etherchannel"), nics) for interface in linkAggregations: logger.debug("Found LA: %s" % interface) nic = aixNetworking.getInterfaceByName(interface.name) if not nic: nic = interface aixNetworking.addInterface(nic) aggregationRole = AggregationRole() nic._addRole(aggregationRole) try: names = self._getMemberNamesOfLinkAggr(nic) logger.debug( 'Gather aggregation information for names %s of %s' % (names, nic)) for name in names: aggregatedInterface = aixNetworking.getInterfaceByName( name) if not aggregatedInterface: aggregatedInterface = nameToNic.get(name) if not aggregatedInterface: index = self._getDevNameAndIndex(name)[1] aggregatedInterface = Interface(name=name, index=index, mac=index) aixNetworking.addInterface(aggregatedInterface) aggregatedRole = _AggregatedRole() aggregatedRole.setAggregatingInterface(nic) aggregatedInterface._addRole(aggregatedRole) if not netutils.isValidMac( aggregatedInterface.mac) and netutils.isValidMac( nic.mac): aggregatedInterface.mac = nic.mac logger.debug('aggregated %s' % aggregatedInterface) aggregationRole.addInterface(aggregatedInterface) except Exception, e: logger.warn(str(e)) self._gatherIpInformation(nic, aixNetworking)
def __discoverClimInterface(self, climName): """ @types: string -> None @raise ValueError: when command "gtacl -cv "climcmd %s /sbin/ifconfig -a % <clim_name>" gives no output or fails """ cmd = "climcmd %s /sbin/ifconfig -a" % climName cmdOutput = self.__shell.execCmd('gtacl -cv "%s"' % cmd) if not cmdOutput or self.__shell.getLastCmdReturnCode() != 0: raise ValueError('Failed to get CLIM') (header, interfaceData) = cmdOutput.split(cmd) if header and interfaceData: interfacesByName = {} matches = ShellDiscoverer.__INTERFACE_REGEXP.findall(interfaceData) for match in matches: name = match[0] uniqueName = "%s.%s" % (climName, match[0]) mac= match[1] if netutils.isValidMac(mac): interface = Interface(netutils.parseMac(mac), uniqueName) parentInterfaceName = self.__getParentInterfaceName(name) if parentInterfaceName and interfacesByName.has_key(parentInterfaceName): parentInterface = interfacesByName[parentInterfaceName] aliasRole = AliasRole() aliasRole.parentInterface = parentInterface interface._addRole(aliasRole) self.__networking.addInterface(interface) interfacesByName[name] = interface matches = ShellDiscoverer.__INTERFACE_AND_IP_REGEXP.findall(interfaceData) for match in matches: name = match[0] ip = match[2] netmask = match[4] if netutils.isValidIp(ip) and netutils.isValidIp(netmask): if interfacesByName.has_key(name): interface = interfacesByName[name] self.__networking.addIpAndNetwork(ip, netmask, interface.name) else: self.__networking.addIpAndNetwork(ip, netmask) else: logger.warn('Unrecognized output') logger.reportWarning("Failed to discover CLIM network interfaces")
def __parseInterfacesInIoscanOutput(self, ioscanOutput): 'str -> map(str, networking.Interface)' nameToInterfaces = {} for line in _split(ioscanOutput): lanProperties = line.split(":") if line.count(":lan:") and len(lanProperties) > 16: hardwarePath = lanProperties[10] try: interfaceIndex = int(lanProperties[12]) except: logger.warn('Cannot parse interface index from value: %s' % lanProperties[12]) else: description = lanProperties[17] nic = Interface(description = description, index = interfaceIndex, mac = interfaceIndex) hpuxRole = _HpuxInterfaceRole(hardwarePath = hardwarePath) nic._addRole(hpuxRole) name = self.__getInterfaceName(nic) nic.name = name nameToInterfaces[name] = nic return nameToInterfaces
def discoverLinkAggregations(self, aixNetworking = None): ''' Discover networking related to link aggregations topology only list(networking.Interfaces) or None -> networking.UnixNetworking''' logger.debug("Discover Link Aggregation interfaces") aixNetworking = aixNetworking or UnixNetworking() nics = self.discoverAvailableInterfaces() nameToNic = {} map(lambda nic, nameToNic = nameToNic: nameToNic.update({nic.name : nic}), nics) # filter only link aggregations linkAggregations = filter(lambda nic: str(nic.description).lower().count("etherchannel"), nics) for interface in linkAggregations: logger.debug("Found LA: %s" % interface) nic = aixNetworking.getInterfaceByName(interface.name) if not nic: nic = interface aixNetworking.addInterface(nic) aggregationRole = AggregationRole() nic._addRole(aggregationRole) try: names = self._getMemberNamesOfLinkAggr(nic) logger.debug('Gather aggregation information for names %s of %s' % (names, nic)) for name in names: aggregatedInterface = aixNetworking.getInterfaceByName(name) if not aggregatedInterface: aggregatedInterface = nameToNic.get(name) if not aggregatedInterface: index = self._getDevNameAndIndex(name)[1] aggregatedInterface = Interface(name = name, index = index, mac = index) aixNetworking.addInterface(aggregatedInterface) aggregatedRole = _AggregatedRole() aggregatedRole.setAggregatingInterface(nic) aggregatedInterface._addRole(aggregatedRole) if not netutils.isValidMac(aggregatedInterface.mac) and netutils.isValidMac(nic.mac): aggregatedInterface.mac = nic.mac logger.debug('aggregated %s' % aggregatedInterface) aggregationRole.addInterface(aggregatedInterface) except Exception, e: logger.warn(str(e)) self._gatherIpInformation(nic, aixNetworking)
def __parseInterfacesInIoscanOutput(self, ioscanOutput): 'str -> map(str, networking.Interface)' nameToInterfaces = {} for line in _split(ioscanOutput): lanProperties = line.split(":") if line.count(":lan:") and len(lanProperties) > 16: hardwarePath = lanProperties[10] try: interfaceIndex = int(lanProperties[12]) except: logger.warn('Cannot parse interface index from value: %s' % lanProperties[12]) else: description = lanProperties[17] nic = Interface(description=description, index=interfaceIndex, mac=interfaceIndex) hpuxRole = _HpuxInterfaceRole(hardwarePath=hardwarePath) nic._addRole(hpuxRole) name = self.__getInterfaceName(nic) nic.name = name nameToInterfaces[name] = nic return nameToInterfaces