def __discoverInterfaceStates(self, interface): ''' Discover interface states - aliases and linked IPs Interface -> list(_InterfaceState)''' logger.debug("Discover interface states for %s" % interface) interfaceStates = [] try: for state in self.getStatesOfInterfaces(): if (self.__isAliasedStateOf(interface, state) or state.interface.name == interface.name): if interface.name == state.interface.name: logger.debug('Found state %s, ip %s ' % (interface, state.ip)) ips = state.ip if ips: for ip in ips: self.__networking().addIpAndNetwork(ip.ip, ip.netmask, interface.name) else: aliasInterface = None try: aliasInterface = self.__getOrAddInterface(state.interface) if (not aliasInterface._hasRole(AliasRole)): aliasRole = AliasRole() aliasRole.parentInterface = interface aliasInterface._addRole(aliasRole) logger.debug('Found alias %s, ip %s ' % (aliasInterface, state.ip)) logger.debug('Adding new IP address to interface %s, %s' %(aliasInterface.name, state.ip)) ips = state.ip if ips: for ip in ips: self.__networking().addIpAndNetwork(ip.ip, ip.netmask, aliasInterface.name) except Exception, e: logger.warnException('Failed to add alias for interface %s' % aliasInterface) interfaceStates.append(state) except Exception, e: logger.warn(str(e))
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 __discoverInterfaceStates(self, interface): ''' Discover interface states - aliases and linked IPs Interface -> list(_InterfaceState)''' logger.debug("Discover interface states for %s" % interface) interfaceStates = [] try: for state in self.getStatesOfInterfaces(): if (self.__isAliasedStateOf(interface, state) or state.interface.name == interface.name): if interface.name == state.interface.name: logger.debug('Found state %s, ip %s ' % (interface, state.ip)) ips = state.ip if ips: for ip in ips: self.__networking().addIpAndNetwork( ip.ip, ip.netmask, interface.name) else: aliasInterface = None try: aliasInterface = self.__getOrAddInterface( state.interface) if (not aliasInterface._hasRole(AliasRole)): aliasRole = AliasRole() aliasRole.parentInterface = interface aliasInterface._addRole(aliasRole) logger.debug('Found alias %s, ip %s ' % (aliasInterface, state.ip)) logger.debug( 'Adding new IP address to interface %s, %s' % (aliasInterface.name, state.ip)) ips = state.ip if ips: for ip in ips: self.__networking().addIpAndNetwork( ip.ip, ip.netmask, aliasInterface.name) except Exception, e: logger.warnException( 'Failed to add alias for interface %s' % aliasInterface) interfaceStates.append(state) except Exception, e: logger.warn(str(e))