示例#1
0
文件: __init__.py 项目: wja30/cortex
def client(env: Optional[str] = None) -> Client:
    """
    Initialize a client based on the specified environment.

    Args:
        env: Name of the environment to use.

    Returns:
        Cortex client that can be used to deploy and manage APIs in the specified environment.
    """
    environments = env_list()

    if env is None:
        if not environments["default_environment"]:
            raise NotFound("no default environment configured")
        env = environments["default_environment"]

    found = False
    for environment in environments["environments"]:
        if environment["name"] == env:
            found = True
            break
    if not found:
        raise NotFound(
            f"can't find environment {env}, create one by calling `cortex.new_client()`"
        )

    return Client(environment)
示例#2
0
def client(env: str):
    """
    Initialize a client based on the specified environment.

    Args:
        env: Name of the environment to use.

    Returns:
        Cortex client that can be used to deploy and manage APIs in the specified environment.
    """
    environments = env_list()

    found = False

    for environment in environments:
        if environment["name"] == env:
            found = True
            break

    if not found:
        raise NotFound(
            f"can't find environment {env}, create one by calling `cortex.cluster_client()`"
        )

    return Client(environment)
示例#3
0
def client(env: str):
    """
    Initialize a client based on the specified environment.

    To deploy and manage APIs on a new cluster:

    1. Spin up a cluster using the CLI command `cortex cluster up`.
        An environment named "aws" will be created once the cluster is ready.
    2. Initialize your client:

        ```python
        import cortex
        c = cortex.client("aws")
        c.deploy("./cortex.yaml")
        ```

    To deploy and manage APIs on an existing cluster:

    1. Use the command `cortex cluster info` to get the Operator Endpoint.
    2. Configure a client to your cluster:

        ```python
        import cortex
        c = cortex.cluster_client("aws", operator_endpoint, aws_access_key_id, aws_secret_access_key)
        c.deploy("./cortex.yaml")
        ```

    To deploy and manage APIs locally:

    ```python
    import cortex
    c = cortex.client("local")
    c.deploy("./cortex.yaml")
    ```

    Args:
        env: Name of the environment to use.

    Returns:
        Cortex client that can be used to deploy and manage APIs in the specified environment.
    """
    environments = env_list()

    found = False

    for environment in environments:
        if environment["name"] == env:
            found = True

    if not found:
        raise NotFound(
            f"can't find environment {env}, create one by calling `cortex.cluster_client()`"
        )

    return Client(env)