예제 #1
0
def login(token):
    """Log into Polyaxon via Auth0."""
    if not token:
        cli_info_url = "{}/settings/security".format(
            GlobalConfigManager.get_value('host'))
        click.confirm(
            'Authentication token page will now open in your browser. Continue?',
            abort=True,
            default=True)

        webbrowser.open(cli_info_url)

    logger.info("Please copy and paste the authentication token.")
    access_code = click.prompt(
        'This is an invisible field. Paste token and press ENTER',
        type=str,
        hide_input=True)

    if not access_code:
        logger.info(
            "Empty token received. "
            "Make sure your shell is handling the token appropriately.")
        logger.info(
            "See docs for help: http://docs.polyaxon.com/faqs/authentication/")
        return

    access_code = access_code.strip(" ")
    user = AuthClient().get_user(access_code)
    access_token = AccessTokenConfig(username=user.username, token=access_code)
    AuthConfigManager.set_config(access_token)
    logger.info("Login Successful")
예제 #2
0
 def get_datasets(self):
     try:
         response = self.get(self._get_url())
         datasets_dict = response.json()
         return [
             DatasetConfig.from_dict(dataset)
             for dataset in datasets_dict.get("datasets", [])
         ]
     except PolyaxonException as e:
         if isinstance(e, AuthenticationError):
             # exit now since there is nothing we can do without login
             sys.exit(1)
         logger.info("Error while retrieving datasets: {}".format(
             e.message))
         return []
예제 #3
0
 def get_projects(self):
     try:
         response = self.get(self._get_url())
         projects_dict = response.json()
         return [
             ProjectConfig.from_dict(project)
             for project in projects_dict.get("projects", [])
         ]
     except PolyaxonException as e:
         logger.info("Error while retrieving projects: {}".format(
             e.message))
         if isinstance(e, AuthenticationError):
             # exit now since there is nothing we can do without login
             sys.exit(1)
         return []
예제 #4
0
def check(file, version, cluster, run_type):
    """Command for checking a polyaxonfile."""
    plx_file = PolyaxonFile(file)
    logger.info("Polyaxonfile valid")

    if version:
        logger.info('The version is: {}'.format(plx_file.version))

    elif cluster:
        cluster_def, is_distributed = plx_file.cluster_def
        logger.info('The cluster definition is: {}'.format(cluster_def))

    elif run_type:
        logger.info('The run_type is: {}'.format(plx_file.run_type))

    else:
        logger.info('Validated file:\n{}'.format(plx_file.parsed_data))
예제 #5
0
def run(file):
    """Command for running a polyaxonfile."""
    plx_file = PolyaxonFile(file)
    if plx_file.run_type == RunTypes.LOCAL:
        # check that polyaxon is installed
        version = get_version(PROJECT_NAME)
        if version is None:
            click.echo("""In order to run locally, polyaxon must be installed.""")
            if click.confirm("Do you want to install polyaxon now?"):
                from polyaxon_cli.cli.version import pip_upgrade
                pip_upgrade(PROJECT_NAME)
            else:
                click.echo("""Your can manually run:
    pip install -U polyaxon
to install to the latest version of polyaxon)""")
                sys.exit(0)

        logger.info('Running polyaxonfile locally')
        from polyaxon.polyaxonfile.local_runner import run
        run(file)
예제 #6
0
 def create_dataset(self, data):
     """
     Create a temporary directory for the tar file that will be removed at
     the end of the operation.
     """
     try:
         logger.info("Making create request to server...")
         post_body = data.to_dict()
         post_body["resumable"] = True
         response = self.post(self._get_url(), json=post_body)
         return response.json()
     except BadRequestError as e:
         if 'Dataset not found, ID' in e.message:
             logger.error(
                 "Data create: ERROR! "
                 "Please run 'polyaxon data init DATASET_NAME' before upload."
             )
         else:
             logger.error('Data create: ERROR! %s', e.message)
         return None
     except PolyaxonException as e:
         logger.error("Data create: ERROR! %s", e.message)
         return None
예제 #7
0
    def upload(self):
        try:
            upload_files, total_file_size = get_files_in_current_directory(
                file_type='code')
        except OSError:
            sys.exit("Directory contains too many files to upload. "
                     "If you have data files in the current directory, "
                     "please upload them separately using `polyaxon data` "
                     "command and remove them from here.\n"
                     "See http://docs.polyaxon.com/faqs/job/ "
                     "for more details on how to fix this.")

        logger.info("Creating project run. Total upload size: %s",
                    total_file_size)
        logger.debug("Creating module. Uploading: %s files", len(upload_files))
        logger.info("Syncing code ...")

        # Add request data
        multipart_encoder = MultipartEncoder(fields=upload_files)

        # Attach progress bar
        progress_callback, bar = create_progress_callback(multipart_encoder)
        multipart_encoder_monitor = MultipartEncoderMonitor(
            multipart_encoder, progress_callback)

        try:
            response = self.request(
                "POST",
                self._get_url(),
                data=multipart_encoder_monitor,
                headers={"Content-Type": multipart_encoder.content_type},
                timeout=3600)
        finally:
            # always make sure we clear the console
            bar.done()
        return response.json().get("id")
예제 #8
0
 def download_tar(self, url, untar=True, delete_after_untar=False):
     """
     Download and optionally untar the tar file from the given url
     """
     try:
         logger.info(
             "Downloading the tar file to the current directory ...")
         filename = self.download(url=url, filename='output.tar')
         if filename and untar:
             logger.info("Untarring the contents of the file ...")
             tar = tarfile.open(filename)
             tar.extractall()
             tar.close()
         if delete_after_untar:
             logger.info("Cleaning up the tar file ...")
             os.remove(filename)
         return filename
     except PolyaxonException as e:
         logger.info("Download URL ERROR! {}".format(e.message))
         return False
예제 #9
0
def logout():
    """Logout of Polyaxon."""
    AuthConfigManager.purge()
    logger.info("You are logged out")
예제 #10
0
def version(all):
    """Prints the current version of the CLI."""
    project_name = PROJECT_NAME if all else PROJECT_CLI_NAME
    version = get_version(project_name)
    logger.info(version)