def init(opts):
    '''
    This function gets called when the proxy starts up. For
    login the protocol and port are cached.
    '''
    log.debug('Initting esxvm proxy module in process %s', os.getpid())
    log.debug('Validating esxvm proxy input')
    proxy_conf = merge(opts.get('proxy', {}), __pillar__.get('proxy', {}))
    log.trace('proxy_conf = %s', proxy_conf)
    # TODO json schema validation

    # Save mandatory fields in cache
    for key in ('vcenter', 'datacenter', 'mechanism'):
        DETAILS[key] = proxy_conf[key]

    # Additional validation
    if DETAILS['mechanism'] == 'userpass':
        if 'username' not in proxy_conf:
            raise excs.InvalidProxyInputError(
                'Mechanism is set to \'userpass\' , but no '
                '\'username\' key found in pillar for this proxy.')
        if 'passwords' not in proxy_conf:
            raise excs.InvalidProxyInputError(
                'Mechanism is set to \'userpass\' , but no '
                '\'passwords\' key found in pillar for this proxy.')
        for key in ('username', 'passwords'):
            DETAILS[key] = proxy_conf[key]
    else:
        if 'domain' not in proxy_conf:
            raise excs.InvalidProxyInputError(
                'Mechanism is set to \'sspi\' , but no '
                '\'domain\' key found in pillar for this proxy.')
        if 'principal' not in proxy_conf:
            raise excs.InvalidProxyInputError(
                'Mechanism is set to \'sspi\' , but no '
                '\'principal\' key found in pillar for this proxy.')
        for key in ('domain', 'principal'):
            DETAILS[key] = proxy_conf[key]

    # Save optional
    DETAILS['protocol'] = proxy_conf.get('protocol')
    DETAILS['port'] = proxy_conf.get('port')

    # Test connection
    if DETAILS['mechanism'] == 'userpass':
        # Get the correct login details
        log.debug('Retrieving credentials and testing vCenter connection for '
                  'mehchanism \'userpass\'')
        try:
            username, password = find_credentials()
            DETAILS['password'] = password
        except excs.SaltSystemExit as err:
            log.critical('Error: %s', err)
            return False
    return True
def init ( opts ) : log . debug ( 'Initting esxvm proxy module in process %s' , os . getpid ( ) ) log . debug ( 'Validating esxvm proxy input' ) proxy_conf = merge ( opts . get ( 'proxy' , { } ) , __pillar__ . get ( 'proxy' , { } ) ) log . trace ( 'proxy_conf = %s' , proxy_conf ) for key in ( 'vcenter' , 'datacenter' , 'mechanism' ) : DETAILS [ key ] = proxy_conf [ key ] if DETAILS [ 'mechanism' ] == 'userpass' : if 'username' not in proxy_conf : raise excs . InvalidProxyInputError ( 'Mechanism is set to \'userpass\' , but no ' '\'username\' key found in pillar for this proxy.' ) if 'passwords' not in proxy_conf : raise excs . InvalidProxyInputError ( 'Mechanism is set to \'userpass\' , but no ' '\'passwords\' key found in pillar for this proxy.' ) for key in ( 'username' , 'passwords' ) : DETAILS [ key ] = proxy_conf [ key ] else : if 'domain' not in proxy_conf : raise excs . InvalidProxyInputError ( 'Mechanism is set to \'sspi\' , but no ' '\'domain\' key found in pillar for this proxy.' ) if 'principal' not in proxy_conf : raise excs . InvalidProxyInputError ( 'Mechanism is set to \'sspi\' , but no ' '\'principal\' key found in pillar for this proxy.' ) for key in ( 'domain' , 'principal' ) : DETAILS [ key ] = proxy_conf [ key ] DETAILS [ 'protocol' ] = proxy_conf . get ( 'protocol' ) DETAILS [ 'port' ] = proxy_conf . get ( 'port' ) if DETAILS [ 'mechanism' ] == 'userpass' : log . debug ( 'Retrieving credentials and testing vCenter connection for ' 'mehchanism \'userpass\'' ) try : username , password = find_credentials ( ) DETAILS [ 'password' ] = password except excs . SaltSystemExit as err : log . critical ( 'Error: %s' , err ) return False return True
This function gets called when the proxy starts up. For
    login the protocol and port are cached.