示例#1
0
def get_configuration(ctx, from_json, compartment_id):

    kwargs = {}
    client = cli_util.build_client('audit', 'audit', ctx)
    result = client.get_configuration(compartment_id=compartment_id, **kwargs)
    cli_util.render_response(result, ctx)
示例#2
0
def nfs_dataset_reopen(ctx, from_json, name, appliance_profile):
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)
    click.echo("Re-opening the dataset {}".format(name))
    nfs_dataset_info = nfs_dataset_client.reopen_nfs_dataset(name)
    cli_util.render_response(nfs_dataset_info, ctx)
示例#3
0
def nfs_dataset_list(ctx, from_json, appliance_profile):
    click.echo("Listing NFS datasets")
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)
    nfs_datasets = nfs_dataset_client.list_nfs_datasets()
    cli_util.render_response(nfs_datasets, ctx)
示例#4
0
def delete_rule(ctx, from_json, wait_for_state, max_wait_seconds,
                wait_interval_seconds, rule_id, if_match):

    if isinstance(rule_id, six.string_types) and len(rule_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --rule-id cannot be whitespace or empty string')

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])
    client = cli_util.build_client('events', ctx)
    result = client.delete_rule(rule_id=rule_id, **kwargs)
    if wait_for_state:
        if hasattr(client, 'get_rule') and callable(getattr(
                client, 'get_rule')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                oci.wait_until(client,
                               client.get_rule(rule_id),
                               'lifecycle_state',
                               wait_for_state,
                               succeed_on_not_found=True,
                               **wait_period_kwargs)
            except oci.exceptions.ServiceError as e:
                # We make an initial service call so we can pass the result to oci.wait_until(), however if we are waiting on the
                # outcome of a delete operation it is possible that the resource is already gone and so the initial service call
                # will result in an exception that reflects a HTTP 404. In this case, we can exit with success (rather than raising
                # the exception) since this would have been the behaviour in the waiter anyway (as for delete we provide the argument
                # succeed_on_not_found=True to the waiter).
                #
                # Any non-404 should still result in the exception being thrown.
                if e.status == 404:
                    pass
                else:
                    raise
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Please retrieve the resource to find its current state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#5
0
def nfs_dataset_deactivate(ctx, from_json, name, appliance_profile):
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)
    click.echo("Deactivating dataset {}".format(name))
    nfs_dataset_info = nfs_dataset_client.deactivate_nfs_dataset(name)
    cli_util.render_response(nfs_dataset_info, ctx)
示例#6
0
def create_compartment(ctx, from_json, wait_for_state, max_wait_seconds,
                       wait_interval_seconds, compartment_id, name,
                       description, freeform_tags, defined_tags):

    kwargs = {}

    _details = {}
    _details['compartmentId'] = compartment_id
    _details['name'] = name
    _details['description'] = description

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('identity', 'identity', ctx)
    result = client.create_compartment(create_compartment_details=_details,
                                       **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_compartment') and callable(
                getattr(client, 'get_compartment')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                # There is a delay to get_compartment after create_compartment. Please see DEX-9701
                time.sleep(10)
                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(client,
                                        client.get_compartment(result.data.id),
                                        'lifecycle_state', wait_for_state,
                                        **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#7
0
def update_policy_config(ctx, from_json, force, wait_for_state, max_wait_seconds, wait_interval_seconds, waas_policy_id, certificate_id, is_https_enabled, is_https_forced, tls_protocols, is_origin_compression_enabled, is_behind_cdn, client_address_header, is_cache_control_respected, is_response_buffering_enabled, cipher_group, if_match):
    if isinstance(waas_policy_id, six.string_types) and len(waas_policy_id.strip()) == 0:
        raise click.UsageError('Parameter --waas-policy-id cannot be whitespace or empty string')
    if not force:
        if tls_protocols:
            if not click.confirm("WARNING: Updates to tls-protocols will replace any existing values. Are you sure you want to continue?"):
                ctx.abort()

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id'])

    details = {}

    if certificate_id is not None:
        details['certificateId'] = certificate_id

    if is_https_enabled is not None:
        details['isHttpsEnabled'] = is_https_enabled

    if is_https_forced is not None:
        details['isHttpsForced'] = is_https_forced

    if tls_protocols is not None and len(tls_protocols) > 0:
        print(tls_protocols)
        details['tlsProtocols'] = tls_protocols

    if is_origin_compression_enabled is not None:
        details['isOriginCompressionEnabled'] = is_origin_compression_enabled

    if is_behind_cdn is not None:
        details['isBehindCdn'] = is_behind_cdn

    if client_address_header is not None:
        details['clientAddressHeader'] = client_address_header

    if is_cache_control_respected is not None:
        details['isCacheControlRespected'] = is_cache_control_respected

    if is_response_buffering_enabled is not None:
        details['isResponseBufferingEnabled'] = is_response_buffering_enabled

    if cipher_group is not None:
        details['cipherGroup'] = cipher_group

    client = cli_util.build_client('waas', ctx)
    result = client.update_policy_config(
        waas_policy_id=waas_policy_id,
        update_policy_config_details=details,
        **kwargs
    )
    if wait_for_state:
        if hasattr(client, 'get_work_request') and callable(getattr(client, 'get_work_request')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs['max_interval_seconds'] = wait_interval_seconds

                click.echo('Action completed. Waiting until the work request has entered state: {}'.format(wait_for_state), file=sys.stderr)
                result = oci.wait_until(client, client.get_work_request(result.headers['opc-work-request-id']), 'status', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo('Failed to wait until the work request entered the specified state. Outputting last known resource state', file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo('Encountered error while waiting for work request to enter the specified state. Outputting last known resource state', file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo('Unable to wait for the work request to enter the specified state', file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#8
0
def create_dashboard_create_v1_dashboard_details(
        ctx, from_json, wait_for_state, max_wait_seconds,
        wait_interval_seconds, dashboard_group_id, widgets, display_name,
        description, freeform_tags, defined_tags, config, opc_cross_region):

    kwargs = {}
    if opc_cross_region is not None:
        kwargs['opc_cross_region'] = opc_cross_region
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    _details = {}
    _details['dashboardGroupId'] = dashboard_group_id
    _details['widgets'] = cli_util.parse_json_parameter("widgets", widgets)

    if display_name is not None:
        _details['displayName'] = display_name

    if description is not None:
        _details['description'] = description

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    if config is not None:
        _details['config'] = cli_util.parse_json_parameter("config", config)

    _details['schemaVersion'] = 'V1'

    client = cli_util.build_client('dashboard_service', 'dashboard', ctx)
    result = client.create_dashboard(create_dashboard_details=_details,
                                     **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_dashboard') and callable(
                getattr(client, 'get_dashboard')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(client,
                                        client.get_dashboard(result.data.id),
                                        'lifecycle_state', wait_for_state,
                                        **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#9
0
def create_transfer_package(ctx, from_json, wait_for_state, max_wait_seconds,
                            wait_interval_seconds, id,
                            original_package_delivery_tracking_number,
                            return_package_delivery_tracking_number,
                            package_delivery_vendor):

    if isinstance(id, six.string_types) and len(id.strip()) == 0:
        raise click.UsageError(
            'Parameter --id cannot be whitespace or empty string')

    kwargs = {}

    _details = {}

    if original_package_delivery_tracking_number is not None:
        _details[
            'originalPackageDeliveryTrackingNumber'] = original_package_delivery_tracking_number

    if return_package_delivery_tracking_number is not None:
        _details[
            'returnPackageDeliveryTrackingNumber'] = return_package_delivery_tracking_number

    if package_delivery_vendor is not None:
        _details['packageDeliveryVendor'] = package_delivery_vendor

    client = cli_util.build_client('dts', 'transfer_package', ctx)
    result = client.create_transfer_package(
        id=id, create_transfer_package_details=_details, **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_transfer_package') and callable(
                getattr(client, 'get_transfer_package')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client, client.get_transfer_package(result.data.id),
                    'lifecycle_state', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#10
0
def create_stack_extended(ctx, from_json, wait_for_state, max_wait_seconds,
                          wait_interval_seconds, compartment_id, config_source,
                          display_name, description, variables,
                          terraform_version, freeform_tags, defined_tags,
                          working_directory, **kwargs):

    config_source = os.path.expandvars(os.path.expanduser(config_source))
    if not os.path.exists(config_source):
        click.echo('Config source does not exist', file=sys.stderr)
        ctx.abort()

    if not (config_source.endswith(".zip") and os.path.isfile(config_source)
            and zipfile.is_zipfile(config_source)):
        click.echo('Config source must be a .zip file.', file=sys.stderr)
        ctx.abort()

    send_value = create_base64encoded_zip(config_source)
    if not send_value:
        click.echo('Internal error: Unable to generate encoded zip',
                   file=sys.stderr)
        ctx.abort()

    config_source = {
        'configSourceType':
        oci.resource_manager.models.ConfigSource.CONFIG_SOURCE_TYPE_ZIP_UPLOAD,
        'zipFileBase64Encoded': send_value
    }

    if working_directory is not None:
        config_source['workingDirectory'] = working_directory

    json_skeleton_utils.remove_json_skeleton_params_from_dict(kwargs)

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    _details = {}
    _details['compartmentId'] = compartment_id
    _details['configSource'] = cli_util.parse_json_parameter(
        "config_source", config_source)

    if display_name is not None:
        _details['displayName'] = display_name

    if description is not None:
        _details['description'] = description

    if variables is not None:
        _details['variables'] = cli_util.parse_json_parameter(
            "variables", variables)

    if terraform_version is not None:
        _details['terraformVersion'] = terraform_version

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('resource_manager', 'resource_manager', ctx)
    result = client.create_stack(create_stack_details=_details, **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_stack') and callable(
                getattr(client, 'get_stack')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the work request has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(client,
                                        client.get_stack(result.data.id),
                                        'lifecycle_state', wait_for_state,
                                        **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the work request entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for work request to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the work request to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#11
0
def copy_stack(ctx, from_json, stack_id, destination_region,
               destination_compartment_id, display_name, description,
               freeform_tags, defined_tags, variables, access_token):

    if isinstance(stack_id, six.string_types) and len(stack_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --stack-id cannot be whitespace or empty string')

    if destination_region is not None and not is_region(destination_region):
        raise click.UsageError(
            "Unrecognized region: {}. Review valid regions at https://docs.oracle.com/iaas/Content/General/Concepts/regions.htm"
            .format(destination_region))

    inner_kwargs = {}
    inner_kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])
    client = cli_util.build_client('resource_manager', 'resource_manager', ctx)

    # GET Stack
    source_stack_response = client.get_stack(stack_id=stack_id, **inner_kwargs)

    source_region = ctx.obj['config']['region']
    if destination_region is not None and get_realm_from_region(
            destination_region) != get_realm_from_region(source_region):
        raise click.UsageError(
            "Invalid region. Destination region must be in the same realm {}. Review valid regions at https://docs.oracle.com/iaas/Content/General/Concepts/regions.htm"
            .format(destination_region))

    copy_display_name_prefix = "[copy-from-" + source_region + "]-"

    if destination_region is not None and destination_region == source_region:
        destination_region = None

    # Prepare Stack Metadata
    if source_stack_response is None or source_stack_response.data is None:
        raise Exception("Could not retrieve stack object",
                        inner_kwargs['opc_request_id'])

    source_stack = source_stack_response.data
    _details = copy_stack_metadata(source_stack, destination_compartment_id,
                                   display_name, description, freeform_tags,
                                   defined_tags, variables,
                                   copy_display_name_prefix)

    # get config source metadata for stack
    _details['configSource'] = get_config_source_metadata_for_stack(
        source_stack, destination_region, access_token)

    is_zip_upload = source_stack.config_source.config_source_type == oci.resource_manager.models.ConfigSource.CONFIG_SOURCE_TYPE_ZIP_UPLOAD or source_stack.config_source.config_source_type == oci.resource_manager.models.ConfigSource.CONFIG_SOURCE_TYPE_COMPARTMENT_CONFIG_SOURCE

    is_git_config = source_stack.config_source.config_source_type == oci.resource_manager.models.ConfigSource.CONFIG_SOURCE_TYPE_GIT_CONFIG_SOURCE

    if not is_zip_upload and not is_git_config:
        raise Exception(
            "Only zip-upload config, git-configuration-source and create-from-compartment stacks are supported for copy stack",
            inner_kwargs['opc_request_id'])

    # GET TF Config
    if is_zip_upload:
        stack_tf_config_response = client.get_stack_tf_config(
            stack_id=stack_id, **inner_kwargs)

        if stack_tf_config_response is None or stack_tf_config_response.data is None:
            raise Exception("Could not retrieve stack TF config",
                            inner_kwargs['opc_request_id'])

        base64encoded_stack_tf_config = get_source_stack_tf_config_base64encoded_zip(
            stack_id, stack_tf_config_response)
        _details['configSource'][
            'zipFileBase64Encoded'] = base64encoded_stack_tf_config

    # Setup Cross region
    if destination_region is not None and is_git_config:
        _get_config_details = {}

        # GET config source provider
        get_config_source_provider_response = client.get_configuration_source_provider(
            configuration_source_provider_id=source_stack.config_source.
            configuration_source_provider_id,
            **inner_kwargs)

        if get_config_source_provider_response is None or get_config_source_provider_response.data is None:
            raise Exception("Unable to get git config source provider",
                            inner_kwargs['opc_request_id'])

        _get_config_details.update(
            copy_git_config_source_provider_metadata(
                get_config_source_provider_response.data, access_token,
                copy_display_name_prefix))

        # Change region
        client.base_client.set_region(destination_region)

        # CREATE config source provider in new region
        create_config_source_provider_response = client.create_configuration_source_provider(
            create_configuration_source_provider_details=_get_config_details,
            **inner_kwargs)

        if create_config_source_provider_response is None or create_config_source_provider_response.data is None:
            raise Exception("Unable to copy Git configuration source provider",
                            inner_kwargs['opc_request_id'])

        cli_util.render_response(create_config_source_provider_response, ctx)
        _details['configSource'][
            'configurationSourceProviderId'] = create_config_source_provider_response.data.id
    elif destination_region is not None:
        # Change region
        client.base_client.set_region(destination_region)

    try:
        # CREATE stack
        result = client.create_stack(create_stack_details=_details,
                                     **inner_kwargs)
        cli_util.render_response(result, ctx)
    except Exception as e:
        print("Failed to copy stack: ", stack_id)
        print(e)
        if destination_region is not None and is_git_config:
            print("Deleting copied configuration source provider: ",
                  create_config_source_provider_response.data.id)

            # delete config source provider
            delete_config_source = client.delete_configuration_source_provider(
                configuration_source_provider_id=
                create_config_source_provider_response.data.id,
                **inner_kwargs)
示例#12
0
def update_rover_node(ctx, from_json, force, wait_for_state, max_wait_seconds, wait_interval_seconds, rover_node_id, display_name, serial_number, customer_shipping_address, node_workloads, super_user_password, unlock_passphrase, point_of_contact, point_of_contact_phone_number, oracle_shipping_tracking_url, shipping_preference, shipping_vendor, time_pickup_expected, lifecycle_state, enclosure_type, lifecycle_state_details, time_return_window_starts, time_return_window_ends, public_key, freeform_tags, defined_tags, system_tags, if_match):

    if isinstance(rover_node_id, six.string_types) and len(rover_node_id.strip()) == 0:
        raise click.UsageError('Parameter --rover-node-id cannot be whitespace or empty string')
    if not force:
        if customer_shipping_address or node_workloads or freeform_tags or defined_tags or system_tags:
            if not click.confirm("WARNING: Updates to customer-shipping-address and node-workloads and freeform-tags and defined-tags and system-tags will replace any existing values. Are you sure you want to continue?"):
                ctx.abort()

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id'])

    _details = {}

    if display_name is not None:
        _details['displayName'] = display_name

    if serial_number is not None:
        _details['serialNumber'] = serial_number

    if customer_shipping_address is not None:
        _details['customerShippingAddress'] = cli_util.parse_json_parameter("customer_shipping_address", customer_shipping_address)

    if node_workloads is not None:
        _details['nodeWorkloads'] = cli_util.parse_json_parameter("node_workloads", node_workloads)

    if super_user_password is not None:
        _details['superUserPassword'] = super_user_password

    if unlock_passphrase is not None:
        _details['unlockPassphrase'] = unlock_passphrase

    if point_of_contact is not None:
        _details['pointOfContact'] = point_of_contact

    if point_of_contact_phone_number is not None:
        _details['pointOfContactPhoneNumber'] = point_of_contact_phone_number

    if oracle_shipping_tracking_url is not None:
        _details['oracleShippingTrackingUrl'] = oracle_shipping_tracking_url

    if shipping_preference is not None:
        _details['shippingPreference'] = shipping_preference

    if shipping_vendor is not None:
        _details['shippingVendor'] = shipping_vendor

    if time_pickup_expected is not None:
        _details['timePickupExpected'] = time_pickup_expected

    if lifecycle_state is not None:
        _details['lifecycleState'] = lifecycle_state

    if enclosure_type is not None:
        _details['enclosureType'] = enclosure_type

    if lifecycle_state_details is not None:
        _details['lifecycleStateDetails'] = lifecycle_state_details

    if time_return_window_starts is not None:
        _details['timeReturnWindowStarts'] = time_return_window_starts

    if time_return_window_ends is not None:
        _details['timeReturnWindowEnds'] = time_return_window_ends

    if public_key is not None:
        _details['publicKey'] = public_key

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter("freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter("defined_tags", defined_tags)

    if system_tags is not None:
        _details['systemTags'] = cli_util.parse_json_parameter("system_tags", system_tags)

    client = cli_util.build_client('rover', 'rover_node', ctx)
    result = client.update_rover_node(
        rover_node_id=rover_node_id,
        update_rover_node_details=_details,
        **kwargs
    )
    if wait_for_state:

        if hasattr(client, 'get_rover_node') and callable(getattr(client, 'get_rover_node')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs['max_interval_seconds'] = wait_interval_seconds

                click.echo('Action completed. Waiting until the resource has entered state: {}'.format(wait_for_state), file=sys.stderr)
                result = oci.wait_until(client, client.get_rover_node(result.data.id), 'lifecycle_state', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo('Failed to wait until the resource entered the specified state. Outputting last known resource state', file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo('Encountered error while waiting for resource to enter the specified state. Outputting last known resource state', file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo('Unable to wait for the resource to enter the specified state', file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#13
0
def create_rover_node(ctx, from_json, wait_for_state, max_wait_seconds, wait_interval_seconds, display_name, compartment_id, customer_shipping_address, node_workloads, super_user_password, unlock_passphrase, point_of_contact, point_of_contact_phone_number, shipping_preference, shipping_vendor, time_pickup_expected, public_key, time_return_window_starts, time_return_window_ends, lifecycle_state, enclosure_type, lifecycle_state_details, serial_number, oracle_shipping_tracking_url, freeform_tags, defined_tags, system_tags):

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id'])

    _details = {}
    _details['displayName'] = display_name
    _details['compartmentId'] = compartment_id

    if customer_shipping_address is not None:
        _details['customerShippingAddress'] = cli_util.parse_json_parameter("customer_shipping_address", customer_shipping_address)

    if node_workloads is not None:
        _details['nodeWorkloads'] = cli_util.parse_json_parameter("node_workloads", node_workloads)

    if super_user_password is not None:
        _details['superUserPassword'] = super_user_password

    if unlock_passphrase is not None:
        _details['unlockPassphrase'] = unlock_passphrase

    if point_of_contact is not None:
        _details['pointOfContact'] = point_of_contact

    if point_of_contact_phone_number is not None:
        _details['pointOfContactPhoneNumber'] = point_of_contact_phone_number

    if shipping_preference is not None:
        _details['shippingPreference'] = shipping_preference

    if shipping_vendor is not None:
        _details['shippingVendor'] = shipping_vendor

    if time_pickup_expected is not None:
        _details['timePickupExpected'] = time_pickup_expected

    if public_key is not None:
        _details['publicKey'] = public_key

    if time_return_window_starts is not None:
        _details['timeReturnWindowStarts'] = time_return_window_starts

    if time_return_window_ends is not None:
        _details['timeReturnWindowEnds'] = time_return_window_ends

    if lifecycle_state is not None:
        _details['lifecycleState'] = lifecycle_state

    if enclosure_type is not None:
        _details['enclosureType'] = enclosure_type

    if lifecycle_state_details is not None:
        _details['lifecycleStateDetails'] = lifecycle_state_details

    if serial_number is not None:
        _details['serialNumber'] = serial_number

    if oracle_shipping_tracking_url is not None:
        _details['oracleShippingTrackingUrl'] = oracle_shipping_tracking_url

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter("freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter("defined_tags", defined_tags)

    if system_tags is not None:
        _details['systemTags'] = cli_util.parse_json_parameter("system_tags", system_tags)

    client = cli_util.build_client('rover', 'rover_node', ctx)
    result = client.create_rover_node(
        create_rover_node_details=_details,
        **kwargs
    )
    if wait_for_state:

        if hasattr(client, 'get_rover_node') and callable(getattr(client, 'get_rover_node')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs['max_interval_seconds'] = wait_interval_seconds

                click.echo('Action completed. Waiting until the resource has entered state: {}'.format(wait_for_state), file=sys.stderr)
                result = oci.wait_until(client, client.get_rover_node(result.data.id), 'lifecycle_state', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo('Failed to wait until the resource entered the specified state. Outputting last known resource state', file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo('Encountered error while waiting for resource to enter the specified state. Outputting last known resource state', file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo('Unable to wait for the resource to enter the specified state', file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#14
0
def update_transfer_appliance(ctx, from_json, force, wait_for_state,
                              max_wait_seconds, wait_interval_seconds, id,
                              transfer_appliance_label, lifecycle_state,
                              customer_shipping_address, if_match):

    if isinstance(id, six.string_types) and len(id.strip()) == 0:
        raise click.UsageError(
            'Parameter --id cannot be whitespace or empty string')

    if isinstance(transfer_appliance_label, six.string_types) and len(
            transfer_appliance_label.strip()) == 0:
        raise click.UsageError(
            'Parameter --transfer-appliance-label cannot be whitespace or empty string'
        )
    if not force:
        if customer_shipping_address:
            if not click.confirm(
                    "WARNING: Updates to customer-shipping-address will replace any existing values. Are you sure you want to continue?"
            ):
                ctx.abort()

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match

    _details = {}

    if lifecycle_state is not None:
        _details['lifecycleState'] = lifecycle_state

    if customer_shipping_address is not None:
        _details['customerShippingAddress'] = cli_util.parse_json_parameter(
            "customer_shipping_address", customer_shipping_address)

    client = cli_util.build_client('dts', 'transfer_appliance', ctx)
    result = client.update_transfer_appliance(
        id=id,
        transfer_appliance_label=transfer_appliance_label,
        update_transfer_appliance_details=_details,
        **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_transfer_appliance') and callable(
                getattr(client, 'get_transfer_appliance')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client, client.get_transfer_appliance(result.data.id),
                    'lifecycle_state', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#15
0
def update_oce_instance(ctx, from_json, force, wait_for_state,
                        max_wait_seconds, wait_interval_seconds,
                        oce_instance_id, description, waf_primary_domain,
                        instance_license_type, freeform_tags, defined_tags,
                        if_match):

    if isinstance(oce_instance_id, six.string_types) and len(
            oce_instance_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --oce-instance-id cannot be whitespace or empty string')
    if not force:
        if freeform_tags or defined_tags:
            if not click.confirm(
                    "WARNING: Updates to freeform-tags and defined-tags will replace any existing values. Are you sure you want to continue?"
            ):
                ctx.abort()

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    _details = {}

    if description is not None:
        _details['description'] = description

    if waf_primary_domain is not None:
        _details['wafPrimaryDomain'] = waf_primary_domain

    if instance_license_type is not None:
        _details['instanceLicenseType'] = instance_license_type

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('oce', 'oce_instance', ctx)
    result = client.update_oce_instance(oce_instance_id=oce_instance_id,
                                        update_oce_instance_details=_details,
                                        **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_work_request') and callable(
                getattr(client, 'get_work_request')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the work request has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client,
                    client.get_work_request(
                        result.headers['opc-work-request-id']), 'status',
                    wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the work request entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for work request to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the work request to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#16
0
def copy_boot_volume_backup(ctx, from_json, wait_for_state, max_wait_seconds,
                            wait_interval_seconds, boot_volume_backup_id,
                            destination_region, display_name, kms_key_id):

    if isinstance(boot_volume_backup_id, six.string_types) and len(
            boot_volume_backup_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --boot-volume-backup-id cannot be whitespace or empty string'
        )

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    details = {}
    details['destinationRegion'] = destination_region

    if display_name is not None:
        details['displayName'] = display_name

    if kms_key_id is not None:
        details['kmsKeyId'] = kms_key_id

    client = cli_util.build_client('core', 'blockstorage', ctx)
    result = client.copy_boot_volume_backup(
        boot_volume_backup_id=boot_volume_backup_id,
        copy_boot_volume_backup_details=details,
        **kwargs)
    # Newly created Resource will be in a different region from the origin region.
    # We should build the client for destination region
    ctx.obj['region'] = destination_region
    client = cli_util.build_client('core', 'blockstorage', ctx)
    if wait_for_state:
        if hasattr(client, 'get_boot_volume_backup') and callable(
                getattr(client, 'get_boot_volume_backup')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client, client.get_boot_volume_backup(result.data.id),
                    'lifecycle_state', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#17
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', '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)
示例#18
0
def schedule_key_version_deletion_extended(ctx, from_json, wait_for_state,
                                           max_wait_seconds,
                                           wait_interval_seconds, key_id,
                                           key_version_id, time_of_deletion,
                                           if_match):

    if isinstance(key_id, six.string_types) and len(key_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --key-id cannot be whitespace or empty string')

    if isinstance(key_version_id, six.string_types) and len(
            key_version_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --key-version-id cannot be whitespace or empty string')

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    _details = {}

    if time_of_deletion is not None:
        _details['timeOfDeletion'] = time_of_deletion

    client = cli_util.build_client('key_management', 'kms_management', ctx)
    result = client.schedule_key_version_deletion(
        key_id=key_id,
        key_version_id=key_version_id,
        schedule_key_version_deletion_details=_details,
        **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_key_version') and callable(
                getattr(client, 'get_key_version')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client, client.get_key_version(key_id, result.data.id),
                    'lifecycle_state', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
def assign_private_ip(ctx, from_json, vnic_id, vlan_id, ip_address, display_name, hostname_label, unassign_if_already_assigned, defined_tags, freeform_tags):
    networking_client = cli_util.build_client('core', 'virtual_network', ctx)
    assign_private_ip_request_body = {}
    is_ip_reassignment = False

    def _pre_strip(string):
        if string is None:
            return ""
        elif isinstance(string, six.string_types):
            return string.strip()
        else:
            raise click.UsageError('Unexpected format for string  {} '.format(string))

    vlan_id = _pre_strip(vlan_id)
    vnic_id = _pre_strip(vnic_id)

    if not any((vlan_id, vnic_id)):
        raise click.UsageError(
            'Parameter --vnic-id AND --vlan-id both cannot be whitespace or empty string. '
            'You have to specify one and ONLY one of these')
    elif all((vlan_id, vnic_id)):
        raise click.UsageError(
            'Parameter --vnic-id AND --vlan-id both cannot be specified at the same time. '
            'You have to specify one and ONLY one of these')

    if vlan_id:
        if ip_address is not None:
            # Try and see whether the private IP is already in use by calling ListPrivateIps with the IP address and subnet. In this case, we don't
            # worry about pagination because we expect at most 1 entry
            list_private_ips_response = networking_client.list_private_ips(ip_address=ip_address, vlan_id=vlan_id)
            list_private_ips_response_data = list_private_ips_response.data

            if list_private_ips_response_data is not None:
                if len(list_private_ips_response_data) == 1:
                    # If the IP is already on the VNIC, make this a no-op
                    if list_private_ips_response_data[0].vlan_id == vlan_id:
                        click.echo('Taking no action as IP address {} is already assigned to VLAN {}'.format(ip_address, vlan_id), err=True)
                        return
        assign_private_ip_request_body['vlanId'] = vlan_id
    else:
        # First we get the VNIC because we need to know the subnet OCID for the ListPrivateIps call
        vnic = networking_client.get_vnic(vnic_id).data
        subnet_id = vnic.subnet_id

        if ip_address is not None:
            # Try and see whether the private IP is already in use by calling ListPrivateIps with the IP address and subnet. In this case, we don't
            # worry about pagination because we expect at most 1 entry
            list_private_ips_response = networking_client.list_private_ips(ip_address=ip_address, subnet_id=subnet_id)
            list_private_ips_response_data = list_private_ips_response.data

            if list_private_ips_response_data is not None:
                if len(list_private_ips_response_data) == 1:
                    # If the IP is already on the VNIC, make this a no-op
                    if list_private_ips_response_data[0].vnic_id == vnic_id:
                        click.echo('Taking no action as IP address {} is already assigned to VNIC {}'.format(ip_address, vnic_id), err=True)
                        return

                    # The IP address exists and it can theoretically be moved since it isn't the primary IP and it is on a separate VNIC. However,
                    # if the user did not specify the --unassign-if-already-assigned flag then we do not proceed as they haven't explicitly
                    # said they want to do the reassignment
                    if not unassign_if_already_assigned:
                        sys.exit(
                            'IP address {} is already assigned to a different VNIC: {}. To reassign it, re-run this command with the --unassign-if-already-assigned option'.format(
                                ip_address, list_private_ips_response_data[0].vnic_id
                            )
                        )

                    is_ip_reassignment = True
                elif len(list_private_ips_response_data) > 1:
                    # This would be unexpected as it means that the IP exists twice in the subnet
                    sys.exit(
                        'IP address {} appeared {} times in subnet with OCID {}. It is expected to appear at most once (Request ID: {})'.format(
                            ip_address, len(list_private_ips_response_data), subnet_id, list_private_ips_response.request_id
                        )
                    )

        assign_private_ip_request_body['vnicId'] = vnic_id
        # These are optional in the request, so check whether we should set them or not.
        if hostname_label is not None:
            assign_private_ip_request_body['hostnameLabel'] = hostname_label

    # These are optional in the request, so check whether we should set them or not.
    if display_name is not None:
        assign_private_ip_request_body['displayName'] = display_name

    if defined_tags is not None:
        assign_private_ip_request_body['definedTags'] = cli_util.parse_json_parameter("defined_tags", defined_tags)
    if freeform_tags is not None:
        assign_private_ip_request_body['freeformTags'] = cli_util.parse_json_parameter("freeform_tags", freeform_tags)

    # If we are here then either the IP address does not exist or it is a candidate to be moved
    if not is_ip_reassignment:
        if ip_address is not None:
            assign_private_ip_request_body['ipAddress'] = ip_address

        result = networking_client.create_private_ip(assign_private_ip_request_body)
    else:
        result = networking_client.update_private_ip(list_private_ips_response_data[0].id, assign_private_ip_request_body)

    private_ip_id = result.data.id
    get_private_id_result = networking_client.get_private_ip(private_ip_id)

    cli_util.render_response(get_private_id_result, ctx)
示例#20
0
def update_transfer_device(ctx, from_json, wait_for_state, max_wait_seconds,
                           wait_interval_seconds, id, transfer_device_label,
                           lifecycle_state, if_match):

    if isinstance(id, six.string_types) and len(id.strip()) == 0:
        raise click.UsageError(
            'Parameter --id cannot be whitespace or empty string')

    if isinstance(transfer_device_label, six.string_types) and len(
            transfer_device_label.strip()) == 0:
        raise click.UsageError(
            'Parameter --transfer-device-label cannot be whitespace or empty string'
        )

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match

    details = {}

    if lifecycle_state is not None:
        details['lifecycleState'] = lifecycle_state

    client = cli_util.build_client('transfer_device', ctx)
    result = client.update_transfer_device(
        id=id,
        transfer_device_label=transfer_device_label,
        update_transfer_device_details=details,
        **kwargs)
    if wait_for_state:
        if hasattr(client, 'get_transfer_device') and callable(
                getattr(client, 'get_transfer_device')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client, client.get_transfer_device(result.data.id),
                    'lifecycle_state', wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#21
0
def create_rule(ctx, from_json, wait_for_state, max_wait_seconds,
                wait_interval_seconds, display_name, is_enabled, condition,
                compartment_id, actions, description, freeform_tags,
                defined_tags):

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    details = {}
    details['displayName'] = display_name
    details['isEnabled'] = is_enabled
    details['condition'] = condition
    details['compartmentId'] = compartment_id
    details['actions'] = cli_util.parse_json_parameter("actions", actions)

    if description is not None:
        details['description'] = description

    if freeform_tags is not None:
        details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('events', ctx)
    result = client.create_rule(create_rule_details=details, **kwargs)
    if wait_for_state:
        if hasattr(client, 'get_rule') and callable(getattr(
                client, 'get_rule')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(client,
                                        client.get_rule(result.data.id),
                                        'lifecycle_state', wait_for_state,
                                        **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#22
0
def create_esxi_host(ctx, from_json, wait_for_state, max_wait_seconds,
                     wait_interval_seconds, sddc_id, display_name, current_sku,
                     next_sku, compute_availability_domain,
                     failed_esxi_host_id, freeform_tags, defined_tags):

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    _details = {}
    _details['sddcId'] = sddc_id

    if display_name is not None:
        _details['displayName'] = display_name

    if current_sku is not None:
        _details['currentSku'] = current_sku

    if next_sku is not None:
        _details['nextSku'] = next_sku

    if compute_availability_domain is not None:
        _details['computeAvailabilityDomain'] = compute_availability_domain

    if failed_esxi_host_id is not None:
        _details['failedEsxiHostId'] = failed_esxi_host_id

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('ocvp', 'esxi_host', ctx)
    result = client.create_esxi_host(create_esxi_host_details=_details,
                                     **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_work_request') and callable(
                getattr(client, 'get_work_request')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the work request has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client,
                    client.get_work_request(
                        result.headers['opc-work-request-id']), 'status',
                    wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the work request entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for work request to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the work request to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#23
0
def update_rule(ctx, from_json, force, wait_for_state, max_wait_seconds,
                wait_interval_seconds, rule_id, display_name, description,
                is_enabled, condition, actions, freeform_tags, defined_tags,
                if_match):

    if isinstance(rule_id, six.string_types) and len(rule_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --rule-id cannot be whitespace or empty string')
    if not force:
        if actions or freeform_tags or defined_tags:
            if not click.confirm(
                    "WARNING: Updates to actions and freeform-tags and defined-tags will replace any existing values. Are you sure you want to continue?"
            ):
                ctx.abort()

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    details = {}

    if display_name is not None:
        details['displayName'] = display_name

    if description is not None:
        details['description'] = description

    if is_enabled is not None:
        details['isEnabled'] = is_enabled

    if condition is not None:
        details['condition'] = condition

    if actions is not None:
        details['actions'] = cli_util.parse_json_parameter("actions", actions)

    if freeform_tags is not None:
        details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('events', ctx)
    result = client.update_rule(rule_id=rule_id,
                                update_rule_details=details,
                                **kwargs)
    if wait_for_state:
        if hasattr(client, 'get_rule') and callable(getattr(
                client, 'get_rule')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the resource has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(client,
                                        client.get_rule(result.data.id),
                                        'lifecycle_state', wait_for_state,
                                        **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the resource entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for resource to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the resource to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#24
0
def create_gateway(ctx, from_json, wait_for_state, max_wait_seconds,
                   wait_interval_seconds, compartment_id, endpoint_type,
                   subnet_id, display_name, freeform_tags, defined_tags):

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    details = {}
    details['compartmentId'] = compartment_id
    details['endpointType'] = endpoint_type
    details['subnetId'] = subnet_id

    if display_name is not None:
        details['displayName'] = display_name

    if freeform_tags is not None:
        details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('gateway', ctx)
    result = client.create_gateway(create_gateway_details=details, **kwargs)
    if wait_for_state:
        if hasattr(client, 'get_work_request') and callable(
                getattr(client, 'get_work_request')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the work request has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client,
                    client.get_work_request(
                        result.headers['opc-work-request-id']), 'status',
                    wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the work request entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for work request to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the work request to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#25
0
def nfs_dataset_get_seal_status(ctx, from_json, name, appliance_profile):
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)
    click.echo("Getting the seal status of the dataset {}".format(name))
    seal_status = nfs_dataset_client.get_nfs_dataset_seal_status(name)
    cli_util.render_response(seal_status, ctx)
示例#26
0
def change_oce_instance_compartment(ctx, from_json, wait_for_state,
                                    max_wait_seconds, wait_interval_seconds,
                                    oce_instance_id, compartment_id, if_match):

    if isinstance(oce_instance_id, six.string_types) and len(
            oce_instance_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --oce-instance-id cannot be whitespace or empty string')

    kwargs = {}
    if if_match is not None:
        kwargs['if_match'] = if_match
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    _details = {}
    _details['compartmentId'] = compartment_id

    client = cli_util.build_client('oce', 'oce_instance', ctx)
    result = client.change_oce_instance_compartment(
        oce_instance_id=oce_instance_id,
        change_oce_instance_compartment_details=_details,
        **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_work_request') and callable(
                getattr(client, 'get_work_request')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the work request has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client,
                    client.get_work_request(
                        result.headers['opc-work-request-id']), 'status',
                    wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the work request entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for work request to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the work request to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#27
0
def nfs_dataset_show(ctx, from_json, name, appliance_profile):
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)
    nfs_dataset_info = nfs_dataset_client.get_nfs_dataset(name)
    cli_util.render_response(nfs_dataset_info, ctx)
示例#28
0
def create_oce_instance(ctx, from_json, wait_for_state, max_wait_seconds,
                        wait_interval_seconds, compartment_id, name,
                        tenancy_id, idcs_access_token, tenancy_name,
                        object_storage_namespace, admin_email, description,
                        identity_stripe, instance_usage_type, upgrade_schedule,
                        waf_primary_domain, instance_access_type,
                        instance_license_type, freeform_tags, defined_tags):

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])

    _details = {}
    _details['compartmentId'] = compartment_id
    _details['name'] = name
    _details['tenancyId'] = tenancy_id
    _details['idcsAccessToken'] = idcs_access_token
    _details['tenancyName'] = tenancy_name
    _details['objectStorageNamespace'] = object_storage_namespace
    _details['adminEmail'] = admin_email

    if description is not None:
        _details['description'] = description

    if identity_stripe is not None:
        _details['identityStripe'] = cli_util.parse_json_parameter(
            "identity_stripe", identity_stripe)

    if instance_usage_type is not None:
        _details['instanceUsageType'] = instance_usage_type

    if upgrade_schedule is not None:
        _details['upgradeSchedule'] = upgrade_schedule

    if waf_primary_domain is not None:
        _details['wafPrimaryDomain'] = waf_primary_domain

    if instance_access_type is not None:
        _details['instanceAccessType'] = instance_access_type

    if instance_license_type is not None:
        _details['instanceLicenseType'] = instance_license_type

    if freeform_tags is not None:
        _details['freeformTags'] = cli_util.parse_json_parameter(
            "freeform_tags", freeform_tags)

    if defined_tags is not None:
        _details['definedTags'] = cli_util.parse_json_parameter(
            "defined_tags", defined_tags)

    client = cli_util.build_client('oce', 'oce_instance', ctx)
    result = client.create_oce_instance(create_oce_instance_details=_details,
                                        **kwargs)
    if wait_for_state:

        if hasattr(client, 'get_work_request') and callable(
                getattr(client, 'get_work_request')):
            try:
                wait_period_kwargs = {}
                if max_wait_seconds is not None:
                    wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
                if wait_interval_seconds is not None:
                    wait_period_kwargs[
                        'max_interval_seconds'] = wait_interval_seconds

                click.echo(
                    'Action completed. Waiting until the work request has entered state: {}'
                    .format(wait_for_state),
                    file=sys.stderr)
                result = oci.wait_until(
                    client,
                    client.get_work_request(
                        result.headers['opc-work-request-id']), 'status',
                    wait_for_state, **wait_period_kwargs)
            except oci.exceptions.MaximumWaitTimeExceeded as e:
                # If we fail, we should show an error, but we should still provide the information to the customer
                click.echo(
                    'Failed to wait until the work request entered the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                sys.exit(2)
            except Exception:
                click.echo(
                    'Encountered error while waiting for work request to enter the specified state. Outputting last known resource state',
                    file=sys.stderr)
                cli_util.render_response(result, ctx)
                raise
        else:
            click.echo(
                'Unable to wait for the work request to enter the specified state',
                file=sys.stderr)
    cli_util.render_response(result, ctx)
示例#29
0
def nfs_dataset_create(ctx, from_json, rw, world, ip, subnet_mask_length, name, appliance_profile):
    result = _create_nfs_dataset_helper(
        create_nfs_dataset_client(ctx, appliance_profile), rw, world, ip, subnet_mask_length, name)
    cli_util.render_response(result, ctx)
示例#30
0
def setup_notifications_helper(ctx, create_topic_details, create_rule_kwargs):
    """
    Sets up notifications and prints out the commands that can be executed manually by the customer as well
    This helper populates the topicId for every action under the create_rule_kwargs actions if not provided
    :param ctx: The context object for the CLI command
    :param create_topic_details: A dictionary that contains the following keys:
        name - String, Required
        description - String, Required
        compartmentId - String, Required
    :param create_rule_kwargs: A dictionary that contains the following structure:
        display_name - String, Required
        compartment_id - String, Optional
        description - String, Required
        is_enabled - Bool, Required
        condition - String, Required
        actions - Dict, Required
            actions - List of dictionaries with the following keys, Required
                actionType - String, Required
                topicId - String, Optional
                isEnabled - Bool, Required

    :return:
    """

    # In case the user doesn't have the right credentials to do events and notifications, print the commands that
    # they can run with the right user
    click.echo(
        'If the commands fail to run, you can use the OCI CLI to do the setup manually:'
    )
    click.echo('oci ons topic create --compartment-id {} --name {} '
               '--description "{}"'.format(
                   create_topic_details['compartmentId'],
                   create_topic_details['name'],
                   create_topic_details['description']))
    click.echo(
        'oci ons subscription create --protocol EMAIL --compartment-id $ROOT_COMPARTMENT_OCID '
        '--topic-id $TOPIC_OCID --subscription_endpoint $EMAIL_ID')
    click.echo(
        'oci events rule create --display-name %s --is-enabled true'
        '--compartment-id %s '
        '--actions \'{"actions":[{"actionType":"ONS","topicId":"$TOPIC_OCID","isEnabled":true}]}\' '
        '--condition \'%s\' '
        '--description "%s"' %
        (create_rule_kwargs['display_name'],
         create_rule_kwargs['compartment_id'], create_rule_kwargs['condition'],
         create_rule_kwargs['description']))

    create_topic_kwargs = {
        'opc_request_id':
        cli_util.use_or_generate_request_id(ctx.obj['request_id'])
    }
    ctx.endpoint = None
    ctx.obj['endpoint'] = None
    create_topic_client = get_topic_client(ctx)
    click.echo('Creating topic {}'.format(create_topic_details['name']))
    create_topic_result = create_topic_client.create_topic(
        create_topic_details=create_topic_details, **create_topic_kwargs)
    cli_util.render_response(create_topic_result, ctx)

    # Create multiple subscriptions to the topic
    emails = prompt_for_emails()
    for email in emails.split(','):
        create_subscription_kwargs = {
            'protocol': 'EMAIL',
            'compartment_id': create_topic_details['compartmentId'],
            'topic_id': get_topic_id(create_topic_result),
            'subscription_endpoint': email
        }
        click.echo('Creating subscription for {}'.format(email))
        create_subscription_helper(ctx, create_subscription_kwargs)

    for index in range(len(create_rule_kwargs['actions']['actions'])):
        if 'topicId' not in create_rule_kwargs['actions']['actions'][index] or \
                create_rule_kwargs['actions']['actions'][index]['topicId'] is None:
            create_rule_kwargs['actions']['actions'][index][
                'topicId'] = get_topic_id(create_topic_result)
    click.echo('Creating rule {}'.format(create_rule_kwargs['display_name']))
    ctx.endpoint = None
    ctx.obj['endpoint'] = None
    create_rule_helper(ctx, create_rule_kwargs)