def buildTopology(self): ''' Construct as400 node topology @types AS400Client -> ObjectStateHolderVector ''' myvec = ObjectStateHolderVector() ip_address = self.__client.getIpAddress() # create as400 agent OSH interfaceList = self.__interfacesInfo as400HostOsh = None if interfaceList and len(interfaceList) > 0: # Create as400 CIT try: # Get the host_key - lowest mac address of the valid interface list as400HostOsh = modeling.createCompleteHostOSHByInterfaceList('as400_node', interfaceList, 'OS400', self.__sysInfo.hostName) as400HostOsh.setAttribute('host_model', self.__sysInfo.hostModel) as400HostOsh.setAttribute('host_serialnumber', self.__sysInfo.hostSerialNum) as400HostOsh.setAttribute('host_osversion', self.__sysInfo.hostOSVersion) as400HostOsh.setAttribute('host_vendor', 'IBM') myvec.add(as400HostOsh) as400Osh = self.__createAS400AgentOSH(ip_address) as400Osh.setAttribute('credentials_id', self.__client.getCredentialId()) as400Osh.setContainer(as400HostOsh) myvec.add(as400Osh) except: logger.warn('Could not find a valid MAC addresses for key on ip : ', self.__client.getIpAddress()) # add all interfaces to the host if as400HostOsh is not None: for interface in interfaceList: interfaceOsh = modeling.createInterfaceOSH(interface.macAddress, as400HostOsh, interface.description, interface.interfaceIndex, interface.type, interface.adminStatus, interface.adminStatus, interface.speed, interface.name, interface.alias, interface.className) ips = interface.ips masks = interface.masks if interfaceOsh: myvec.add(interfaceOsh) if ips and masks: for i in xrange(len(ips)): ipAddress = ips[i] ipMask = masks[i] ipProp = modeling.getIpAddressPropertyValue(ipAddress, ipMask, interface.dhcpEnabled, interface.description) ipOSH = modeling.createIpOSH(ipAddress, ipMask, ipProp) myvec.add(ipOSH) myvec.add(modeling.createLinkOSH('containment', as400HostOsh, ipOSH)) netOSH = modeling.createNetworkOSH(ipAddress, ipMask) myvec.add(netOSH) myvec.add(modeling.createLinkOSH('member', netOSH, as400HostOsh)) myvec.add(modeling.createLinkOSH('member', netOSH, ipOSH)) myvec.add(modeling.createLinkOSH('containment', interfaceOsh, ipOSH)) else: logger.warn('Parent host wasn\'t created. No interfaces will be reported.') return myvec
def getIPNetworkMemebrList(ipList, netmaskList, dnsname='', dhcpEnabled=None, description=None): _ipList = [] _maskList = [] _ipOshList = [] vec = ObjectStateHolderVector() if ipList: _ipList = str(ipList).split(',') if netmaskList: _maskList = str(netmaskList).split(',') for i in range(len(_ipList)): try: try: ip = ip_addr.IPAddress(_ipList[i]) mask = _maskList[i] if ip.is_loopback or ip.is_unspecified: # invalid or local ip raise ValueError() except: logger.debug('ignoring invalid ip=%s' % ip) continue # ip is valid and not local (i.e. 0.0.0.0, 127.0.0.1) # create an IP ipProps = modeling.getIpAddressPropertyValue(str(ip), mask, dhcpEnabled, description) ipOSH = modeling.createIpOSH(ip, mask, None, ipProps) vec.add(ipOSH) if ip.version != 6: # create network netOSH = modeling.createNetworkOSH(str(ip), mask) link = modeling.createLinkOSH('member', netOSH, ipOSH) vec.add(netOSH) vec.add(link) except: logger.errorException("Failed parsing IP: ", ip) return vec
def build(self, interfaceName=None): ipProperties = modeling.getIpAddressPropertyValue( str(self.ip), self.netmask, self.hasFlag(Ip.FLAG_DHCP), interfaceName ) self.osh = modeling.createIpOSH(self.ip, self.netmask, None, ipProperties)
def buildInterfaces(self): """ We create and report such topology for destination ip in following cases: |host is complete | host is incomplete| ip is virtual |all except NTCMD |only virtual ip | ip is not virtual |all topology |all topology | """ try: self.hostOsh = modeling.createCompleteHostOSHByInterfaceList('nt', self.interfacesList, self.hostDo.hostOsName, self.hostDo.hostName, self.hostDo.lastBootDate, self.hostCmdbId, self.hostKey, self.hostMacs, self.ucmdbVersion) if self.hostDo.ipIsVirtual: logger.warn('IP: ', self.destinationIp, ' does not appear in the result buffer of the interfaces output - assuming virtual') logger.warn('Host topology will be reported without NTCMD CI.') except: self.hostOsh = modeling.createHostOSH(str(self.destinationIp), 'nt', self.hostDo.hostOsName, self.hostDo.hostName) logger.warn('Could not find a valid MAC address for key on ip : ', self.destinationIp) if self.hostDo.ipIsVirtual: logger.warn('IP: ', self.destinationIp, ' does not appear in the result buffer of the interfaces output - assuming virtual') logger.warn('Only IP marked as virtual will be reported.') self.resultVector.clear() virtualIpOsh = modeling.createIpOSH(str(self.destinationIp)) virtualIpOsh.setBoolAttribute('isvirtual', 1) self.resultVector.add(virtualIpOsh) self.hostOsh = None return #process interfaces looking for nic teaming interfaces. #looking up for interfaces with same mac macToInterfaceListMap = {} for interface in self.interfacesList: intList = macToInterfaceListMap.get(interface.macAddress, []) intList.append(interface) macToInterfaceListMap[interface.macAddress] = intList #checking if interface has a Team key word in it's name for interfaceList in macToInterfaceListMap.values(): if interfaceList and len(interfaceList) < 2: continue for interf in interfaceList: if (interf.name and re.search('[Tt]eam', interf.name)) or (interf.description and re.search('[Tt]eam', interf.description)): #picking up interface with max interfaceIndex value and setting it aggregate role try: iface = reduce(lambda x,y: int(x.interfaceIndex) > int(y.interfaceIndex) and x or y, interfaceList) iface.role = 'aggregate_interface' except: logger.debugException('') interfacesVector = modeling.createInterfacesOSHV(self.interfacesList, self.hostOsh) roleManager = InterfaceRoleManager() for interface in self.interfacesList: interfaceOsh = interface.getOsh() if not interfaceOsh: continue roleManager.assignInterfaceRole(interface) self.resultVector.add(interfaceOsh) if interface.ips: for ipIndex in range(len(interface.ips)): ipAddress = interface.ips[ipIndex] ipMask = None try: ipMask = interface.masks[ipIndex] except: pass if ipAddress.is_loopback or ipAddress.is_unspecified: logger.debug('Invalid IP retrieved %s. Skipping.' % ipAddress) continue ipProp = modeling.getIpAddressPropertyValue(str(ipAddress), ipMask, interface.dhcpEnabled, interface.description) ipOsh = modeling.createIpOSH(ipAddress, ipMask, None, ipProp) if self.hostDo.ipIsVirtual and ipAddress == self.destinationIp: ipOsh.setBoolAttribute('isvirtual', 1) self.resultVector.add(ipOsh) self.resultVector.add(modeling.createLinkOSH('containment', self.hostOsh, ipOsh)) self.resultVector.add(modeling.createLinkOSH('containment', interfaceOsh, ipOsh)) if ipAddress.version != 6: networkOsh = modeling.createNetworkOSH(str(ipAddress), ipMask) self.resultVector.add(networkOsh) self.resultVector.add(modeling.createLinkOSH('member', networkOsh, ipOsh)) self.resultVector.add(modeling.createLinkOSH('member', networkOsh, self.hostOsh))
def buildInterfaces(self): """ We create and report such topology for destination ip in following cases: |host is complete | host is incomplete| ip is virtual |all except NTCMD |only virtual ip | ip is not virtual |all topology |all topology | """ try: self.hostOsh = modeling.createCompleteHostOSHByInterfaceList( 'nt', self.interfacesList, self.hostDo.hostOsName, self.hostDo.hostName, self.hostDo.lastBootDate, self.hostCmdbId, self.hostKey, self.hostMacs, self.ucmdbVersion) if self.hostDo.ipIsVirtual: logger.warn( 'IP: ', self.destinationIp, ' does not appear in the result buffer of the interfaces output - assuming virtual' ) logger.warn('Host topology will be reported without NTCMD CI.') except: self.hostOsh = modeling.createHostOSH(str(self.destinationIp), 'nt', self.hostDo.hostOsName, self.hostDo.hostName) logger.warn('Could not find a valid MAC address for key on ip : ', self.destinationIp) if self.hostDo.ipIsVirtual: logger.warn( 'IP: ', self.destinationIp, ' does not appear in the result buffer of the interfaces output - assuming virtual' ) logger.warn('Only IP marked as virtual will be reported.') self.resultVector.clear() virtualIpOsh = modeling.createIpOSH(str(self.destinationIp)) virtualIpOsh.setBoolAttribute('isvirtual', 1) self.resultVector.add(virtualIpOsh) self.hostOsh = None return #process interfaces looking for nic teaming interfaces. #looking up for interfaces with same mac macToInterfaceListMap = {} for interface in self.interfacesList: intList = macToInterfaceListMap.get(interface.macAddress, []) intList.append(interface) macToInterfaceListMap[interface.macAddress] = intList #checking if interface has a Team key word in it's name for interfaceList in macToInterfaceListMap.values(): if interfaceList and len(interfaceList) < 2: continue for interf in interfaceList: if (interf.name and re.search('[Tt]eam', interf.name)) or ( interf.description and re.search('[Tt]eam', interf.description)): #picking up interface with max interfaceIndex value and setting it aggregate role try: iface = reduce( lambda x, y: int(x.interfaceIndex) > int( y.interfaceIndex) and x or y, interfaceList) iface.role = 'aggregate_interface' except: logger.debugException('') interfacesVector = modeling.createInterfacesOSHV( self.interfacesList, self.hostOsh) roleManager = InterfaceRoleManager() for interface in self.interfacesList: interfaceOsh = interface.getOsh() if not interfaceOsh: continue roleManager.assignInterfaceRole(interface) self.resultVector.add(interfaceOsh) if interface.ips: for ipIndex in range(len(interface.ips)): ipAddress = interface.ips[ipIndex] ipMask = None try: ipMask = interface.masks[ipIndex] except: pass if ipAddress.is_loopback or ipAddress.is_unspecified: logger.debug('Invalid IP retrieved %s. Skipping.' % ipAddress) continue ipProp = modeling.getIpAddressPropertyValue( str(ipAddress), ipMask, interface.dhcpEnabled, interface.description) ipOsh = modeling.createIpOSH(ipAddress, ipMask, None, ipProp) if self.hostDo.ipIsVirtual and ipAddress == self.destinationIp: ipOsh.setBoolAttribute('isvirtual', 1) self.resultVector.add(ipOsh) self.resultVector.add( modeling.createLinkOSH('containment', self.hostOsh, ipOsh)) self.resultVector.add( modeling.createLinkOSH('containment', interfaceOsh, ipOsh)) if ipAddress.version != 6: networkOsh = modeling.createNetworkOSH( str(ipAddress), ipMask) self.resultVector.add(networkOsh) self.resultVector.add( modeling.createLinkOSH('member', networkOsh, ipOsh)) self.resultVector.add( modeling.createLinkOSH('member', networkOsh, self.hostOsh))
def build(self, interfaceName=None): ipProperties = modeling.getIpAddressPropertyValue( str(self.ip), self.netmask, self.hasFlag(Ip.FLAG_DHCP), interfaceName) self.osh = modeling.createIpOSH(self.ip, self.netmask, None, ipProperties)