Пример #1
0
 def test_esxcluster_schema(self):
     mock_json_validate = MagicMock()
     serialized_schema = EsxclusterProxySchema().serialize()
     with patch("salt.proxy.esxcluster.jsonschema.validate",
                mock_json_validate):
         esxcluster.init(self.opts_sspi)
     mock_json_validate.assert_called_once_with(self.opts_sspi["proxy"],
                                                serialized_schema)
Пример #2
0
def init(opts):
    '''
    This function gets called when the proxy starts up. For
    login
    the protocol and port are cached.
    '''
    log.debug('Initting esxcluster proxy module in process %s', os.getpid())
    log.debug('Validating esxcluster proxy input')
    schema = EsxclusterProxySchema.serialize()
    log.trace('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 salt.exceptions.InvalidConfigError(exc)

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

    # Additional validation
    if DETAILS['mechanism'] == 'userpass':
        if 'username' not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                'Mechanism is set to \'userpass\', but no '
                '\'username\' key found in proxy config.')
        if 'passwords' not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                'Mechanism is set to \'userpass\', but no '
                '\'passwords\' key found in proxy config.')
        for key in ('username', 'passwords'):
            DETAILS[key] = proxy_conf[key]
    else:
        if 'domain' not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                'Mechanism is set to \'sspi\', but no '
                '\'domain\' key found in proxy config.')
        if 'principal' not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                'Mechanism is set to \'sspi\', but no '
                '\'principal\' key found in proxy config.')
        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 salt.exceptions.SaltSystemExit as err:
            log.critical('Error: %s', err)
            return False
    return True
Пример #3
0
def init(opts):
    """
    This function gets called when the proxy starts up. For
    login
    the protocol and port are cached.
    """
    log.debug("Initting esxcluster proxy module in process %s", os.getpid())
    log.debug("Validating esxcluster proxy input")
    schema = EsxclusterProxySchema.serialize()
    log.trace("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 salt.exceptions.InvalidConfigError(exc)

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

    # Additional validation
    if DETAILS["mechanism"] == "userpass":
        if "username" not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                "Mechanism is set to 'userpass', but no "
                "'username' key found in proxy config.")
        if "passwords" not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                "Mechanism is set to 'userpass', but no "
                "'passwords' key found in proxy config.")
        for key in ("username", "passwords"):
            DETAILS[key] = proxy_conf[key]
    else:
        if "domain" not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                "Mechanism is set to 'sspi', but no 'domain' key found in proxy config."
            )
        if "principal" not in proxy_conf:
            raise salt.exceptions.InvalidConfigError(
                "Mechanism is set to 'sspi', but no "
                "'principal' key found in proxy config.")
        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 salt.exceptions.SaltSystemExit as err:
            log.critical("Error: %s", err)
            return False
    return True