Exemplo n.º 1
0
def list_workloads_common(ctx, **kwargs):
    result = get_rover_cluster_helper(ctx, kwargs['cluster_id'])
    workload_data = result.data.cluster_workloads
    if workload_data:
        for idx, each_workload in enumerate(workload_data, 1):
            if each_workload.workload_type.lower() == ROVER_WORKLOAD_TYPE_IMAGE:
                export_status = export_compute_image_status_helper(ctx, each_workload.work_request_id)
                workload_dict = json.loads(str(each_workload))
                export_status_dict = dict()
                export_status_dict["export_compute_image_status"] = export_status
                workload_dict.update(export_status_dict)
                click.echo("{}. {}".format(idx, formatted_flat_dict(workload_dict)))
            else:
                click.echo("{}. {}".format(idx, formatted_flat_dict(each_workload)))
    else:

        raise click.UsageError("Cluster has no associated workloads.")
Exemplo n.º 2
0
def update_policy(ctx, from_json, policy_id, description, statements, version_date, if_match, force, defined_tags, freeform_tags):
    cli_util.load_context_obj_values_from_defaults(ctx)

    client = cli_util.build_client('identity', ctx)
    if statements or version_date:
        if statements is None or version_date is None:
            sys.exit('If updating either statements or version date, both parameters must be specified.')

        if not force:
            result = client.get_policy(policy_id=policy_id)
            etag = result.headers['etag']

            if (if_match and etag != if_match):
                sys.exit('If-match {!r} does not match the current etag, {!r}.'.format(if_match, result.headers['etag']))

            if_match = etag

            existing_statements = cli_util.formatted_flat_dict(result.data.statements)
            if not click.confirm("WARNING: The value passed to statements will overwrite all existing statements for this policy. The existing statements are:\n" + existing_statements + "\nAre you sure you want to continue?"):
                ctx.abort()

    if not force:
        if defined_tags or freeform_tags:
            if not click.confirm("WARNING: Updates to defined-tags and freeform-tags will replace any existing values. Are you sure you want to continue?"):
                ctx.abort()

    args = {}

    if if_match is not None:
        args['if_match'] = if_match

    details = {}

    if description:
        details['description'] = description
    if statements:
        details['statements'] = cli_util.parse_json_parameter("statements", statements)
    if version_date:
        if len(version_date) == 0:
            version_date = None
        details['versionDate'] = version_date
    if defined_tags is not None:
        details['definedTags'] = cli_util.parse_json_parameter("defined_tags", defined_tags)
    if freeform_tags is not None:
        details['freeformTags'] = cli_util.parse_json_parameter("freeform_tags", freeform_tags)

    result = client.update_policy(policy_id=policy_id, update_policy_details=details, ** args)
    cli_util.render_response(result, ctx)
Exemplo n.º 3
0
def delete_workload_common(ctx, **kwargs):

    result = get_rover_cluster_helper(ctx, kwargs['cluster_id'])
    workload_index = 0
    workload_data = result.data.cluster_workloads
    if workload_data:
        if len(workload_data) > 1:
            for idx, each_workload in enumerate(workload_data, 1):
                click.echo("{}. {}".format(idx, formatted_flat_dict(each_workload)))
            workload_index = prompt_for_workload_delete()
            if workload_index > len(workload_data) or workload_index < 1:
                raise click.UsageError("Please try again with valid selection")
        if not kwargs['force']:
            confirm_prompt = "Are you sure you want to delete following workload ? " + formatted_flat_dict(
                workload_data[workload_index - 1])
            if not click.confirm(click.style(confirm_prompt, fg="yellow")):
                raise click.UsageError("Aborting workload deletion from Rover Cluster")
        workload_data.pop(workload_index - 1)
    else:
        raise click.UsageError("Cluster has no associated workloads.")
    kwargs_request = {'rover_cluster_id': kwargs['cluster_id'],
                      'cluster_workloads': workload_data, 'force': kwargs['force']}
    ctx.invoke(rovercluster_cli.update_rover_cluster, **kwargs_request)
Exemplo n.º 4
0
def add_workload_common(ctx, **kwargs):

    workload_data = image_id = workload_id = destination_uri = None
    result = get_rover_cluster_helper(ctx, kwargs['cluster_id'])

    if kwargs['type'].lower() == "bucket":
        result_bucket = validate_bucket(ctx, **kwargs)

        workload_id = result_bucket.data.name
        workload_data = prepare_bucket_workload_data(result_bucket, **kwargs)

    elif kwargs['type'].lower() == "image":
        compute_image_obj = validate_get_image(ctx, **kwargs)
        workload_id = image_id = kwargs['image_id']
        workload_data = prepare_image_workload_data(compute_image_obj, image_id)
        destination_uri = result.data.image_export_par + workload_data[0]['name'] + "_" + image_id + ".oci"
    confirm_prompt = "Would you like to submit the following workload information ? " + formatted_flat_dict(workload_data)
    if result.data.cluster_workloads and len(result.data.cluster_workloads) > 0 and any(existing_workload.id == workload_id for existing_workload in result.data.cluster_workloads):
        raise click.UsageError("Workload with {} is already attached".format(workload_id))

    if not kwargs['force'] and not click.confirm(click.style(confirm_prompt, fg="yellow")):
        click.echo("Aborting workload selection for Rover Cluster")
        ctx.abort()

    if kwargs['type'].lower() == "image":
        export_return_response = export_compute_image_helper(ctx, image_id, destination_uri)
        workload_data[0]["workRequestId"] = export_return_response.headers["opc-work-request-id"]
    if result.data.cluster_workloads:
        workload_data.extend(result.data.cluster_workloads)
    kwargs_request = {'rover_cluster_id': kwargs['cluster_id'],
                      'cluster_workloads': workload_data, 'force': kwargs['force']}
    ctx.invoke(rovercluster_cli.update_rover_cluster, **kwargs_request)