コード例 #1
0
ファイル: layer2.py プロジェクト: ddonnelly19/dd-git
def buildVlan(vlan, swithOsh):
    if not vlan:
        return None
    try:
        vlanOsh = modeling.createVlanOsh(int(vlan.id), swithOsh, [str(x) for x in vlan.ports])
        vlanOsh.setAttribute('data_name', vlan.name)
        return vlanOsh
    except:
        logger.debug('Vlan scipped. No ports directly assigned.')
コード例 #2
0
ファイル: layer2.py プロジェクト: deezeesms/dd-git
def buildVlan(vlan, swithOsh):
    if not vlan:
        return None
    try:
        vlanOsh = modeling.createVlanOsh(int(vlan.id), swithOsh,
                                         [str(x) for x in vlan.ports])
        vlanOsh.setAttribute('data_name', vlan.name)
        return vlanOsh
    except:
        logger.debug('Vlan scipped. No ports directly assigned.')
コード例 #3
0
def DiscoveryMain(Framework):

    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    ucmdbversion = modeling.CmdbClassModel().version()
    
    snmpCommunityPostfixList = ''
    try:
        snmpCommunityPostfixList = Framework.getTriggerCIDataAsList('snmpCommunityPostfix')
        if not snmpCommunityPostfixList:
            raise Exception, "No Vlans defined on switch"
    except:
        Framework.reportError('Failed to discover destination. No Vlans properly configured.')
        return OSHVResult

    hostId    = Framework.getDestinationAttribute('hostId')
    hostOSH = modeling.createOshByCmdbIdString('host', hostId)
    
    vlan_context_dict = {}
    snmp_version = Framework.getProtocolProperty(credentialsId, "snmpprotocol_version")
    if snmp_version == 'version 3':
        client = Framework.createClient()
        vlan_context_dict = snmputils.get_snmp_vlan_context_dict(client)
        client and client.close()
        
    vlanOSH = None
    failedToDiscoverCounter = 0
    for snmpCommunityPostfix in snmpCommunityPostfixList:
        vlanOSH = modeling.createVlanOsh(snmpCommunityPostfix, hostOSH)
        vlanOSH.setContainer(hostOSH)

        properties = Properties()
        if credentialsId and ipAddress:
            properties.setProperty('ip_address', ipAddress)
            properties.setProperty(BaseClient.CREDENTIALS_ID, credentialsId)

        if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
            if snmp_version == 'version 3':
                if not vlan_context_dict:
                    logger.warn("Vlan Conext is not present on the device. No Vlan details might be discovered")
                    continue
                
                vlan_context = vlan_context_dict.get(snmpCommunityPostfix)
                if not vlan_context:
                    logger.warn("Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % snmpCommunityPostfix)
                    continue
                properties.setProperty(SnmpQueries._postfix, '%s' % vlan_context)
            else:
                properties.setProperty(SnmpQueries._postfix, '%s%s' % ('@', snmpCommunityPostfix))
        

        snmpClient = None
        try:
            snmpClient = Framework.createClient(properties)
            #SnmpConnectionTester(snmpClient).testSnmpConnection()
            doAll(snmpClient, hostOSH, vlanOSH, OSHVResult, ucmdbversion)
            Framework.sendObjects(OSHVResult)
            Framework.flushObjects()
            logger.debug('Vlan %s successfully discovered. Result vector contains %d objects.' % (snmpCommunityPostfix, OSHVResult.size()))
            OSHVResult = ObjectStateHolderVector()
        except:
            logger.debugException('')
            failedToDiscoverCounter =+ 1
            logger.debugException('Failed to discover ip: %s on Vlan#: %s. ' % (ipAddress, snmpCommunityPostfix))
        if snmpClient != None:
            snmpClient.close()

    if failedToDiscoverCounter == len(snmpCommunityPostfixList):
        Framework.reportError('Failed to discover all Vlans on the destination.')
    elif failedToDiscoverCounter:
        Framework.reportWarning('Failed to discover one or more Vlans on the destination')
    
    if snmpClient != None:
        snmpClient.close()
    return OSHVResult