def createCMDBConnection(i__LocalShell):

    logger.info('************* START createCMDBConnection *************')
    l__HostName = CollectorsParameters.getValue(
        CollectorsParameters.KEY_SERVER_NAME)
    l__HTTPPort = int(
        CollectorsParameters.getValue(
            CollectorsParameters.KEY_SERVER_PORT_HTTP))
    l__HTTPSPort = int(
        CollectorsParameters.getValue(
            CollectorsParameters.KEY_SERVER_PORT_HTTPS))

    l__ProtocolParameters = ProtocolDictionaryManager.getProtocolParameters(
        'genericprotocol', netutils.resolveIP(i__LocalShell, l__HostName))

    l__UserName = ''

    for l__Protocol in l__ProtocolParameters:
        if l__Protocol.getProtocolAttribute(
                'protocol_username') == C__INTEGRATION_USER:
            l__UserName = l__Protocol.getProtocolAttribute('protocol_username')
            l__UserPassword = l__Protocol.getProtocolAttribute(
                'protocol_password')
            break

    if not l__UserName:
        logger.error('Error Username Protocol not initialized')
        return None

    #logger.debug('Accessing uCMDB = ',(l__HostName, l__HTTPPort, l__UserName))
    # try http first
    try:
        logger.debug('Attempting HTTP connection')
        l__Provider = UcmdbServiceFactory.getServiceProvider(
            'http', l__HostName, l__HTTPPort)
    except:
        logger.debug('HTTP connection failed, trying HTTPS')
        UcmdbServiceFactory.initSSL()
        l__Provider = UcmdbServiceFactory.getServiceProvider(
            'https', l__HostName, l__HTTPSPort)

    l__Credentials = l__Provider.createCredentials(l__UserName,
                                                   l__UserPassword)
    l__ClientContext = l__Provider.createClientContext("UD")
    o__UcmdbService = l__Provider.connect(l__Credentials, l__ClientContext)
    logger.info('************* END createCMDBConnection *************')
    return o__UcmdbService
Пример #2
0
def getNnmProtocol(Framework, cmdbServerIp):
    ''' Framework, string -> protocol
    @raise MissingNnmProtocolException in case no NNM protocol is defined
    '''
    credentialsId = Framework.getParameter('credentialsId')
    protocols = []
    if credentialsId:
        protocolObject = ProtocolDictionaryManager.getProtocolById(credentialsId)
        if protocolObject:
            protocols.append(protocolObject)
        else:
            logger.warn("Failed to get Protocol by provided credentialsId")
    else:
        protocols = ProtocolDictionaryManager.getProtocolParameters(NNM_PROTOCOL, cmdbServerIp)

    if not protocols:
        raise MissingNnmProtocolException('NNM Protocol is not defined')

    if len(protocols) > 1:
        logger.warn('More than one set of credentials found, the first one is used')

    return protocols[0]