Ejemplo n.º 1
0
 def teardown_on_kubernetes(self, hooks):
     args = ["delete", "--purge", "polyaxon"]
     if not hooks:
         args += ["--no-hooks"]
     click.echo("Running teardown command ...")
     self.helm.execute(args=args)
     Printer.print_success("Deployment successfully deleted.")
Ejemplo n.º 2
0
def delete(ctx):
    """Delete project.

    Uses /docs/core/cli/#caching
    """
    owner, project_name = get_project_or_local(ctx.obj.get("project"),
                                               is_cli=True)

    if not click.confirm("Are sure you want to delete project `{}/{}`".format(
            owner, project_name)):
        click.echo("Existing without deleting project.")
        sys.exit(1)

    try:
        polyaxon_client = ProjectClient(owner=owner, project=project_name)
        response = polyaxon_client.delete()
        local_project = ProjectManager.get_config()
        if local_project and (owner, project_name) == (
                local_project.user,
                local_project.name,
        ):
            # Purge caching
            ProjectManager.purge()
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not delete project `{}/{}`.".format(
                             owner, project_name))
        sys.exit(1)

    if response.status_code == 204:
        Printer.print_success("Project `{}/{}` was delete successfully".format(
            owner, project_name))
Ejemplo n.º 3
0
def deploy(config_file, manager_path, check, dry_run):
    """Deploy polyaxon."""
    config = read_deployment_config(config_file)
    manager = DeployManager(config=config,
                            filepath=config_file,
                            manager_path=manager_path,
                            dry_run=dry_run)
    exception = None
    if check:
        try:
            manager.check()
        except Exception as e:
            handle_cli_error(e,
                             message="Polyaxon deployment file is not valid.")
            sys.exit(1)

        Printer.print_success("Polyaxon deployment file is valid.")
    else:
        try:
            manager.install()
        except Exception as e:
            Printer.print_error("Polyaxon could not be installed.")
            exception = e

    if exception:
        Printer.print_error("Error message: {}.".format(exception))
Ejemplo n.º 4
0
def resume(ctx, polyaxonfile):
    """Resume run.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops --uid=8aac02e3a62a4f0aaa257c59da5eab80 resume
    """
    content = None
    if polyaxonfile:
        content = "{}".format(ConfigSpec.read_from(polyaxonfile))

    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True,
    )
    try:
        polyaxon_client = RunClient(
            owner=owner, project=project_name, run_uuid=run_uuid
        )
        response = polyaxon_client.resume(override_config=content)
        Printer.print_success("Run was resumed with uid {}".format(response.uuid))
    except (ApiException, HTTPError) as e:
        handle_cli_error(e, message="Could not resume run `{}`.".format(run_uuid))
        sys.exit(1)
Ejemplo n.º 5
0
def deploy(config_file, deployment_type, manager_path, check, dry_run):
    """Deploy polyaxon."""
    config = read_deployment_config(config_file)
    manager = DeployManager(
        config=config,
        filepath=config_file,
        deployment_type=deployment_type,
        manager_path=manager_path,
        dry_run=dry_run,
    )
    exception = None
    if config:
        Printer.print_success("Polyaxon `{}` deployment file is valid.".format(
            config.deployment_chart))
    if check:
        try:
            manager.check()
        except Exception as e:
            handle_cli_error(e,
                             message="Polyaxon deployment manager error.",
                             sys_exit=True)

    else:
        try:
            manager.install()
        except Exception as e:
            Printer.print_error("Polyaxon could not be installed.")
            exception = e

    if exception:
        Printer.print_error("Error message: {}.".format(exception),
                            sys_exit=True)
Ejemplo n.º 6
0
def approve(ctx, project, uid):
    """Approve a run waiting for human validation.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops approve

    \b
    $ polyaxon ops approve --uid=8aac02e3a62a4f0aaa257c59da5eab80
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        project or ctx.obj.get("project"),
        uid or ctx.obj.get("run_uuid"),
        is_cli=True,
    )

    try:
        polyaxon_client = RunClient(owner=owner,
                                    project=project_name,
                                    run_uuid=run_uuid)
        polyaxon_client.approve()
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not approve run `{}`.".format(run_uuid))
        sys.exit(1)

    Printer.print_success("Run is approved")
Ejemplo n.º 7
0
def delete(ctx):
    """Delete a run.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon ops delete

    \b
    $ polyaxon ops --uid=8aac02e3a62a4f0aaa257c59da5eab80 delete  # project is cached

    \b
    $ polyaxon ops --project=cats-vs-dogs -uid 8aac02e3a62a4f0aaa257c59da5eab80 delete
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True,
    )
    if not click.confirm("Are sure you want to delete run `{}`".format(run_uuid)):
        click.echo("Existing without deleting the run.")
        sys.exit(1)

    try:
        polyaxon_client = RunClient(
            owner=owner, project=project_name, run_uuid=run_uuid
        )
        polyaxon_client.delete()
        # Purge caching
        RunManager.purge()
    except (ApiException, HTTPError) as e:
        handle_cli_error(e, message="Could not delete run `{}`.".format(run_uuid))
        sys.exit(1)

    Printer.print_success("Run `{}` was delete successfully".format(run_uuid))
Ejemplo n.º 8
0
def delete(component, version):
    """Delete a component hub or a component version."""
    owner, component_hub, component_version, is_version = get_info(
        component, version)
    full_entity = ("{}/{}:{}".format(owner, component_hub, component_version)
                   if is_version else "{}/{}".format(owner, component_hub))

    if not click.confirm(
            "Are sure you want to delete component {} `{}`".format(
                "version" if is_version else "hub", full_entity)):
        click.echo("Existing without deleting component hub.")
        sys.exit(1)

    try:
        polyaxon_client = PolyaxonClient()
        if is_version:
            polyaxon_client.component_hub_v1.delete_component_version(
                owner, component_hub, component_version)
        else:
            polyaxon_client.component_hub_v1.delete_component_hub(
                owner, component_hub)
        Printer.print_success(
            "Component {} `{}` was delete successfully".format(
                "version" if is_version else "hub", full_entity))
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e,
            message="Could not delete component {} `{}`.".format(
                "version" if is_version else "hub", full_entity),
        )
        sys.exit(1)
Ejemplo n.º 9
0
def update(component, version, name, description, tags, private):
    """Update component hub.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon hub update foobar --description="Image Classification with DL using TensorFlow"

    \b
    $ polyaxon hub update mike1/foobar --description="Image Classification with DL using TensorFlow"

    \b
    $ polyaxon hub update --tags="foo, bar"
    """
    owner, component_hub, component_version, is_version = get_info(
        component, version)
    full_entity = ("{}/{}:{}".format(owner, component_hub, component_version)
                   if is_version else "{}/{}".format(owner, component_hub))

    update_dict = {}
    if name:
        update_dict["name"] = name

    if description:
        update_dict["description"] = description

    tags = validate_tags(tags)
    if tags:
        update_dict["tags"] = tags

    if private is not None:
        update_dict["is_public"] = not private

    if not update_dict:
        Printer.print_warning(
            "No argument was provided to update the component {}.".format(
                "version" if is_version else "hub"))
        sys.exit(1)

    try:
        polyaxon_client = PolyaxonClient()
        if is_version:
            response = polyaxon_client.component_hub_v1.patch_component_version(
                owner, component_hub, component_version, body=update_dict)
            Printer.print_success("Component version updated.")
            get_component_version_details(response)
        else:
            response = polyaxon_client.component_hub_v1.patch_component_hub(
                owner, component_hub, body=update_dict)
            Printer.print_success("Component updated.")
            get_entity_details(response, "Component hub")
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e,
            message="Could not update component {} `{}`.".format(
                "version" if is_version else "hub", full_entity),
        )
        sys.exit(1)
Ejemplo n.º 10
0
def delete(model, version):
    """Delete a model registry or a model version."""
    owner, model_registry, model_version, is_version = get_info(model, version)
    full_entity = ("{}/{}:{}".format(owner, model_registry, model_version)
                   if is_version else "{}/{}".format(owner, model_registry))

    if not click.confirm("Are sure you want to delete model {} `{}`".format(
            "version" if is_version else "registry", full_entity)):
        click.echo("Existing without deleting model registry.")
        sys.exit(1)

    try:
        polyaxon_client = PolyaxonClient()
        if is_version:
            polyaxon_client.model_registry_v1.delete_model_version(
                owner, model_registry, model_version)
        else:
            polyaxon_client.model_registry_v1.delete_model_registry(
                owner, model_registry)
        Printer.print_success("Model {} `{}` was delete successfully".format(
            "version" if is_version else "registry", full_entity))
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e,
            message="Could not delete model {} `{}`.".format(
                "version" if is_version else "registry", full_entity),
        )
        sys.exit(1)
Ejemplo n.º 11
0
def create(ctx, name, owner, description, private, init):
    """Create a new project.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon project create --name=cats-vs-dogs --description="Image Classification with DL"
    """
    owner = owner or AuthConfigManager.get_value("username")

    if not owner:
        Printer.print_error(
            "Please login first or provide a valid owner --owner. "
            "`polyaxon login --help`")
        sys.exit(1)

    try:
        project_config = V1Project(name=name,
                                   description=description,
                                   is_public=not private)
        _project = ProjectClient(owner=owner).create(project_config)
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not create project `{}`.".format(name))
        sys.exit(1)

    Printer.print_success("Project `{}` was created successfully.".format(
        _project.name))

    if init:
        ctx.obj = {}
        ctx.invoke(init_project, project=name)
Ejemplo n.º 12
0
def artifacts(ctx):
    """Download outputs/artifacts for run.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops -uid=8aac02e3a62a4f0aaa257c59da5eab80 artifacts
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"),
        ctx.obj.get("run_uuid"),
        is_cli=True,
    )
    try:
        client = RunClient(owner=owner,
                           project=project_name,
                           run_uuid=run_uuid)
        client.download_artifacts()
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e,
            message="Could not download outputs for run `{}`.".format(
                run_uuid))
        sys.exit(1)
    Printer.print_success("Files downloaded.")
Ejemplo n.º 13
0
def restart(ctx, copy, polyaxonfile, u):
    """Restart run.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon run --uid=8aac02e3a62a4f0aaa257c59da5eab80 restart
    ```
    """
    content = None
    if polyaxonfile:
        content = "{}".format(reader.read(polyaxonfile))

    # Check if we need to upload
    if u:
        ctx.invoke(upload, sync=False)

    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True)
    try:
        polyaxon_client = RunClient(owner=owner,
                                    project=project_name,
                                    run_uuid=run_uuid)
        response = polyaxon_client.restart(override_config=content, copy=copy)
        Printer.print_success("Run was {} with uid {}".format(
            "copied" if copy else "restarted", response.uuid))
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not restart run `{}`.".format(run_uuid))
        sys.exit(1)
Ejemplo n.º 14
0
 def create_run():
     click.echo("Creating a run.")
     try:
         compiled_operation = OperationSpecification.compile_operation(
             op_spec)
         run_name = compiled_operation.name or name
         resource = compiler.make(
             owner_name=owner,
             project_name=project_name,
             project_uuid=project_name,
             run_uuid=run_name,
             run_name=name,
             run_path=run_name,
             compiled_operation=compiled_operation,
             params=op_spec.params,
             default_sa=settings.AGENT_CONFIG.runs_sa,
         )
         Spawner(namespace=settings.AGENT_CONFIG.namespace).create(
             run_uuid=run_name,
             run_kind=compiled_operation.get_run_kind(),
             resource=resource,
         )
         # cache.cache(config_manager=RunConfigManager, response=response)
         run_job_uid = get_resource_name(run_name)
         Printer.print_success(
             "A new run `{}` was created".format(run_job_uid))
     except (PolyaxonCompilerError, PolyaxonK8SError,
             PolypodException) as e:
         handle_cli_error(e, message="Could not create a run.")
         sys.exit(1)
Ejemplo n.º 15
0
 def upgrade_on_kubernetes(self):
     args = ["upgrade", self.release_name]
     if self.manager_path:
         args += [self.manager_path]
     else:
         args += [self.k8s_chart]
     if self.filepath:
         args += ["-f", self.filepath]
     if self.type and self.type in [
             DeploymentTypes.MICRO_K8S,
             DeploymentTypes.MINIKUBE,
     ]:
         args += [
             "--set",
             "gateway.service.type=NodePort,deploymentType={}".format(
                 self.type),
         ]
     if self.deployment_version:
         args += ["--version", self.deployment_version]
     args += ["--namespace={}".format(self.deployment_namespace)]
     if self.dry_run:
         args += ["--debug", "--dry-run"]
     click.echo("Running upgrade command ...")
     stdout = self.helm.execute(args=args,
                                stream=settings.CLIENT_CONFIG.debug)
     click.echo(stdout)
     Printer.print_success("Deployment upgraded.")
Ejemplo n.º 16
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()
Ejemplo n.º 17
0
def upload(ctx, project, uid, path_from, path_to, is_file, sync_failure):
    """Upload runs' artifacts.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops upload -uid=8aac02e3a62a4f0aaa257c59da5eab80

    \b
    $ polyaxon ops upload -uid=8aac02e3a62a4f0aaa257c59da5eab80 path_from="path/to/upload"

    \b
    $ polyaxon ops upload -uid=8aac02e3a62a4f0aaa257c59da5eab80 path_to="path/to/upload/to"
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        project or ctx.obj.get("project"),
        uid or ctx.obj.get("run_uuid"),
        is_cli=True,
    )
    try:
        client = RunClient(owner=owner,
                           project=project_name,
                           run_uuid=run_uuid)
        if is_file:
            response = client.upload_artifact(filepath=path_from,
                                              path=path_to,
                                              overwrite=True)
        else:
            response = client.upload_artifacts_dir(
                dirpath=path_from,
                path=path_to,
                overwrite=True,
                relative_to=path_from,
            )
    except (
            ApiException,
            HTTPError,
            PolyaxonHTTPError,
            PolyaxonShouldExitError,
            PolyaxonClientException,
    ) as e:
        handle_cli_error(
            e,
            message="Could not upload artifacts for run `{}`".format(run_uuid))
        sys.exit(1)

    if response.status_code == 200:
        Printer.print_success("Artifacts uploaded")
    else:
        if sync_failure:
            client.log_failed(reason="OperationCli",
                              message="Operation failed uploading artifacts")
        Printer.print_error(
            "Error uploading artifacts. "
            "Status: {}. Error: {}.".format(response.status_code,
                                            response.content),
            sys_exit=True,
        )
Ejemplo n.º 18
0
def stop(ctx, yes):
    """Stop run.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon runs stop
    ```

    \b
    ```bash
    $ polyaxon runs --uid=8aac02e3a62a4f0aaa257c59da5eab80 stop
    ```
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"))
    if not yes and not click.confirm("Are sure you want to stop "
                                     "run `{}`".format(run_uuid)):
        click.echo("Existing without stopping run.")
        sys.exit(0)

    try:
        polyaxon_client = PolyaxonClient()
        polyaxon_client.runs_v1.stop_run(owner, project_name, run_uuid)
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not stop run `{}`.".format(run_uuid))
        sys.exit(1)

    Printer.print_success("Run is being stopped.")
Ejemplo n.º 19
0
def invalidate(ctx, project, uid):
    """Invalidate the run's cache state.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops invalidate
    """

    owner, project_name, run_uuid = get_project_run_or_local(
        project or ctx.obj.get("project"),
        uid or ctx.obj.get("run_uuid"),
        is_cli=True,
    )
    try:
        polyaxon_client = RunClient(owner=owner,
                                    project=project_name,
                                    run_uuid=run_uuid)
        response = polyaxon_client.invalidate()
        Printer.print_success("Run was invalidated with uid {}".format(
            response.uuid))
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not invalidate run `{}`.".format(run_uuid))
        sys.exit(1)
Ejemplo n.º 20
0
def resume(ctx, polyaxonfile, u):
    """Resume run.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon runs --uid=8aac02e3a62a4f0aaa257c59da5eab80 resume
    ```
    """
    content = None
    if polyaxonfile:
        content = "{}".format(rhea.read(polyaxonfile))

    # Check if we need to upload
    if u:
        ctx.invoke(upload, sync=False)

    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"))
    try:
        polyaxon_client = PolyaxonClient()
        body = V1Run(content=content)
        response = polyaxon_client.runs_v1.resume_run(owner, project_name,
                                                      run_uuid, body)
        Printer.print_success("Run was resumed with uid {}".format(
            response.uuid))
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not resume run `{}`.".format(run_uuid))
        sys.exit(1)
Ejemplo n.º 21
0
def stop(ctx, yes):
    """Stop run.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops stop

    \b
    $ polyaxon ops --uid=8aac02e3a62a4f0aaa257c59da5eab80 stop
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True,
    )
    if not yes and not click.confirm(
        "Are sure you want to stop " "run `{}`".format(run_uuid)
    ):
        click.echo("Existing without stopping run.")
        sys.exit(0)

    try:
        polyaxon_client = RunClient(
            owner=owner, project=project_name, run_uuid=run_uuid
        )
        polyaxon_client.stop()
    except (ApiException, HTTPError) as e:
        handle_cli_error(e, message="Could not stop run `{}`.".format(run_uuid))
        sys.exit(1)

    Printer.print_success("Run is being stopped.")
Ejemplo n.º 22
0
def invalidate_run(ctx):
    """Invalidate runs' cache inside this project.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon invalidate_builds
    ```
    """

    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"))
    try:
        polyaxon_client = PolyaxonClient()
        response = polyaxon_client.runs_v1.invalidate_run(
            owner, project_name, run_uuid)
        Printer.print_success("Run was invalidated with uid {}".format(
            response.uuid))
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not invalidate run `{}`.".format(run_uuid))
        sys.exit(1)
Ejemplo n.º 23
0
def artifacts(ctx, path, path_to, no_untar):
    """Download outputs/artifacts for run.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops -uid=8aac02e3a62a4f0aaa257c59da5eab80 artifacts

    \b
    $ polyaxon ops -uid=8aac02e3a62a4f0aaa257c59da5eab80 artifacts path="events/only"

    \b
    $ polyaxon ops -uid=8aac02e3a62a4f0aaa257c59da5eab80 artifacts path_to="this/path"
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True,
    )
    try:
        client = RunClient(owner=owner, project=project_name, run_uuid=run_uuid)
        download_path = client.download_artifacts(
            path=path or "", path_to=path_to, untar=not no_untar
        )
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not download outputs for run `{}`.".format(run_uuid)
        )
        sys.exit(1)
    Printer.print_success("Files downloaded: path: {}".format(download_path))
Ejemplo n.º 24
0
def unbookmark(ctx):
    """Unbookmark run.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon runs unbookmark
    ```

    \b
    ```bash
    $ polyaxon runs -uid=8aac02e3a62a4f0aaa257c59da5eab80 unbookmark
    ```
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"))
    try:
        polyaxon_client = PolyaxonClient()
        polyaxon_client.runs_v1.unbookmark_run(owner, project_name, run_uuid)
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not unbookmark run `{}`.".format(run_uuid))
        sys.exit(1)

    Printer.print_success("Run is unbookmarked.")
Ejemplo n.º 25
0
 def install_on_docker_compose(self):
     path = ComposeConfigManager.get_config_filepath()
     path = "/".join(path.split("/")[:-1])
     # Fetch docker-compose
     Transport().download(
         url=
         "https://github.com/polyaxon/polyaxon-compose/archive/master.tar.gz",
         filename=path + "/file",
         untar=True,
         delete_tar=True,
         extract_path=path,
     )
     # Move necessary info
     shutil.copy(
         path + "/polyaxon-compose-master/docker-compose.yml",
         path + "/docker-compose.yml",
     )
     shutil.copy(path + "/polyaxon-compose-master/components.env",
                 path + "/components.env")
     shutil.copy(path + "/polyaxon-compose-master/base.env",
                 path + "/base.env")
     shutil.rmtree(path + "/polyaxon-compose-master/")
     # Generate env from config
     ComposeConfigManager.set_config(self.compose.generate_env(self.config))
     Printer.print_success("Docker Compose deployment is initialised.")
     if self.dry_run:
         Printer.print_success("Polyaxon generated deployment env.")
         return
     self.docker.execute(["volume", "create", "--name=polyaxon-postgres"])
     Printer.print_success("Docker volume created.")
     self.compose.execute(["-f", path + "/docker-compose.yml", "up", "-d"])
     Printer.print_success("Deployment is running in the background.")
     Printer.print_success("You can configure your CLI by running: "
                           "polyaxon config set --host=localhost.")
Ejemplo n.º 26
0
def restart(ctx, project, uid, copy, polyaxonfile):
    """Restart run.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon run --uid=8aac02e3a62a4f0aaa257c59da5eab80 restart
    """
    content = None
    if polyaxonfile:
        content = OperationSpecification.read(
            polyaxonfile, is_preset=True).to_dict(dump=True)

    owner, project_name, run_uuid = get_project_run_or_local(
        project or ctx.obj.get("project"),
        uid or ctx.obj.get("run_uuid"),
        is_cli=True,
    )
    try:
        polyaxon_client = RunClient(owner=owner,
                                    project=project_name,
                                    run_uuid=run_uuid)
        response = polyaxon_client.restart(override_config=content, copy=copy)
        Printer.print_success("Run was {} with uid {}".format(
            "copied" if copy else "restarted", response.uuid))
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not restart run `{}`.".format(run_uuid))
        sys.exit(1)
Ejemplo n.º 27
0
def upload(sync=True):  # pylint:disable=assign-to-new-keyword
    """Upload code of the current directory while respecting the .polyaxonignore file."""
    project = ProjectManager.get_config_or_raise()
    files = IgnoreManager.get_unignored_filepaths()
    try:
        with create_project_tarfile(files, project.name) as filepath:
            with get_files_by_paths("repo", [filepath]) as (files, files_size):
                try:
                    PolyaxonClient().project.upload_repo(project.user,
                                                         project.name,
                                                         files,
                                                         files_size,
                                                         sync=sync)
                except (
                        PolyaxonHTTPError,
                        PolyaxonShouldExitError,
                        PolyaxonClientException,
                ) as e:
                    handle_cli_error(
                        e,
                        message="Could not upload code for project `{}`.".
                        format(project.name),
                    )
                    Printer.print_error(
                        "Check the project exists, "
                        "and that you have access rights, "
                        "this could happen as well when uploading large files. "
                        "Please also make sure that you have enough space to upload the data."
                    )
                    sys.exit(1)
                Printer.print_success("Files uploaded.")
    except Exception as e:
        handle_cli_error(e, message="Could not upload the file.")
        sys.exit(1)
Ejemplo n.º 28
0
def upgrade(config_file, deployment_type, manager_path, check, dry_run):
    """Upgrade a Polyaxon deployment."""
    config = read_deployment_config(config_file, command="upgrade")
    manager = DeployConfigManager(
        config=config,
        filepath=config_file,
        deployment_type=deployment_type,
        manager_path=manager_path,
        dry_run=dry_run,
    )
    exception = None
    if config:
        Printer.print_success("Polyaxon `{}` deployment file is valid.".format(
            config.deployment_chart))
    if check:
        try:
            manager.check()
        except Exception as e:
            handle_cli_error(e,
                             message="Polyaxon deployment manager error.",
                             sys_exit=True)
    else:
        try:
            manager.upgrade()
        except Exception as e:
            Printer.print_error("Polyaxon could not upgrade the deployment.")
            exception = e

    if exception:
        Printer.print_error("Error message: {}.".format(exception))
Ejemplo n.º 29
0
def check_polyaxonfile(polyaxonfile,
                       params=None,
                       profile=None,
                       queue=None,
                       nocache=None,
                       log=True):
    if not polyaxonfile:
        polyaxonfile = PolyaxonFile.check_default_path(path=".")
    if not polyaxonfile:
        polyaxonfile = ""

    polyaxonfile = to_list(polyaxonfile)
    exists = [os.path.isfile(f) for f in polyaxonfile]

    parsed_params = None
    if params:
        parsed_params = parse_params(params)

    if not any(exists):
        Printer.print_error("Polyaxonfile is not present, "
                            "please run {}".format(constants.INIT_COMMAND))
        sys.exit(1)

    try:
        plx_file = PolyaxonFile(polyaxonfile)
        plx_file = plx_file.get_op_specification(params=parsed_params,
                                                 profile=profile,
                                                 queue=queue,
                                                 nocache=nocache)
        if log:
            Printer.print_success("Polyaxonfile valid")
        return plx_file
    except Exception as e:
        handle_cli_error(e, message="Polyaxonfile is not valid.")
        sys.exit(1)
Ejemplo n.º 30
0
 def create_run():
     click.echo("Creating a run.")
     try:
         polyaxon_client = RunClient(owner=owner, project=project_name)
         response = polyaxon_client.create(
             name=name, description=description, tags=tags, content=op_spec
         )
         config = polyaxon_client.client.sanitize_for_serialization(response)
         cache.cache(
             config_manager=RunManager,
             config=config,
             owner=owner,
             project=project_name,
         )
         Printer.print_success("A new run `{}` was created".format(response.uuid))
         click.echo(
             "You can view this run on Polyaxon UI: {}".format(
                 get_dashboard_url(
                     subpath="{}/{}/runs/{}".format(
                         owner, project_name, response.uuid
                     )
                 )
             )
         )
     except (ApiException, HTTPError) as e:
         handle_cli_error(e, message="Could not create a run.")
         sys.exit(1)