示例#1
0
def create_rest_client(**kwargs):
    # Doing it with kwargs instead of arguments with default values to allow
    # not passing args (which will then use the default values), or explicitly
    # passing None (or False) which will then be passed as-is to the Client

    username = kwargs.get('username', get_manager_username())
    password = kwargs.get('password', get_manager_password())
    tenant = kwargs.get('tenant', get_manager_tenant())
    token = kwargs.get('token')
    rest_port = kwargs.get('rest_port',
                           os.environ.get(constants.CLOUDIFY_REST_PORT, 80))
    rest_protocol = kwargs.get('rest_protocol',
                               'https' if rest_port == '443' else 'http')
    cert_path = kwargs.get('cert_path', cli_env.get_ssl_cert())
    trust_all = kwargs.get('trust_all', cli_env.get_ssl_trust_all())

    headers = create_auth_header(username, password, token, tenant)

    return CloudifyClient(
            host=get_manager_ip(),
            port=rest_port,
            protocol=rest_protocol,
            headers=headers,
            trust_all=trust_all,
            cert=cert_path)
示例#2
0
def create_rest_client(**kwargs):
    # Doing it with kwargs instead of arguments with default values to allow
    # not passing args (which will then use the default values), or explicitly
    # passing None (or False) which will then be passed as-is to the Client

    username = kwargs.get('username', get_manager_username())
    password = kwargs.get('password', get_manager_password())
    tenant = kwargs.get('tenant', get_manager_tenant())
    token = kwargs.get('token')
    rest_port = kwargs.get('rest_port',
                           os.environ.get(constants.CLOUDIFY_REST_PORT, 80))
    rest_protocol = kwargs.get('rest_protocol',
                               'https' if rest_port == '443' else 'http')
    cert_path = kwargs.get('cert_path', cli_env.get_ssl_cert())
    trust_all = kwargs.get('trust_all', cli_env.get_ssl_trust_all())

    headers = create_auth_header(username, password, token, tenant)

    return CloudifyClient(
            host=get_manager_ip(),
            port=rest_port,
            protocol=rest_protocol,
            headers=headers,
            trust_all=trust_all,
            cert=cert_path)