コード例 #1
0
ファイル: auth.py プロジェクト: oldas1/floyd-cli
def login(token):
    """
    Log into Floyd via Auth0.
    """
    if not token:
        cli_info_url = "{}/settings/security".format(floyd.floyd_web_host)
        click.confirm(
            'Authentication token page will now open in your browser. Continue?',
            abort=True,
            default=True)

        webbrowser.open(cli_info_url)

    floyd_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:
        floyd_logger.info(
            "Empty token received. Make sure your shell is handling the token appropriately."
        )
        floyd_logger.info(
            "See docs for help: http://docs.floydhub.com/faqs/authentication/")
        return

    access_code = access_code.strip(" ")
    user = AuthClient().get_user(access_code)
    access_token = AccessToken(username=user.username, token=access_code)
    AuthConfigManager.set_access_token(access_token)
    floyd_logger.info("Login Successful as %s.", user.username)
コード例 #2
0
ファイル: auth.py プロジェクト: sanketsaurav/floyd-cli
def manual_login_success(token, username, password):
    if token:
        # Login using authentication token
        floyd_logger.info(
            "Please paste the authentication token from %s/settings/security.",
            floyd.floyd_web_host)
        access_token = click.prompt(
            'This is an invisible field. Paste token and press ENTER',
            type=str,
            hide_input=True)
        access_token = access_token.strip()

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

    elif username or password:
        access_token = get_access_code_from_password(username, password)
    else:
        return False

    user = AuthClient().get_user(access_token)
    AuthConfigManager.set_access_token(
        AccessToken(username=user.username, token=access_token))
    floyd_logger.info("Login Successful as %s", user.username)
    return True
コード例 #3
0
 def test_auth_config(self, sys_exit, expanduser):
     import base64
     from floyd.model.access_token import assert_token_not_expired, AccessToken
     expanduser.return_value = '/tmp/.floydconfig'
     mock_token = 'a.' + base64.b64encode('{"exp": 1}'.encode('ascii')).decode('ascii') + '.c'
     access_token = AccessToken('foo', mock_token)
     AuthConfigManager.set_access_token(access_token)
     assert AuthConfigManager.get_access_token().token == mock_token
コード例 #4
0
def login(token, username, password):
    """
    Log into Floyd via Auth0.
    """
    if username:
        # Use username / password login
        if not password:
            password = click.prompt('Please enter your password',
                                    type=str,
                                    hide_input=True)
            password = password.strip()
            if not password:
                floyd_logger.info(
                    'You entered an empty string. Please make sure you enter your password correctly.'
                )
                sys.exit(1)

        login_credentials = Credentials(username=username, password=password)
        access_code = AuthClient().login(login_credentials)
        if not access_code:
            floyd_logger.info("Failed to login")
            return

    else:
        # Fallback to the access token from the browser login
        if not token:
            cli_info_url = "{}/settings/security".format(floyd.floyd_web_host)
            click.confirm(
                'Authentication token page will now open in your browser. Continue?',
                abort=True,
                default=True)
            webbrowser.open(cli_info_url)

        floyd_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)

        access_code = access_code.strip()

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

        access_code = access_code.strip(" ")

    user = AuthClient().get_user(access_code)
    access_token = AccessToken(username=user.username, token=access_code)
    AuthConfigManager.set_access_token(access_token)
    floyd_logger.info("Login Successful as %s", user.username)
コード例 #5
0
def login(token, apikey, username, password):
    """
    Log into Floyd via Auth0.
    """
    if apikey:
        user = AuthClient().get_user(apikey, True)
        AuthConfigManager.set_apikey(username=user.username, apikey=apikey)
        floyd_logger.info("Login Successful as %s", user.username)
        return

    elif token:
        # Login using authentication token
        floyd_logger.info(
            "Please paste the authentication token from {}/settings/security.".format(floyd.floyd_web_host))
        access_code = click.prompt('This is an invisible field. Paste token and press ENTER', type=str, hide_input=True)
        access_code = access_code.strip()

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

        access_code = access_code.strip(" ")

    else:
        # Use username / password login
        floyd_logger.info("Login with your FloydHub username and password to run jobs.")

        if not username:
            username = click.prompt('Username', type=str, default=getpass.getuser())
            username = username.strip()
            if not username:
                floyd_logger.info('You entered an empty string. Please make sure you enter your username correctly.')
                sys.exit(1)

        if not password:
            password = click.prompt('Password', type=str, hide_input=True)
            password = password.strip()
            if not password:
                floyd_logger.info('You entered an empty string. Please make sure you enter your password correctly.')
                sys.exit(1)

        login_credentials = Credentials(username=username,
                                        password=password)
        access_code = AuthClient().login(login_credentials)
        if not access_code:
            floyd_logger.info("Failed to login")
            return

    user = AuthClient().get_user(access_code)
    access_token = AccessToken(username=user.username,
                               token=access_code)
    AuthConfigManager.set_access_token(access_token)
    floyd_logger.info("Login Successful as %s", user.username)
コード例 #6
0
ファイル: auth.py プロジェクト: pkucarey/floyd-cli
def login():
    """
    Log into Floyd via Auth0.
    """
    cli_info_url = "{}/cli".format(floyd.floyd_web_host)
    click.confirm('Access token page will now open in your browser. Continue?', abort=True, default=True)

    webbrowser.open(cli_info_url)
    access_code = click.prompt('Please paste the code here', type=str, hide_input=True)

    user = AuthClient().get_user(access_code)
    access_token = AccessToken(username=user.username,
                               token=access_code)
    AuthConfigManager.set_access_token(access_token)
    floyd_logger.info("Login Successful")
コード例 #7
0
ファイル: data.py プロジェクト: pkucarey/floyd-cli
def upload():
    """
    Upload data in the current dir to Floyd.
    """
    data_config = DataConfigManager.get_config()
    access_token = AuthConfigManager.get_access_token()
    version = data_config.version

    # Create data object
    data_name = "{}/{}:{}".format(access_token.username, data_config.name,
                                  version)
    data = DataRequest(name=data_name, description=version, version=version)
    data_id = DataClient().create(data)
    floyd_logger.debug("Created data with id : {}".format(data_id))
    floyd_logger.info("Upload finished")

    # Update expt config including predecessor
    data_config.increment_version()
    data_config.set_data_predecessor(data_id)
    DataConfigManager.set_config(data_config)

    # Print output
    table_output = [["DATA ID", "NAME", "VERSION"],
                    [data_id, data_name, version]]
    floyd_logger.info(tabulate(table_output, headers="firstrow"))
コード例 #8
0
ファイル: project.py プロジェクト: rmdort/floyd-cli
 def get_by_name(self, name):
     access_token = AuthConfigManager.get_access_token()
     try:
         response = self.request(
             'GET', '%s/%s/%s' % (self.url, access_token.username, name))
         return Project.from_dict(response.json())
     except NotFoundException:
         return None
コード例 #9
0
 def get_by_name(self, name, username=None):
     username = username or AuthConfigManager.get_access_token().username
     try:
         response = self.request('GET',
                                 '%s/%s/%s' % (self.url, username, name))
         return Dataset.from_dict(response.json())
     except NotFoundException:
         return None
コード例 #10
0
def upload(resume, tar_file, message):
    """
    Upload data in the current dir to Floyd.
    """
    data_config = DataConfigManager.get_config()

    if not upload_is_resumable(data_config) or not opt_to_resume(resume):
        abort_previous_upload(data_config)
        access_token = AuthConfigManager.get_access_token()
        initialize_new_upload(data_config, access_token, tar_file, message)

    complete_upload(data_config)
コード例 #11
0
 def get_all(self):
     try:
         access_token = AuthConfigManager.get_access_token()
         response = self.request("GET",
                                 self.url,
                                 params={
                                     "module_type": "data",
                                     "username": access_token.username
                                 })
         data_dict = response.json()
         return [Data.from_dict(data) for data in data_dict]
     except FloydException as e:
         floyd_logger.error("Error while retrieving data: %s", e.message)
         return []
コード例 #12
0
ファイル: auth.py プロジェクト: sanketsaurav/floyd-cli
def login(token, apikey, username, password):
    """
    Login to FloydHub.
    """
    if manual_login_success(token, username, password):
        return

    if not apikey:
        if has_browser():
            apikey = wait_for_apikey()
        else:
            floyd_logger.error(
                "No browser found, please login manually by creating login key at %s/settings/apikey.",
                floyd.floyd_web_host)
            sys.exit(1)

    if apikey:
        user = AuthClient().get_user(apikey, is_apikey=True)
        AuthConfigManager.set_apikey(username=user.username, apikey=apikey)
        floyd_logger.info("Login Successful as %s", user.username)
    else:
        floyd_logger.error(
            "Login failed, please see --help for other login options.")
コード例 #13
0
ファイル: project.py プロジェクト: sanketsaurav/floyd-cli
 def get_by_name(self, name, namespace=None):
     """
     name: can be either <namespace>/<project_name> or just <project_name>
     namespace: if specified, will skip name parsing, defaults to current user's username
     """
     if not namespace:
         namespace, name = get_namespace_from_name(name)
     if not namespace:
         namespace = AuthConfigManager.get_access_token().username
     try:
         response = self.request('GET',
                                 '%s/%s/%s' % (self.url, namespace, name))
         return Project.from_dict(response.json())
     except NotFoundException:
         return None
コード例 #14
0
 def __init__(self, skip_auth=False):
     self.base_url = "{}/api/v1".format(floyd.floyd_host)
     if skip_auth:
         self.auth_header = None
     else:
         self.auth_header = AuthConfigManager.get_auth_header()
コード例 #15
0
ファイル: base.py プロジェクト: oldas1/floyd-cli
 def __init__(self, skip_auth=False):
     self.base_url = "{}/api/v1".format(floyd.floyd_host)
     if not skip_auth:
         self.access_token = AuthConfigManager.get_access_token()
     else:
         self.access_token = None
コード例 #16
0
ファイル: run.py プロジェクト: rmdort/floyd-cli
def run(ctx, gpu, env, message, data, mode, open, tensorboard, command):
    """
    Run a command on Floyd. Floyd will upload contents of the
    current directory and run your command remotely.
    This command will generate a run id for reference.
    """
    experiment_config = ExperimentConfigManager.get_config()
    if not ProjectClient().exists(experiment_config.family_id):
        floyd_logger.error(
            'Invalid project id, please run '
            '"floyd init PROJECT_NAME" before scheduling a job.')
        return

    access_token = AuthConfigManager.get_access_token()
    experiment_name = "{}/{}".format(access_token.username,
                                     experiment_config.name)

    # Create module
    if len(data) > 5:
        floyd_logger.error("Cannot attach more than 5 datasets to an job")
        return

    # Get the data entity from the server to:
    # 1. Confirm that the data id or uri exists and has the right permissions
    # 2. If uri is used, get the id of the dataset
    data_ids = []
    for data_name_or_id in data:
        path = None
        if ':' in data_name_or_id:
            data_name_or_id, path = data_name_or_id.split(':')
        data_obj = DataClient().get(data_name_or_id)
        if not data_obj:
            floyd_logger.error(
                "Data not found for name or id: {}".format(data_name_or_id))
            return
        data_ids.append(
            "{}:{}".format(data_obj.id, path) if path else data_obj.id)

    default_name = 'input' if len(data_ids) <= 1 else None
    module_inputs = [{
        'name': get_data_name(data_str, default_name),
        'type': 'dir'
    } for data_str in data_ids]

    if gpu:
        arch = 'gpu'
        instance_type = GPU_INSTANCE_TYPE
    else:
        arch = 'cpu'
        instance_type = CPU_INSTANCE_TYPE

    env_map = EnvClient().get_all()
    envs = env_map.get(arch)
    if envs:
        if env not in envs:
            floyd_logger.error(
                "{} is not in the list of supported environments: {}".format(
                    env, ', '.join(envs.keys())))
            return
    else:
        floyd_logger.error("{} is not a supported architecture".format(arch))
        return

    command_str = ' '.join(command)
    module = Module(name=experiment_name,
                    description=message or '',
                    command=command_str,
                    mode=get_mode_parameter(mode),
                    enable_tensorboard=tensorboard,
                    family_id=experiment_config.family_id,
                    inputs=module_inputs,
                    env=env,
                    arch=arch)

    from floyd.exceptions import BadRequestException
    try:
        module_id = ModuleClient().create(module)
    except BadRequestException as e:
        if 'Project not found, ID' in e.message:
            floyd_logger.error(
                'ERROR: Please run "floyd init PROJECT_NAME" before scheduling a job.'
            )
        else:
            floyd_logger.error('ERROR: %s', e.message)
        sys.exit(1)
    floyd_logger.debug("Created module with id : {}".format(module_id))

    # Create experiment request
    # Get the actual command entered in the command line
    full_command = get_command_line(gpu, env, message, data, mode, open,
                                    tensorboard, command)
    experiment_request = ExperimentRequest(
        name=experiment_name,
        description=message,
        full_command=full_command,
        module_id=module_id,
        data_ids=data_ids,
        family_id=experiment_config.family_id,
        instance_type=instance_type)
    expt_cli = ExperimentClient()
    expt_info = expt_cli.create(experiment_request)
    floyd_logger.debug("Created job : {}".format(expt_info['id']))

    table_output = [["JOB NAME"], [expt_info['name']]]
    floyd_logger.info(tabulate(table_output, headers="firstrow"))
    floyd_logger.info("")

    if mode in ['jupyter', 'serve']:
        while True:
            # Wait for the experiment / task instances to become available
            try:
                experiment = expt_cli.get(expt_info['id'])
                if experiment.task_instances:
                    break
            except Exception:
                floyd_logger.debug("Job not available yet: {}".format(
                    expt_info['id']))

            floyd_logger.debug("Job not available yet: {}".format(
                expt_info['id']))
            sleep(3)
            continue

        # Print the path to jupyter notebook
        if mode == 'jupyter':
            jupyter_url = experiment.service_url
            print(
                "Setting up your instance and waiting for Jupyter notebook to become available ...",
                end='')
            if wait_for_url(jupyter_url,
                            sleep_duration_seconds=2,
                            iterations=900):
                floyd_logger.info(
                    "\nPath to jupyter notebook: {}".format(jupyter_url))
                if open:
                    webbrowser.open(jupyter_url)
            else:
                floyd_logger.info(
                    "\nPath to jupyter notebook: {}".format(jupyter_url))
                floyd_logger.info(
                    "Notebook is still loading. View logs to track progress")
                floyd_logger.info("   floyd logs {}".format(expt_info['name']))

        # Print the path to serving endpoint
        if mode == 'serve':
            floyd_logger.info("Path to service endpoint: {}".format(
                experiment.service_url))

        if experiment.timeout_seconds < 4 * 60 * 60:
            floyd_logger.info(
                "\nYour job timeout is currently set to {} seconds".format(
                    experiment.timeout_seconds))
            floyd_logger.info(
                "This is because you are in a trial account. Paid users will have longer timeouts. "
                "See https://www.floydhub.com/pricing for details")

    else:
        floyd_logger.info("To view logs enter:")
        floyd_logger.info("   floyd logs {}".format(expt_info['name']))
コード例 #17
0
ファイル: run.py プロジェクト: longhuei/floyd-cli
def run(ctx, cpu, gpu, env, message, data, mode, open_notebook, follow,
        tensorboard, gpup, cpup, gpu2, cpu2, max_runtime, task, command):
    """
    Run a command on Floyd. Floyd will upload contents of the
    current directory and run your command remotely.
    This command will generate a run id for reference.
    """
    # cli_default is used for any option that has default value
    cli_default = {'description': '', 'command': ''}
    # Error early if more than one --env is passed.  Then get the first/only
    # --env out of the list so all other operations work normally (they don't
    # expect an iterable). For details on this approach, see the comment above
    # the --env click option
    if not env:
        cli_default['env'] = DEFAULT_ENV
        env = None
    elif len(env) > 1:
        floyd_logger.error(
            "You passed more than one environment: {}. Please specify a single environment."
            .format(env))
        sys.exit(1)
    else:
        env = env[0]

    if not mode:
        cli_default['mode'] = 'command'

    experiment_config = ExperimentConfigManager.get_config()
    access_token = AuthConfigManager.get_access_token()
    namespace = experiment_config.namespace or access_token.username

    if not ProjectClient().exists(experiment_config.name, namespace=namespace):
        floyd_logger.error(
            'Invalid project id, please run '
            '"floyd init PROJECT_NAME" before scheduling a job.')
        sys.exit(1)

    experiment_name = "{}/{}".format(namespace, experiment_config.name)

    success, data_ids = process_data_ids(data)
    if not success:
        sys.exit(2)

    # Create module
    default_name = 'input' if len(data_ids) <= 1 else None
    module_inputs = [{
        'name': get_data_name(data_str, default_name),
        'type': 'dir'
    } for data_str in data_ids]

    instance_type = None
    if gpu2:
        instance_type = G2_INSTANCE_TYPE
    elif cpu2:
        instance_type = C2_INSTANCE_TYPE
    elif gpup:
        instance_type = G1P_INSTANCE_TYPE
    elif cpup:
        instance_type = C1P_INSTANCE_TYPE
    elif gpu:
        instance_type = G1_INSTANCE_TYPE
    elif cpu:
        instance_type = C1_INSTANCE_TYPE

    if not instance_type:
        cli_default['instance_type'] = C1_INSTANCE_TYPE

    yaml_config = read_yaml_config()
    arch = INSTANCE_ARCH_MAP[resolve_final_instance_type(
        instance_type, yaml_config, task, cli_default)]
    if not validate_env(env or cli_default['env'], arch):
        sys.exit(3)

    command_str = ' '.join(command)
    if command_str and mode in ('jupyter', 'serve'):
        floyd_logger.error(
            'Command argument "%s" cannot be used with mode: %s.\nSee http://docs.floydhub.com/guides/run_a_job/#mode for more information about run modes.',
            command_str, mode)  # noqa
        sys.exit(3)
    if command_str == '':
        # set to none so it won't override floyd config
        command_str = None

    module = Module(name=experiment_name,
                    description=message or '',
                    command=command_str,
                    mode=mode,
                    enable_tensorboard=tensorboard,
                    family_id=experiment_config.family_id,
                    inputs=module_inputs,
                    env=env,
                    instance_type=instance_type,
                    yaml_config=yaml_config,
                    task=task)

    try:
        module_id = ModuleClient().create(module, cli_default)
    except BadRequestException as e:
        if 'Project not found, ID' in e.message:
            floyd_logger.error(
                'ERROR: Please run "floyd init PROJECT_NAME" before scheduling a job.'
            )
        else:
            floyd_logger.error('ERROR: %s', e.message)
        sys.exit(4)
    floyd_logger.debug("Created module with id : %s", module_id)

    # Create experiment request
    # Get the actual command entered in the command line
    if max_runtime:
        max_runtime = int(max_runtime)
    full_command = get_command_line(instance_type, env, message, data, mode,
                                    open_notebook, tensorboard, command_str)
    experiment_request = ExperimentRequest(
        name=experiment_name,
        description=message,
        full_command=full_command,
        module_id=module_id,
        max_runtime=max_runtime,
        env=env,
        data_ids=data_ids,
        family_id=experiment_config.family_id,
        instance_type=instance_type,
        yaml_config=yaml_config,
        task=task)
    expt_client = ExperimentClient()
    expt_info = expt_client.create(experiment_request, cli_default)
    floyd_logger.debug("Created job : %s", expt_info['id'])

    job_name = expt_info['name']
    if not follow:
        show_new_job_info(expt_client, job_name, expt_info, mode,
                          open_notebook)
    else:
        # If the user specified --follow, we assume they're only interested in
        # log output and not in anything that would be displayed by
        # show_new_job_info.
        floyd_logger.info("Opening logs ...")
        instance_log_id = instance_log_id = get_log_id(job_name)
        follow_logs(instance_log_id)
コード例 #18
0
ファイル: run.py プロジェクト: IntuitionMachine/floyd-cli
def run(ctx, gpu, env, message, data, mode, open_notebook, tensorboard, gpup,
        cpup, gpu2, cpu2, command):
    """
    Run a command on Floyd. Floyd will upload contents of the
    current directory and run your command remotely.
    This command will generate a run id for reference.
    """
    # Error early if more than one --env is passed.  Then get the first/only
    # --env out of the list so all other operations work normally (they don't
    # expect an iterable). For details on this approach, see the comment above
    # the --env click option
    if len(env) > 1:
        floyd_logger.error(
            "You passed more than one environment: {}. Please specify a single environment."
            .format(env))
        sys.exit(1)
    env = env[0]
    experiment_config = ExperimentConfigManager.get_config()
    access_token = AuthConfigManager.get_access_token()
    namespace = experiment_config.namespace or access_token.username

    if not ProjectClient().exists(experiment_config.name, namespace=namespace):
        floyd_logger.error(
            'Invalid project id, please run '
            '"floyd init PROJECT_NAME" before scheduling a job.')
        sys.exit(1)

    experiment_name = "{}/{}".format(namespace, experiment_config.name)

    success, data_ids = process_data_ids(data)
    if not success:
        sys.exit(2)

    # Create module
    default_name = 'input' if len(data_ids) <= 1 else None
    module_inputs = [{
        'name': get_data_name(data_str, default_name),
        'type': 'dir'
    } for data_str in data_ids]

    if gpu2:
        instance_type = G2_INSTANCE_TYPE
    elif cpu2:
        instance_type = C2_INSTANCE_TYPE
    elif gpup:
        instance_type = G1P_INSTANCE_TYPE
    elif cpup:
        instance_type = C1P_INSTANCE_TYPE
    elif gpu:
        instance_type = G1_INSTANCE_TYPE
    else:
        instance_type = C1_INSTANCE_TYPE

    if not validate_env(env, instance_type):
        sys.exit(3)

    command_str = ' '.join(command)
    if command_str and mode in ('jupyter', 'serve'):
        floyd_logger.error(
            'Command argument "%s" cannot be used with mode: %s.\nSee http://docs.floydhub.com/guides/run_a_job/#mode for more information about run modes.',
            command_str, mode)  # noqa
        sys.exit(3)

    module = Module(name=experiment_name,
                    description=message or '',
                    command=command_str,
                    mode=get_mode_parameter(mode),
                    enable_tensorboard=tensorboard,
                    family_id=experiment_config.family_id,
                    inputs=module_inputs,
                    env=env,
                    arch=INSTANCE_ARCH_MAP[instance_type])

    try:
        module_id = ModuleClient().create(module)
    except BadRequestException as e:
        if 'Project not found, ID' in e.message:
            floyd_logger.error(
                'ERROR: Please run "floyd init PROJECT_NAME" before scheduling a job.'
            )
        else:
            floyd_logger.error('ERROR: %s', e.message)
        sys.exit(4)
    floyd_logger.debug("Created module with id : %s", module_id)

    # Create experiment request
    # Get the actual command entered in the command line
    full_command = get_command_line(instance_type, env, message, data, mode,
                                    open_notebook, tensorboard, command_str)
    experiment_request = ExperimentRequest(
        name=experiment_name,
        description=message,
        full_command=full_command,
        module_id=module_id,
        env=env,
        data_ids=data_ids,
        family_id=experiment_config.family_id,
        instance_type=instance_type)
    expt_client = ExperimentClient()
    expt_info = expt_client.create(experiment_request)
    floyd_logger.debug("Created job : %s", expt_info['id'])

    job_name = expt_info['name']
    show_new_job_info(expt_client, job_name, expt_info, mode, open_notebook)
コード例 #19
0
def run(ctx, gpu, env, message, data, mode, open, tensorboard, gpup, cpup,
        command):
    """
    Run a command on Floyd. Floyd will upload contents of the
    current directory and run your command remotely.
    This command will generate a run id for reference.
    """
    experiment_config = ExperimentConfigManager.get_config()
    if not ProjectClient().exists(experiment_config.family_id):
        floyd_logger.error(
            'Invalid project id, please run '
            '"floyd init PROJECT_NAME" before scheduling a job.')
        sys.exit(1)

    access_token = AuthConfigManager.get_access_token()
    experiment_name = "{}/{}".format(access_token.username,
                                     experiment_config.name)

    success, data_ids = process_data_ids(data)
    if not success:
        sys.exit(2)

    # Create module
    default_name = 'input' if len(data_ids) <= 1 else None
    module_inputs = [{
        'name': get_data_name(data_str, default_name),
        'type': 'dir'
    } for data_str in data_ids]

    if gpup:
        instance_type = G1P_INSTANCE_TYPE
    elif cpup:
        instance_type = C1P_INSTANCE_TYPE
    elif gpu:
        instance_type = G1_INSTANCE_TYPE
    else:
        instance_type = C1_INSTANCE_TYPE

    if not validate_env(env, instance_type):
        sys.exit(3)

    command_str = ' '.join(command)
    if command_str and mode in ('jupyter', 'serve'):
        floyd_logger.error(
            'Command argument "%s" cannot be used with mode: %s.\nSee http://docs.floydhub.com/guides/run_a_job/#mode for more information about run modes.',
            command_str, mode)
        sys.exit(3)

    module = Module(name=experiment_name,
                    description=message or '',
                    command=command_str,
                    mode=get_mode_parameter(mode),
                    enable_tensorboard=tensorboard,
                    family_id=experiment_config.family_id,
                    inputs=module_inputs,
                    env=env,
                    arch=INSTANCE_ARCH_MAP[instance_type])

    try:
        module_id = ModuleClient().create(module)
    except BadRequestException as e:
        if 'Project not found, ID' in e.message:
            floyd_logger.error(
                'ERROR: Please run "floyd init PROJECT_NAME" before scheduling a job.'
            )
        else:
            floyd_logger.error('ERROR: %s', e.message)
        sys.exit(4)
    floyd_logger.debug("Created module with id : %s", module_id)

    # Create experiment request
    # Get the actual command entered in the command line
    full_command = get_command_line(instance_type, env, message, data, mode,
                                    open, tensorboard, command_str)
    experiment_request = ExperimentRequest(
        name=experiment_name,
        description=message,
        full_command=full_command,
        module_id=module_id,
        data_ids=data_ids,
        family_id=experiment_config.family_id,
        instance_type=instance_type)
    expt_client = ExperimentClient()
    expt_info = expt_client.create(experiment_request)
    floyd_logger.debug("Created job : %s", expt_info['id'])

    job_name = normalize_job_name(expt_info['name'])
    floyd_logger.info("")
    table_output = [["JOB NAME"], [job_name]]
    floyd_logger.info(tabulate(table_output, headers="firstrow"))
    floyd_logger.info("")
    show_new_job_info(expt_client, job_name, expt_info, mode)
コード例 #20
0
ファイル: auth.py プロジェクト: pkucarey/floyd-cli
def logout():
    """
    Logout of Floyd.
    """
    AuthConfigManager.purge_access_token()
コード例 #21
0
def current_username():
    return AuthConfigManager.get_access_token().username
コード例 #22
0
ファイル: base.py プロジェクト: wheremiah/floyd-cli
 def __init__(self):
     self.base_url = "{}/api/v1".format(floyd.floyd_host)
     self.access_token = AuthConfigManager.get_access_token()
コード例 #23
0
def run(ctx, gpu, env, data, mode, command):
    """
    Run a command on Floyd. Floyd will upload contents of the
    current directory and run your command remotely.
    This command will generate a run id for reference.
    """
    command_str = ' '.join(command)
    experiment_config = ExperimentConfigManager.get_config()
    access_token = AuthConfigManager.get_access_token()
    version = experiment_config.version
    experiment_name = "{}/{}:{}".format(access_token.username,
                                        experiment_config.name,
                                        version)

    # Create module
    module = Module(name=experiment_name,
                    description=version,
                    command=command_str,
                    mode=get_mode_parameter(mode),
                    family_id=experiment_config.family_id,
                    default_container=get_docker_image(env, gpu),
                    version=version)
    module_id = ModuleClient().create(module)
    floyd_logger.debug("Created module with id : {}".format(module_id))

    # Create experiment request
    instance_type = GPU_INSTANCE_TYPE if gpu else CPU_INSTANCE_TYPE
    experiment_request = ExperimentRequest(name=experiment_name,
                                           description=version,
                                           module_id=module_id,
                                           data_id=data,
                                           predecessor=experiment_config.experiment_predecessor,
                                           family_id=experiment_config.family_id,
                                           version=version,
                                           instance_type=instance_type)
    experiment_id = ExperimentClient().create(experiment_request)
    floyd_logger.debug("Created experiment : {}".format(experiment_id))

    # Update expt config including predecessor
    experiment_config.increment_version()
    experiment_config.set_module_predecessor(module_id)
    experiment_config.set_experiment_predecessor(experiment_id)
    ExperimentConfigManager.set_config(experiment_config)

    table_output = [["RUN ID", "NAME", "VERSION"],
                    [experiment_id, experiment_name, version]]
    floyd_logger.info(tabulate(table_output, headers="firstrow"))
    floyd_logger.info("")

    if mode != 'default':
        while True:
            # Wait for the experiment to become available
            try:
                experiment = ExperimentClient().get(experiment_id)
                break
            except Exception:
                floyd_logger.debug("Experiment not available yet: {}".format(experiment_id))
                sleep(1)
                continue

        # Print the path to jupyter notebook
        if mode == 'jupyter':
            jupyter_url = get_task_url(get_module_task_instance_id(experiment.task_instances))
            floyd_logger.info("Waiting for Jupyter notebook to become available ...")
            if wait_for_url(jupyter_url):
                floyd_logger.info("\nPath to jupyter notebook: {}".format(jupyter_url))
            else:
                floyd_logger.info("Problem starting the notebook. View logs for more information")

        # Print the path to serving endpoint
        if mode == 'serve':
            floyd_logger.info("Path to service endpoint: {}".format(
                get_task_url(get_module_task_instance_id(experiment.task_instances))))

    floyd_logger.info("""
To view logs enter:
    floyd logs {}
        """.format(experiment_id))