Exemplo n.º 1
0
            macToInterfaceListMap[interface.macAddress] = intList
        #checking if interface has a Team key word in it's name
        for ifaceList in macToInterfaceListMap.values():
            if ifaceList and len(ifaceList) < 2:
                continue
            for interf in ifaceList:
                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, ifaceList)
                        iface.role = 'aggregate_interface'
                    except:
                        logger.debugException('')

        # add all interfaces to the host
        vector.addAll(modeling.createInterfacesOSHV(interfaceList, hostOSH))
        roleManager = networking_win.InterfaceRoleManager()

        builtInets = filter(modeling.NetworkInterface.getOsh, interfaceList)
        fptools.each(roleManager.assignInterfaceRole, builtInets)

        isCompleteAttr = hostOSH.getAttribute('host_iscomplete')
        for i in range(vector.size()):
            osh = vector.get(i)
            if osh.getObjectClass() == 'ip':
                if (isCompleteAttr != None
                    and isCompleteAttr.getBooleanValue() == 1):
                    link = modeling.createLinkOSH('contained', hostOSH, osh)
                    vector.add(link)
            elif osh.getObjectClass() == 'network':
                link = modeling.createLinkOSH('member', osh, hostOSH)
Exemplo n.º 2
0
def createInterfaceOsh(nic, container):
    tempVector = modeling.createInterfacesOSHV((nic, ), container)
    if tempVector.size() > 0:
        return tempVector.get(0)
Exemplo n.º 3
0
    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))
Exemplo n.º 4
0
def createInterfaceOsh(nic, container):
    tempVector = modeling.createInterfacesOSHV((nic,), container)
    if tempVector.size() > 0:
        return tempVector.get(0)
Exemplo n.º 5
0
    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))