This function gets called when the proxy starts up. For
    ESXi devices, the host, login credentials, and, if configured,
    the protocol and port are cached.

def init(opts):
    '''
    This function gets called when the proxy starts up. For
    ESXi devices, the host, login credentials, and, if configured,
    the protocol and port are cached.
    '''
    log.debug('Initting esxi proxy module in process %s', os.getpid())
    log.debug('Validating esxi proxy input')
    schema = EsxiProxySchema.serialize()
    log.trace('esxi_proxy_schema = %s', schema)
    proxy_conf = merge(opts.get('proxy', {}), __pillar__.get('proxy', {}))
    log.trace('proxy_conf = %s', proxy_conf)
    try:
        jsonschema.validate(proxy_conf, schema)
    except jsonschema.exceptions.ValidationError as exc:
        raise InvalidConfigError(exc)

    DETAILS['proxytype'] = proxy_conf['proxytype']
    if ('host' not in proxy_conf) and ('vcenter' not in proxy_conf):
        log.critical('Neither \'host\' nor \'vcenter\' keys found in pillar '
                     'for this proxy.')
        return False
    if 'host' in proxy_conf:
        # We have started the proxy by connecting directly to the host
        if 'username' not in proxy_conf:
            log.critical('No \'username\' key found in pillar for this proxy.')
            return False
        if 'passwords' not in proxy_conf:
            log.critical('No \'passwords\' key found in pillar for this proxy.')
            return False
        host = proxy_conf['host']

        # Get the correct login details
        try:
            username, password = find_credentials(host)
        except SaltSystemExit as err:
            log.critical('Error: %s', err)
            return False

        # Set configuration details
        DETAILS['host'] = host
        DETAILS['username'] = username
        DETAILS['password'] = password
        DETAILS['protocol'] = proxy_conf.get('protocol')
        DETAILS['port'] = proxy_conf.get('port')
        return True

    if 'vcenter' in proxy_conf:
        vcenter = proxy_conf['vcenter']
        if not proxy_conf.get('esxi_host'):
            log.critical('No \'esxi_host\' key found in pillar for this proxy.')
        DETAILS['esxi_host'] = proxy_conf['esxi_host']
        # We have started the proxy by connecting via the vCenter
        if 'mechanism' not in proxy_conf:
            log.critical('No \'mechanism\' key found in pillar for this proxy.')
            return False
        mechanism = proxy_conf['mechanism']
        # Save mandatory fields in cache
        for key in ('vcenter', 'mechanism'):
            DETAILS[key] = proxy_conf[key]

        if mechanism == 'userpass':
            if 'username' not in proxy_conf:
                log.critical('No \'username\' key found in pillar for this '
                             'proxy.')
                return False
            if 'passwords' not in proxy_conf and proxy_conf['passwords']:
                log.critical('Mechanism is set to \'userpass\' , but no '
                             '\'passwords\' key found in pillar for this '
                             'proxy.')
                return False
            for key in ('username', 'passwords'):
                DETAILS[key] = proxy_conf[key]
        elif mechanism == 'sspi':
            if 'domain' not in proxy_conf:
                log.critical('Mechanism is set to \'sspi\' , but no '
                             '\'domain\' key found in pillar for this proxy.')
                return False
            if 'principal' not in proxy_conf:
                log.critical('Mechanism is set to \'sspi\' , but no '
                             '\'principal\' key found in pillar for this '
                             'proxy.')
                return False
            for key in ('domain', 'principal'):
                DETAILS[key] = proxy_conf[key]

        if mechanism == 'userpass':
            # Get the correct login details
            log.debug('Retrieving credentials and testing vCenter connection'
                      ' for mehchanism \'userpass\'')
            try:
                username, password = find_credentials(DETAILS['vcenter'])
                DETAILS['password'] = password
            except SaltSystemExit as err:
                log.critical('Error: %s', err)
                return False

    # Save optional
    DETAILS['protocol'] = proxy_conf.get('protocol', 'https')
    DETAILS['port'] = proxy_conf.get('port', '443')
    DETAILS['credstore'] = proxy_conf.get('credstore')