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)
def create_run(is_managed: bool = True, meta_info: Dict = None): is_approved = False if upload else None try: response = polyaxon_client.create( name=name, description=description, tags=tags, content=op_spec, is_managed=is_managed, is_approved=is_approved, meta_info=meta_info, ) Printer.print_success("A new run `{}` was created".format( response.uuid)) if not eager: cache_run(response) click.echo("You can view this run on Polyaxon UI: {}".format( get_dashboard_url(subpath="{}/{}/runs/{}".format( owner, project_name, response.uuid)))) return response.uuid except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create a run.", http_messages_mapping={ 404: "Make sure you have a project initialized in your current workdir, " "otherwise you need to pass a project with `-p/--project`. " "The project {}/{} does not exist.".format( owner, project_name) }, ) sys.exit(1)
def dashboard(ctx, yes, url): """Open this operation's dashboard details in browser.""" owner, project_name, run_uuid = get_project_run_or_local( ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True, ) subpath = "{}/{}/runs/{}".format(owner, project_name, run_uuid) get_dashboard( dashboard_url=get_dashboard_url(subpath=subpath), url_only=url, yes=yes )
def create(ctx, name, description, tags, public, init): """Create a new project. Uses /docs/core/cli/#caching Example: \b $ polyaxon project create --name=cats-vs-dogs --description="Image Classification with DL" \b $ polyaxon project create --name=owner/name --description="Project Description" """ if not name: Printer.print_error( "Please provide a valid name to create a project.", command_help="project create", sys_exit=True, ) owner, project_name = resolve_entity_info(name or ctx.obj.get("project"), is_cli=True, entity_name="project") tags = validate_tags(tags) if not owner: Printer.print_error( "Please provide a valid name with an owner namespace: --name=owner/project." ) sys.exit(1) try: project_config = V1Project(name=project_name, description=description, tags=tags, is_public=public) polyaxon_client = ProjectClient(owner=owner) _project = polyaxon_client.create(project_config) config = polyaxon_client.client.sanitize_for_serialization(_project) cache.cache(config_manager=ProjectConfigManager, config=config) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create project `{}`.".format(project_name)) sys.exit(1) Printer.print_success("Project `{}` was created successfully.".format( _project.name)) click.echo("You can view this project on Polyaxon UI: {}".format( get_dashboard_url(subpath="{}/{}".format(owner, _project.name)))) if init: ctx.obj = {} ctx.invoke( init_project, project="{}/{}".format(owner, project_name), polyaxonignore=True, )
def create(ctx, name, description, tags, private, init): """Create a new project. Uses /docs/core/cli/#caching Example: \b $ polyaxon project create --project=cats-vs-dogs --description="Image Classification with DL" \b $ polyaxon project create --project=owner/name --description="Project Description" """ if not name: Printer.print_error( "Please login provide a name to create a project.", command_help="project create", sys_exit=True, ) owner, project_name = get_project_or_local(name or ctx.obj.get("project"), is_cli=True) owner = owner or settings.AUTH_CONFIG.username if not owner and (not settings.CLI_CONFIG or settings.CLI_CONFIG.is_ce): owner = DEFAULT tags = validate_tags(tags) if not owner: Printer.print_error( "Please login first or provide a valid name with owner --name=owner/project. " "`polyaxon login --help`") sys.exit(1) try: project_config = V1Project(name=project_name, description=description, tags=tags, is_public=not private) polyaxon_client = ProjectClient(owner=owner) _project = polyaxon_client.create(project_config) config = polyaxon_client.client.sanitize_for_serialization(_project) cache.cache(config_manager=ProjectConfigManager, config=config) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create project `{}`.".format(project_name)) sys.exit(1) Printer.print_success("Project `{}` was created successfully.".format( _project.name)) click.echo("You can view this project on Polyaxon UI: {}".format( get_dashboard_url(subpath="{}/{}".format(owner, _project.name)))) if init: ctx.obj = {} ctx.invoke(init_project, project="{}/{}".format(owner, project_name))
def create(name, description, tags, public): """Create a new model. Example: \b $ polyaxon registry create --name=kaniko --description="Tool to build container images" \b $ polyaxon registry create --name=owner/name --description="Model description" """ if not name: Printer.print_error( "Please provide a name to create a model registry.", command_help="registry create", sys_exit=True, ) owner, registry_name, _, _ = get_info(name, None) tags = validate_tags(tags) if not owner or not registry_name: Printer.print_error( "Please provide a valid model name with --name=owner/registry-name. " ) sys.exit(1) try: registry_config = V1ModelRegistry( name=registry_name, description=description, tags=tags, is_public=public ) polyaxon_client = PolyaxonClient() _registry = polyaxon_client.model_registry_v1.create_model_registry( owner, registry_config ) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create model registry `{}`.".format(registry_name) ) sys.exit(1) Printer.print_success( "Model registry `{}` was created successfully.".format(_registry.name) ) click.echo( "You can view this model registry on Polyaxon UI: {}".format( get_dashboard_url(subpath="{}/registry/{}".format(owner, _registry.name)) ) )
def dashboard(ctx, _project, yes, url): """Open this operation's dashboard details in browser.""" owner, project_name = get_project_or_local( _project or ctx.obj.get("project"), is_cli=True ) project_url = get_dashboard_url(subpath="{}/{}".format(owner, project_name)) if url: Printer.print_header("The dashboard is available at: {}".format(project_url)) sys.exit(0) if not yes: click.confirm( "Dashboard page will now open in your browser. Continue?", abort=True, default=True, ) click.launch(project_url)
def create(name, description, tags, public): """Create a new component. Example: \b $ polyaxon hub create --name=kaniko --description="Tool to build container images" \b $ polyaxon hub create --name=owner/name --description="Component description" """ if not name: Printer.print_error( "Please provide a name to create a component hub.", command_help="hub create", sys_exit=True, ) owner, hub_name, _, _ = get_info(name, None) tags = validate_tags(tags) if not owner or not hub_name: Printer.print_error( "Please provide a valid component name with --name=owner/hub-name. " ) sys.exit(1) try: hub_config = V1ComponentHub( name=hub_name, description=description, tags=tags, is_public=public ) polyaxon_client = PolyaxonClient() _hub = polyaxon_client.component_hub_v1.create_component_hub(owner, hub_config) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create component hub `{}`.".format(hub_name) ) sys.exit(1) Printer.print_success( "Component hub `{}` was created successfully.".format(_hub.name) ) click.echo( "You can view this component hub on Polyaxon UI: {}".format( get_dashboard_url(subpath="{}/hub/{}".format(owner, _hub.name)) ) )
def dashboard(model, version, yes, url): """Open this operation's dashboard details in browser.""" owner, model_registry, model_version, is_version = get_info(model, version) subpath = ("{}/registry/{}/versions?version={}".format( owner, model_registry, model_version) if is_version else "{}/registry/{}".format(owner, model_registry)) registry_url = get_dashboard_url(subpath=subpath) if url: Printer.print_header( "The dashboard is available at: {}".format(registry_url)) sys.exit(0) if not yes: click.confirm( "Dashboard page will now open in your browser. Continue?", abort=True, default=True, ) click.launch(registry_url)
def create_run(is_manged: bool = True): try: response = polyaxon_client.create( name=name, description=description, tags=tags, content=op_spec, is_managed=is_manged, ) Printer.print_success("A new run `{}` was created".format( response.uuid)) if not eager: cache_run(response) 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)
def dashboard(component, version, yes, url): """Open this operation's dashboard details in browser.""" owner, component_hub, component_version, is_version = get_info(component, version) subpath = ( "{}/hub/{}/versions?version={}".format(owner, component_hub, component_version) if is_version else "{}/hub/{}".format(owner, component_hub) ) hub_url = get_dashboard_url(subpath=subpath, use_cloud=settings.CLI_CONFIG.is_ce) if url: Printer.print_header("The dashboard is available at: {}".format(hub_url)) sys.exit(0) if not yes: click.confirm( "Dashboard page will now open in your browser. Continue?", abort=True, default=True, ) click.launch(hub_url)
def push(polyaxonfile, name, description, tags): """Push a new component version. If the name corresponds to an existing component version, it will be updated. Example: \b $ polyaxon hub push -f polyaxonfile.yaml --name=kaniko:latest --description="Tool to build container images" \b $ polyaxon hub push -f polyaxonfile.yaml --name=owner/name:v1 --description="Component description" """ if not name: Printer.print_error( "Please provide a name to create a component version.", command_help="hub push", sys_exit=True, ) owner, hub_name, version, is_version = get_info(None, name) tags = validate_tags(tags) if not polyaxonfile or not os.path.isfile(polyaxonfile): Printer.print_error( "Please provide a path to a polyaxonfile to create a component version.", command_help="hub push", sys_exit=True, ) try: plx_file = get_specification(data=polyaxonfile) except Exception as e: handle_cli_error(e, message="Polyaxonfile is not valid.") sys.exit(1) if not owner or not hub_name or not version: Printer.print_error( "Please provide a valid component version with --name=owner/hub-name:version. " ) sys.exit(1) polyaxon_client = PolyaxonClient() try: polyaxon_client.component_hub_v1.get_component_version(owner, hub_name, version) to_update = True except (ApiException, HTTPError): to_update = False if to_update: if not click.confirm( "A component version {}/{}:{} already exists. " "Do you want to push force this version?".format(owner, hub_name, version) ): click.echo("Existing without pushing component version.") sys.exit(1) try: hub_config = V1ComponentVersion( name=version, description=description, tags=tags, content=plx_file.to_dict(dump=True), ) if to_update: _version = polyaxon_client.component_hub_v1.update_component_version( owner, hub_name, version, hub_config, ) else: _version = polyaxon_client.component_hub_v1.create_component_version( owner, hub_name, hub_config, ) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create component version `{}`.".format(hub_name) ) sys.exit(1) Printer.print_success( "Component version `{}` was created successfully.".format(_version.name) ) click.echo( "You can view this component version on Polyaxon UI: {}".format( get_dashboard_url( subpath="{}/hub/{}/versions/{}".format(owner, hub_name, _version.name) ) ) )
def login(token, username, password): """Login to Polyaxon Cloud or Polyaxon EE.""" if not settings.CLI_CONFIG or settings.CLI_CONFIG.is_ce: handle_command_not_in_ce() polyaxon_client = PolyaxonClient() if username and not token: # Use user or email / password login if not password: password = click.prompt("Please enter your password", type=str, hide_input=True) password = password.strip() if not password: logger.info( "You entered an empty string. " "Please make sure you enter your password correctly.") sys.exit(1) try: body = V1Credentials(username=username, password=password) access_auth = polyaxon_client.auth_v1.login(body=body) except (ApiException, HTTPError) as e: AuthConfigManager.purge() UserConfigManager.purge() CliConfigManager.purge() handle_cli_error(e, message="Could not login.") sys.exit(1) if not access_auth.token: Printer.print_error("Failed to login") return else: if not token: token_url = get_dashboard_url(subpath="profile/token") click.confirm( "Authentication token page will now open in your browser. Continue?", abort=True, default=True, ) click.launch(token_url) logger.info("Please copy and paste the authentication token.") token = click.prompt( "This is an invisible field. Paste token and press ENTER", type=str, hide_input=True, ) if not token: logger.info( "Empty token received. " "Make sure your shell is handling the token appropriately.") logger.info( "See docs for help: http://polyaxon.com/docs/polyaxon_cli/commands/auth" ) return access_auth = polyaxon_sdk.models.V1Auth(token=token.strip(" ")) # Set user try: AuthConfigManager.purge() UserConfigManager.purge() polyaxon_client = PolyaxonClient(token=access_auth.token) user = polyaxon_client.users_v1.get_user() except (ApiException, HTTPError) as e: handle_cli_error(e, message="Could not load user info.") sys.exit(1) access_token = AccessTokenConfig(username=user.username, token=access_auth.token) AuthConfigManager.set_config(access_token) UserConfigManager.set_config(user) polyaxon_client.config.token = access_auth.token Printer.print_success("Login successful") set_versions_config(polyaxon_client=polyaxon_client, set_handler=True)
def dashboard(yes, url): """Open dashboard in browser.""" get_dashboard(dashboard_url=get_dashboard_url(base="_admin"), url_only=url, yes=yes)
def push(name, description, tags, run_uid): """Push a new model version. If the name corresponds to an existing model version, it will be updated. Example: \b $ polyaxon registry push -f polyaxonfile.yaml --name=kaniko:latest --description="Tool to build container images" \b $ polyaxon registry push -f polyaxonfile.yaml --name=owner/name:v1 --description="Model description" """ if not name: Printer.print_error( "Please provide a name to create a model version.", command_help="registry push", sys_exit=True, ) owner, registry_name, version, is_version = get_info(None, name) tags = validate_tags(tags) if not owner or not registry_name or not version: Printer.print_error( "Please provide a valid model version with --name=owner/registry-name:version. " ) sys.exit(1) polyaxon_client = PolyaxonClient() try: polyaxon_client.model_registry_v1.get_model_version( owner, registry_name, version ) to_update = True except (ApiException, HTTPError): to_update = False if to_update: if not click.confirm( "A model version {}/{}:{} already exists. " "Do you want to push force this version?".format( owner, registry_name, version ) ): click.echo("Existing without pushing model version.") sys.exit(1) try: registry_config = V1ModelVersion( name=version, description=description, tags=tags, run=run_uid, ) if to_update: _version = polyaxon_client.model_registry_v1.update_model_version( owner, registry_name, version, registry_config, ) else: _version = polyaxon_client.model_registry_v1.create_model_version( owner, registry_name, registry_config, ) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create model version `{}`.".format(registry_name) ) sys.exit(1) Printer.print_success( "Model version `{}` was created successfully.".format(_version.name) ) click.echo( "You can view this model version on Polyaxon UI: {}".format( get_dashboard_url( subpath="{}/registry/{}/versions/{}".format( owner, registry_name, _version.name ) ) ) )
def service(ctx, yes, external, url): """Open the operation service in browser. N.B. The operation must have a run kind service, otherwise it will raise an error. You can open the service embedded in Polyaxon UI or using the real service URL, please use the `--external` flag. """ owner, project_name, run_uuid = get_project_run_or_local( ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True, ) client = RunClient(owner=owner, project=project_name, run_uuid=run_uuid) client.refresh_data() if client.run_data.kind != V1RunKind.SERVICE: Printer.print_warning( "Command expected an operation of " "kind `service` received kind: `{}`!".format(client.run_data.kind) ) sys.exit(1) Printer.print_header("Waiting for running condition ...") client.wait_for_condition( statuses={V1Statuses.RUNNING} | LifeCycle.DONE_VALUES, print_status=True ) client.refresh_data() if LifeCycle.is_done(client.run_data.status): Printer.print_header("The operations reached a done statuses.") latest_status = Printer.add_status_color( {"status": client.run_data.status}, status_key="status" ) click.echo("{}\n".format(latest_status["status"])) run_url = get_dashboard_url( subpath="{}/{}/runs/{}/service".format(owner, project_name, run_uuid) ) namespace = client.run_data.settings.namespace service_endpoint = SERVICES_V1 if client.run_data.meta_info.get("rewrite_path", False): service_endpoint = REWRITE_SERVICES_V1 external_run_url = get_dashboard_url( base=service_endpoint, subpath="{}/{}/{}/runs/{}/".format(namespace, owner, project_name, run_uuid), ) if url: Printer.print_header("The service will be available at: {}".format(run_url)) Printer.print_header( "You can also view it in an external link at: {}".format(external_run_url) ) sys.exit(0) if not yes: click.confirm( "Dashboard page will now open in your browser. Continue?", abort=True, default=True, ) if external: click.launch(external_run_url) sys.exit(0) click.launch(run_url)