Beispiel #1
0
def discoverPorts(vlanID, vlanOSH, hostOSH, ucmdbversion, Framework,
                  vlan_context_dict):
    localPorts = ObjectStateHolderVector()
    properties = Properties()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    properties.setProperty('ip_address', ipAddress)
    properties.setProperty(BaseClient.CREDENTIALS_ID, credentialsId)
    snmp_version = Framework.getProtocolProperty(credentialsId,
                                                 "snmpprotocol_version")

    if snmp_version == 'version 3':
        if not vlan_context_dict:
            raise Exception, "Vlan Conext is not present on the device. No Vlan details might be discovered"

        vlan_context = vlan_context_dict.get(vlanID)
        if not vlan_context:
            raise Exception, "Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % vlanID
        properties.setProperty(SnmpQueries._postfix, '%s' % vlan_context)

    else:
        properties.setProperty(SnmpQueries._postfix, '%s%s' % ('@', vlanID))

    newClient = Framework.createClient(properties)

    if not newClient:
        raise ValueError(
            "Failed to get physical port information from the device. VLAN will not be reported."
        )

    portNumIfIndexTableMib = '1.3.6.1.2.1.17.1.4.1.2,1.3.6.1.2.1.17.1.4.1.3,string'
    portNumIfIndexTableRes = newClient.executeQuery(
        portNumIfIndexTableMib)  #@@CMD_PERMISION snmp protocol execution
    portNumIfIndexTable = portNumIfIndexTableRes.asTable()
    if len(portNumIfIndexTable) == 0:
        newClient and newClient.close()
        raise ValueError, "Failed to get physical port information from the device. VLAN will not be reported."

    for i in range(len(portNumIfIndexTable)):
        port = portNumIfIndexTable[i][0]

        portOSH = ObjectStateHolder('port')
        portOSH.setContainer(hostOSH)
        modeling.setPhysicalPortNumber(portOSH, port)
        localPorts.add(portOSH)

        if ucmdbversion < 9:
            member_link = modeling.createLinkOSH('member', portOSH, vlanOSH)
        else:
            member_link = modeling.createLinkOSH('membership', vlanOSH,
                                                 portOSH)
        localPorts.add(member_link)
    if newClient:
        newClient.close()
    return localPorts
Beispiel #2
0
 def discover_vlans(self):
     bridge_mac_address = self.get_bridge_mac_address()
     vlan_table_res = self.snmp_client.executeQuery(
         self.VLAN_TABLE_MIB)  #@@CMD_PERMISION snmp protocol execution
     vlan_table = vlan_table_res.asTable()
     if len(vlan_table) == 0:
         raise NoVlansException, "No VLANs Configured on the device."
     vlan_ports_map = self.get_ports()
     for i in range(len(vlan_table)):
         oshv_result = ObjectStateHolderVector()
         vlan_oid = vlan_table[i][0]
         vlan_name = vlan_table[i][1]
         vlan_number = vlan_oid[vlan_oid.find('.') + 1:]
         port_list = vlan_ports_map.get(vlan_number)
         bridge_osh = None
         if not port_list:
             logger.warn(
                 'Skipping VLAN %s since it has no ports assigned.' %
                 vlan_number)
             continue
         vlan_osh = ObjectStateHolder('vlan')
         vlan_osh.setContainer(self.host_osh)
         modeling.setVlanIdAttribute(vlan_osh, vlan_number)
         vlan_osh.setAttribute('data_name', vlan_name)
         if bridge_mac_address:
             vlan_osh.setAttribute('vlan_bridgemac', bridge_mac_address)
             bridge_osh = ObjectStateHolder('bridge')
             bridge_osh.setContainer(self.host_osh)
             bridge_osh.setAttribute('bridge_basemacaddr',
                                     bridge_mac_address)
             oshv_result.add(bridge_osh)
             depend_link = modeling.createLinkOSH('depend', vlan_osh,
                                                  bridge_osh)
             oshv_result.add(depend_link)
         oshv_result.add(vlan_osh)
         for port in port_list:
             port_osh = ObjectStateHolder('port')
             port_osh.setContainer(self.host_osh)
             modeling.setPhysicalPortNumber(port_osh, port)
             oshv_result.add(port_osh)
             member_link = modeling.createLinkOSH('membership', vlan_osh,
                                                  port_osh)
             oshv_result.add(member_link)
             if bridge_osh:
                 contains_link = modeling.createLinkOSH(
                     'contains', bridge_osh, port_osh)
                 oshv_result.add(contains_link)
         self.framework.sendObjects(oshv_result)
         self.framework.flushObjects()
         logger.debug(
             'Vlan %s successfully discovered. Result vector contains %d objects.'
             % (vlan_name, oshv_result.size()))
         if self.snmp_client:
             self.snmp_client.close()
Beispiel #3
0
 def addToOSHV (self, aSwitch, ObjSHV):
     aPtOSH = ObjectStateHolder("port")
     aPtOSH.setContainer(aSwitch.hostOSH)
     modeling.setPhysicalPortNumber(aPtOSH, self.portNumber)
     aPtOSH.setAttribute('port_remotestpbgid',self.remoteStpBgId)
     self.__setRemotePortNumber(aPtOSH, self.remoteStpPortId)
     aPtOSH.setAttribute('port_intfcindex',int(self.interfaceIndex))
     aPtOSH.setAttribute('port_nextmac',self.remoteTermMac)
     aPtOSH.setAttribute('port_hostbgid',self.hostBgId)
     aPtOSH.setAttribute('port_discoverylastrun',self.discoveryInst)
     aPtOSH.setAttribute('data_name',self.data_name)
     ObjSHV.add(aPtOSH)
     if self.ucmdbversion and self.ucmdbversion >= 9:
         interface = aSwitch.getInterfaceByIfIndex(self.interfaceIndex)
         if interface:
             intfOsh = modeling.createInterfaceOSH(interface.ifMac, aSwitch.hostOSH, interface.ifDescr, interface.ifIndex, interface.ifType, interface.ifAdminStatus, interface.ifOperStatus, interface.ifSpeed, interface.ifName, interface.ifAlias)
             if intfOsh:
                 ObjSHV.add(modeling.createLinkOSH('realization', aPtOSH, intfOsh))
         #in case we get a MAC for remote iface and this is a real MAC report a Layer2Connection between these interfaces
         if self.remoteTermMac and not self.remoteTermMac.endswith(":" + self.portNumber) and netutils.isValidMac(self.remoteTermMac):
             logger.debug('Created L2C from Ports')
             #write the reported layer2 info to file in order to post process in case of remote MAC "Multiple Match" 
             md5_obj = md5.new()
             updateValue = ''
             vlan_id = self.framework.getDestinationAttribute('snmpCommunityPostfix')
             for value in [interface.ifMac.upper(), interface.ifDescr, interface.ifIndex, interface.ifType, interface.ifAdminStatus, interface.ifOperStatus, interface.ifSpeed, interface.ifName, interface.ifAlias, vlan_id]:
                 if not updateValue:
                     updateValue = str(value)
                 else:
                     updateValue = updateValue + ':::' + str(value)
             md5_obj.update(updateValue)
             
             filename = md5_obj.hexdigest()
             filepath = os.path.join(CollectorsParameters.HOME_DIR, 'runtime/l2reported/')
             if not os.path.exists(filepath):
                 try:
                     os.mkdir(filepath)
                 except:
                     logger.debug('folder creation failed')
             f = open(filepath+filename,'w')
             f.write(updateValue+'\n')
             macsSeparated = ''
             for mac in [self.remoteTermMacRaw.get(self.remoteTermMac)]:
                 if mac.count('.'):
                     mac = self.convertToHexString(mac)
                 if not macsSeparated:
                     macsSeparated = mac
                 else:
                     macsSeparated = macsSeparated + ':::' + mac
             f.write(macsSeparated)
             f.close()
             
             ObjSHV.addAll(modeling.createLayer2ConnectionWithLinks([self.remoteTermMacRaw.get(self.remoteTermMac)], aSwitch, interface))
def discoverPorts(vlanID, vlanOSH, hostOSH, ucmdbversion, Framework, vlan_context_dict):
    localPorts = ObjectStateHolderVector()
    properties = Properties()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    properties.setProperty('ip_address', ipAddress)
    properties.setProperty(BaseClient.CREDENTIALS_ID, credentialsId)
    snmp_version = Framework.getProtocolProperty(credentialsId, "snmpprotocol_version")
    
    if snmp_version == 'version 3':
        if not vlan_context_dict:
            raise Exception, "Vlan Conext is not present on the device. No Vlan details might be discovered"
        
        vlan_context = vlan_context_dict.get(vlanID)
        if not vlan_context:
            raise Exception, "Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % vlanID
        properties.setProperty(SnmpQueries._postfix, '%s' % vlan_context)
        
    else:
        properties.setProperty(SnmpQueries._postfix, '%s%s' % ('@', vlanID))
        
    newClient = Framework.createClient(properties)
        
    if not newClient:
        raise ValueError("Failed to get physical port information from the device. VLAN will not be reported.")
    
    portNumIfIndexTableMib = '1.3.6.1.2.1.17.1.4.1.2,1.3.6.1.2.1.17.1.4.1.3,string'
    portNumIfIndexTableRes = newClient.executeQuery(portNumIfIndexTableMib)#@@CMD_PERMISION snmp protocol execution
    portNumIfIndexTable = portNumIfIndexTableRes.asTable()
    if len(portNumIfIndexTable) == 0:
        newClient and newClient.close()
        raise ValueError, "Failed to get physical port information from the device. VLAN will not be reported."
    
    for i in range(len(portNumIfIndexTable)):
        port = portNumIfIndexTable[i][0]

        portOSH = ObjectStateHolder('port')
        portOSH.setContainer(hostOSH)
        modeling.setPhysicalPortNumber(portOSH, port)
        localPorts.add(portOSH)

        if ucmdbversion < 9:
            member_link = modeling.createLinkOSH('member', portOSH, vlanOSH)
        else:
            member_link = modeling.createLinkOSH('membership', vlanOSH, portOSH)
        localPorts.add(member_link)
    if newClient:
        newClient.close()
    return localPorts
Beispiel #5
0
def _build_port_osh(port):
    '@types: Port -> osh'
    osh = ObjectStateHolder('fcport')
    populateOSH(osh, {
        'fcport_portid': port.id,
        'fcport_type': port.type,
        'data_name': port.name,
        'fcport_wwn': str(port.wwn),
        'fcport_status': port.status,
        'fcport_connectedtowwn': str(port.connected_to_wwn)})
    portNum = port.port
    if portNum in (None, ''):
        portNum = '-1'
    modeling.setPhysicalPortNumber(osh, portNum)
    return osh
 def discover_vlans(self):
     bridge_mac_address = self.get_bridge_mac_address()
     vlan_table_res = self.snmp_client.executeQuery(self.VLAN_TABLE_MIB)#@@CMD_PERMISION snmp protocol execution
     vlan_table = vlan_table_res.asTable()
     if len(vlan_table) == 0:
         raise NoVlansException, "No VLANs Configured on the device."
     vlan_ports_map = self.get_ports()
     for i in range(len(vlan_table)):
         oshv_result = ObjectStateHolderVector()
         vlan_oid = vlan_table[i][0]
         vlan_name = vlan_table[i][1]
         vlan_number = vlan_oid[vlan_oid.find('.')+1:]
         port_list = vlan_ports_map.get(vlan_number)
         bridge_osh = None
         if not port_list:
             logger.warn('Skipping VLAN %s since it has no ports assigned.' % vlan_number)
             continue
         vlan_osh = ObjectStateHolder('vlan')
         vlan_osh.setContainer(self.host_osh)
         modeling.setVlanIdAttribute(vlan_osh, vlan_number)
         vlan_osh.setAttribute('data_name', vlan_name)
         if bridge_mac_address:
             vlan_osh.setAttribute('vlan_bridgemac', bridge_mac_address)
             bridge_osh = ObjectStateHolder('bridge')
             bridge_osh.setContainer(self.host_osh)
             bridge_osh.setAttribute('bridge_basemacaddr', bridge_mac_address)
             oshv_result.add(bridge_osh)
             depend_link = modeling.createLinkOSH('depend',vlan_osh,bridge_osh)
             oshv_result.add(depend_link)
         oshv_result.add(vlan_osh)
         for port in port_list:
             port_osh = ObjectStateHolder('port')
             port_osh.setContainer(self.host_osh)
             modeling.setPhysicalPortNumber(port_osh, port)
             oshv_result.add(port_osh)
             member_link = modeling.createLinkOSH('membership', vlan_osh, port_osh)
             oshv_result.add(member_link)
             if bridge_osh:
                 contains_link = modeling.createLinkOSH('contains', bridge_osh, port_osh)
                 oshv_result.add(contains_link)
         self.framework.sendObjects(oshv_result)
         self.framework.flushObjects()
         logger.debug('Vlan %s successfully discovered. Result vector contains %d objects.' % (vlan_name, oshv_result.size()))
         if self.snmp_client:
             self.snmp_client.close()
def doAll(snmpClient, hostOSH, vlanOSH, OSHVResult, ucmdbversion):

    baseMacTableMib        = '1.3.6.1.2.1.17.1.1,1.3.6.1.2.1.17.1.2,hexa'
    portNumIfIndexTableMib    = '1.3.6.1.2.1.17.1.4.1.2,1.3.6.1.2.1.17.1.4.1.3,string'

    baseMacTableRes = snmpClient.executeQuery(baseMacTableMib)#@@CMD_PERMISION snmp protocol execution
    portNumIfIndexTableRes = snmpClient.executeQuery(portNumIfIndexTableMib)#@@CMD_PERMISION snmp protocol execution

    baseMacTable = baseMacTableRes.asTable()
    portNumIfIndexTable = portNumIfIndexTableRes.asTable()
    bridgeOSH = None
    if (len(baseMacTable) > 0) and (baseMacTable[0][1] != None) and (baseMacTable[0][1] != '') and (baseMacTable[0][1] != '000000000000'):

        bridgeOSH = ObjectStateHolder('bridge')
        bridgeOSH.setContainer(hostOSH)
        bridgeOSH.setAttribute('bridge_basemacaddr', baseMacTable[0][1])
        OSHVResult.add(bridgeOSH)
        
        vlanOSH.setAttribute('vlan_bridgemac', baseMacTable[0][1])
        OSHVResult.add(vlanOSH)
    
    if len(portNumIfIndexTable) == 0:
        raise ValueError, "Failed to get physical port information from the device."
    for i in range(len(portNumIfIndexTable)):
        port = portNumIfIndexTable[i][0]

        portOSH = ObjectStateHolder('port')
        portOSH.setContainer(hostOSH)
        modeling.setPhysicalPortNumber(portOSH, port)
        OSHVResult.add(portOSH)

        if ucmdbversion < 9:
            member_link = modeling.createLinkOSH('member', portOSH, vlanOSH)
        else:
            member_link = modeling.createLinkOSH('member', vlanOSH, portOSH)
        OSHVResult.add(member_link)
        if (bridgeOSH != None):
            contains_link = modeling.createLinkOSH('contains',bridgeOSH,portOSH)
            OSHVResult.add(contains_link)
            depend_link = modeling.createLinkOSH('depend',vlanOSH,bridgeOSH)
            OSHVResult.add(depend_link)
Beispiel #8
0
def createBridgePhysicalPort(portNumber, containerOsh):
    portOsh = ObjectStateHolder('port')
    modeling.setPhysicalPortNumber(portOsh, portNumber)
    portOsh.setBoolAttribute('isvirtual', 1)
    portOsh.setContainer(containerOsh)
    return portOsh
Beispiel #9
0
def createBridgePhysicalPort(portNumber, containerOsh):
    portOsh = ObjectStateHolder('port')
    modeling.setPhysicalPortNumber(portOsh, portNumber)
    portOsh.setBoolAttribute('isvirtual', 1)
    portOsh.setContainer(containerOsh)
    return portOsh
Beispiel #10
0
    def addToOSHV(self, aSwitch, ObjSHV):
        aPtOSH = ObjectStateHolder("port")
        aPtOSH.setContainer(aSwitch.hostOSH)
        modeling.setPhysicalPortNumber(aPtOSH, self.portNumber)
        aPtOSH.setAttribute('port_remotestpbgid', self.remoteStpBgId)
        self.__setRemotePortNumber(aPtOSH, self.remoteStpPortId)
        aPtOSH.setAttribute('port_intfcindex', int(self.interfaceIndex))
        aPtOSH.setAttribute('port_nextmac', self.remoteTermMac)
        aPtOSH.setAttribute('port_hostbgid', self.hostBgId)
        aPtOSH.setAttribute('port_discoverylastrun', self.discoveryInst)
        aPtOSH.setAttribute('data_name', self.data_name)
        ObjSHV.add(aPtOSH)
        if self.ucmdbversion and self.ucmdbversion >= 9:
            interface = aSwitch.getInterfaceByIfIndex(self.interfaceIndex)
            if interface:
                intfOsh = modeling.createInterfaceOSH(
                    interface.ifMac, aSwitch.hostOSH, interface.ifDescr,
                    interface.ifIndex, interface.ifType,
                    interface.ifAdminStatus, interface.ifOperStatus,
                    interface.ifSpeed, interface.ifName, interface.ifAlias)
                if intfOsh:
                    ObjSHV.add(
                        modeling.createLinkOSH('realization', aPtOSH, intfOsh))
            #in case we get a MAC for remote iface and this is a real MAC report a Layer2Connection between these interfaces
            if self.remoteTermMac and not self.remoteTermMac.endswith(
                    ":" + self.portNumber) and netutils.isValidMac(
                        self.remoteTermMac):
                logger.debug('Created L2C from Ports')
                #write the reported layer2 info to file in order to post process in case of remote MAC "Multiple Match"
                md5_obj = md5.new()
                updateValue = ''
                vlan_id = self.framework.getDestinationAttribute(
                    'snmpCommunityPostfix')
                for value in [
                        interface.ifMac.upper(), interface.ifDescr,
                        interface.ifIndex, interface.ifType,
                        interface.ifAdminStatus, interface.ifOperStatus,
                        interface.ifSpeed, interface.ifName, interface.ifAlias,
                        vlan_id
                ]:
                    if not updateValue:
                        updateValue = str(value)
                    else:
                        updateValue = updateValue + ':::' + str(value)
                md5_obj.update(updateValue)

                filename = md5_obj.hexdigest()
                filepath = os.path.join(CollectorsParameters.HOME_DIR,
                                        'runtime/l2reported/')
                if not os.path.exists(filepath):
                    try:
                        os.mkdir(filepath)
                    except:
                        logger.debug('folder creation failed')
                f = open(filepath + filename, 'w')
                f.write(updateValue + '\n')
                macsSeparated = ''
                for mac in [self.remoteTermMacRaw.get(self.remoteTermMac)]:
                    if mac.count('.'):
                        mac = self.convertToHexString(mac)
                    if not macsSeparated:
                        macsSeparated = mac
                    else:
                        macsSeparated = macsSeparated + ':::' + mac
                f.write(macsSeparated)
                f.close()

                ObjSHV.addAll(
                    modeling.createLayer2ConnectionWithLinks(
                        [self.remoteTermMacRaw.get(self.remoteTermMac)],
                        aSwitch, interface))