Beispiel #1
0
def set(**kwargs):  # pylint:disable=redefined-builtin
    """Set the global config values.

    Example:

    \b
    $ polyaxon config set --host=localhost
    """
    try:
        _config = ClientConfigManager.get_config_or_default()
    except Exception as e:
        handle_cli_error(e, message="Polyaxon load configuration.")
        Printer.print_header(
            "You can reset your config by running: polyaxon config purge"
        )
        sys.exit(1)

    for key, value in kwargs.items():
        if value is not None:
            setattr(_config, key, value)

    ClientConfigManager.set_config(_config)
    Printer.print_success("Config was updated.")
    # Reset cli config
    CliConfigManager.purge()
Beispiel #2
0
def cli(context, verbose, offline):
    """ Polyaxon CLI tool to:

        * Parse, Validate, and Check Polyaxonfiles.

        * Interact with Polyaxon server.

        * Run and Monitor experiments.

    Check the help available for each command listed below.
    """

    try:
        configure_logger(verbose or ClientConfigManager.get_value("debug"))
    except ValidationError:
        ClientConfigManager.purge()
    non_check_cmds = [
        "completion",
        "config",
        "version",
        "login",
        "logout",
        "deploy",
        "admin",
        "teardown",
    ]
    context.obj = context.obj or {}
    if not settings.CLIENT_CONFIG.client_header:
        settings.CLIENT_CONFIG.set_cli_header()
    context.obj["offline"] = offline
    if offline:
        os.environ["POLYAXON_IS_OFFLINE"] = "true"
        settings.CLIENT_CONFIG.is_offline = True
    if not (context.invoked_subcommand in non_check_cmds or offline):
        check_cli_version()
Beispiel #3
0
def purge():
    """Purge the global config values."""
    ClientConfigManager.purge()
    CliConfigManager.purge()
    AuthConfigManager.purge()
    ProjectManager.purge()
    RunManager.purge()
    Printer.print_success("Config was removed.")
Beispiel #4
0
def set_client_config():
    global CLIENT_CONFIG

    try:
        CLIENT_CONFIG = ClientConfigManager.get_config_from_env()
    except (TypeError, ValidationError):
        ClientConfigManager.purge()
        Printer.print_warning("Your client Configuration was purged!")
        CLIENT_CONFIG = ClientConfigManager.get_config_from_env()
Beispiel #5
0
def purge(cache_only):
    """Purge the global config values."""
    if not cache_only:
        ClientConfigManager.purge()
        CliConfigManager.purge()
        AuthConfigManager.purge()
        UserConfigManager.purge()
    ProjectConfigManager.purge()
    RunConfigManager.purge()
    Printer.print_success("Configs was removed.")
Beispiel #6
0
def show():
    """Show the current cli, client, and user configs."""
    _config = ClientConfigManager.get_config_or_default()
    Printer.print_header("Client config:")
    dict_tabulate(_config.to_dict())
    _config = CliConfigManager.get_config_or_default()
    if _config:
        Printer.print_header("CLI config:")
        if _config.current_version:
            click.echo("Version {}".format(_config.current_version))
        else:
            Printer.print_warning("This cli is not configured.")
        if _config.installation:
            config_installation = dict_to_tabulate(
                _config.installation,
                humanize_values=True,
                exclude_attrs=["hmac", "auth", "host"],
            )
            dict_tabulate(config_installation)
        else:
            Printer.print_warning(
                "This cli is not connected to a Polyaxon Host.")
    _config = UserConfigManager.get_config_or_default()
    if _config:
        Printer.print_header("User config:")
        config_user = dict_to_tabulate(
            _config.to_dict(),
            humanize_values=True,
            exclude_attrs=["theme"],
        )
        dict_tabulate(config_user)
Beispiel #7
0
def port_forward(port, namespace, deployment_type, release_name):
    """If you deploy Polyaxon using ClusterIP, you can use this command
    to access the gateway through `localhost:port`.
    """
    from polyaxon.deploy.operators.kubectl import KubectlOperator

    if not port and deployment_type in [
            DeploymentTypes.MICRO_K8S,
            DeploymentTypes.MINIKUBE,
    ]:
        port = 31833
    port = port or 8000
    namespace = namespace or "polyaxon"
    release_name = release_name or "polyaxon"

    kubectl = KubectlOperator()
    args = [
        "port-forward",
        "-n",
        namespace,
        "svc/{}-polyaxon-gateway".format(release_name),
        "{}:80".format(port),
    ]

    try:
        _config = ClientConfigManager.get_config_or_default()
    except Exception as e:
        handle_cli_error(e, message="Polyaxon load configuration.")
        Printer.print_header(
            "You can reset your config by running: polyaxon config purge")
        sys.exit(1)

    _config.host = "http://localhost:{}".format(port)
    ClientConfigManager.set_config(_config)
    CliConfigManager.purge()
    AuthConfigManager.purge()
    UserConfigManager.purge()
    Printer.print_header("Client configuration is updated!")
    Printer.print_success("Polyaxon will be available at: {}".format(
        _config.host))
    stdout = kubectl.execute(args=args,
                             is_json=False,
                             stream=settings.CLIENT_CONFIG.debug)
    click.echo(stdout)
Beispiel #8
0
def get(keys):
    """Get the global config values by keys.

    Example:

    \b
    $ polyaxon config get host port
    """
    _config = ClientConfigManager.get_config_or_default()

    if not keys:
        return

    print_values = {}
    for key in keys:
        if hasattr(_config, key):
            print_values[key] = getattr(_config, key)
        else:
            click.echo("Key `{}` is not recognised.".format(key))

    dict_tabulate(print_values)
Beispiel #9
0
def get(keys):
    """Get the specific keys from the global configuration.

    Example:

    \b
    $ polyaxon config get host verify-ssl
    """
    _config = ClientConfigManager.get_config_or_default()

    if not keys:
        return

    print_values = {}
    for key in keys:
        key = key.replace("-", "_")
        if hasattr(_config, key):
            print_values[key] = getattr(_config, key)
        else:
            click.echo("Key `{}` is not recognised.".format(key))

    dict_tabulate(print_values)
Beispiel #10
0
def config(list):  # pylint:disable=redefined-builtin
    """Set and get the global configurations."""
    if list:
        _config = ClientConfigManager.get_config_or_default()
        Printer.print_header("Current config:")
        dict_tabulate(_config.to_dict())
Beispiel #11
0
def set_client_config():
    global CLIENT_CONFIG

    try:
        CLIENT_CONFIG = ClientConfigManager.get_config_from_env()
    except (TypeError, ValidationError):
        ClientConfigManager.purge()
        Printer.print_warning("Your client Configuration was purged!")
        CLIENT_CONFIG = ClientConfigManager.get_config_from_env()


def set_auth_config():
    from polyaxon.managers.auth import AuthConfigManager

    global AUTH_CONFIG
    try:
        AUTH_CONFIG = AuthConfigManager.get_config_from_env()
    except (TypeError, ValidationError):
        AuthConfigManager.purge()
        Printer.print_warning("Your auth Configuration was purged!")


if not to_bool(os.environ.get(POLYAXON_KEYS_NO_CONFIG, False)):
    set_auth_config()
    set_client_config()
    if to_bool(os.environ.get(POLYAXON_KEYS_SET_AGENT, False)):
        set_agent_config()
else:
    CLIENT_CONFIG = ClientConfigManager.CONFIG(host=LOCALHOST)
Beispiel #12
0
    def get_config_from_manager():
        from polyaxon.managers.client import ClientConfigManager

        config = ClientConfigManager.get_config_or_default()
        config.token = AuthConfigManager.get_value("token")
        return config
Beispiel #13
0
from polyaxon.managers.auth import AuthConfigManager
from polyaxon.managers.client import ClientConfigManager
from polyaxon.utils.bool_utils import to_bool

MIN_TIMEOUT = 1
LONG_REQUEST_TIMEOUT = 3600
HEALTH_CHECK_INTERVAL = 60

AUTH_CONFIG = None
CLIENT_CONFIG = None
PROXIES_CONFIG = None
AGENT_CONFIG = None

if not to_bool(os.environ.get("POLYAXON_NO_CONFIG", False)):
    AUTH_CONFIG = AuthConfigManager.get_config_from_env()
    CLIENT_CONFIG = ClientConfigManager.get_config_from_env()

    if CLIENT_CONFIG.set_agent:
        from polyaxon.managers.agent import AgentManager

        AGENT_CONFIG = AgentManager.get_config_from_env(
            agent_path=CLIENT_CONFIG.agent_path
        )
else:
    CLIENT_CONFIG = ClientConfigManager.CONFIG()


def set_proxies_config():
    from polyaxon.managers.proxies import ProxiesManager

    global PROXIES_CONFIG
Beispiel #14
0
def purge():
    """Purge the global config values."""
    ClientConfigManager.purge()
    Printer.print_success("Config was removed.")
    # Reset cli config
    CliConfigManager.purge()
Beispiel #15
0
def cli(context, verbose, check_version, offline):
    """Polyaxon - Cloud Native Machine Learning Automation & Experimentation tool.

    This CLI provides tools to:

      - Parse, Validate, and Check Polyaxonfiles.

      - Interact with Polyaxon server.

      - Run and Monitor experiments and jobs.

    This CLI tool comes with a caching mechanism:

      - You can initialize a project with: polyaxon init [project name]

      - Otherwise Polyaxon will the default global path will be used for the cache.

    You can check the version of you CLI by running:

      - polyaxon version

    To Enable debug mode, you can use the `-v` flag:

      - polyaxon -v admin

    Common commands:

      - polyaxon project get

      - polyaxon run [-f] [-l]

      - polyaxon ops ls

      - polyaxon ops get

      - polyaxon config -l

      - polyaxon config set ...

    Admin deployment commands:

      - polyaxon admin deploy [-f] [--check]

      - polyaxon admin upgrade [-f] [--check]

      - polyaxon admin teardown [-f]

    For more information, please visit https://polyaxon.com/docs/core/cli/

    Check the help available for each command listed below.
    """

    try:
        configure_logger(verbose or ClientConfigManager.get_value("debug"))
    except ValidationError:
        ClientConfigManager.purge()
    non_check_cmds = [
        "completion",
        "config",
        "version",
        "login",
        "logout",
        "deploy",
        "admin",
        "teardown",
        "docker",
        "initializer",
        "sidecar",
        "proxy",
        "notify",
    ]
    context.obj = context.obj or {}
    if not settings.CLIENT_CONFIG.client_header:
        settings.CLIENT_CONFIG.set_cli_header()
    context.obj["offline"] = offline
    if offline:
        os.environ["POLYAXON_IS_OFFLINE"] = "true"
        settings.CLIENT_CONFIG.is_offline = True
    if check_version and not (context.invoked_subcommand in non_check_cmds
                              or offline or settings.CLIENT_CONFIG.no_api
                              or settings.CLIENT_CONFIG.is_ops or DOCS_GEN):
        check_cli_version()