Esempio n. 1
0
def configure_physical_appliance_export_job_extended(ctx, **kwargs):
    # Should do:
    #   - oci dts update the export job to be in CUSTOMER_PROCESSING
    #   - Get the passphrase by doing a show_appliance_export_job_extended and parsing the passphrase
    #       - Use the output in the init auth and unlock appliance commands
    #   - oci dts physical-appliance initialize-authentication
    #   - oci dts physical-appliance unlock
    #   - oci dts nfs-dataset list
    #   - oci dts nfs-dataset set-export
    #   - oci dts nfs-dataset activate
    if isinstance(kwargs['job_id'], six.string_types) and len(
            kwargs['job_id'].strip()) == 0:
        raise click.UsageError(
            'Parameter --appliance-export-job-id cannot be whitespace or empty string'
        )
    client = cli_util.build_client('dts', 'appliance_export_job', ctx)

    kwargs_request = {
        'opc_request_id':
        cli_util.use_or_generate_request_id(ctx.obj['request_id'])
    }
    result = client.get_appliance_export_job(
        appliance_export_job_id=kwargs['job_id'], **kwargs_request)

    click.echo("Getting the serial number and passphrase of the appliance")
    serial_number = result.data.appliance_serial_number
    passphrase = result.data.appliance_decryption_passphrase
    appliance_profile = kwargs['appliance_profile']

    # Initialize authentication with XA
    click.echo("Initializing authentication with the appliance")
    pa_init_auth_helper(ctx, appliance_profile,
                        kwargs['appliance_cert_fingerprint'],
                        kwargs['appliance_ip'], kwargs['appliance_port'],
                        serial_number, kwargs['access_token'])

    # Appliance state change
    appliance_lifecycle_state = result.data.lifecycle_state
    appliance_lifecycle_state_details = result.data.lifecycle_state_details
    kwargs_update = appliance_state_update(appliance_lifecycle_state,
                                           appliance_lifecycle_state_details,
                                           **kwargs)
    if kwargs_update:
        ctx.invoke(applianceexportjob_cli.update_appliance_export_job,
                   **kwargs_update)

    # Get appliance info
    appliance_info = pa_show_helper(ctx=ctx,
                                    appliance_profile=appliance_profile,
                                    from_json=None)
    appliance_encryption_check(appliance_info.data['encryptionConfigured'])
    appliance_unlock(ctx, appliance_profile, passphrase,
                     appliance_info.data['lockStatus'])

    # There is only one dataset. Get the name of that dataset and use it to set exports and activate it
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)
    click.echo("Getting the NFS dataset on the appliance")

    nfs_datasets = nfs_dataset_client.list_nfs_datasets()

    if len(nfs_datasets.data) != 1:
        raise exceptions.ClientError(
            "No/multiple datasets exist on the appliance. Contact Oracle Support"
        )
    nfs_dataset_name = nfs_datasets.data[0]['name']
    nfs_dataset = nfs_datasets.data[0]
    # Check if the dataset is ACTIVE, if INACTIVE, do nothing
    # Deactivate the dataset before setting the exports
    deactivate_nfs_dataset(ctx, appliance_profile, **nfs_dataset)

    # Set the exports
    nfs_kwargs = {
        'rw': kwargs['rw'],
        'world': kwargs['world'],
        'ip': kwargs['ip'],
        'subnet_mask_length': kwargs['subnet_mask_length'],
        'name': nfs_dataset_name,
        'appliance_profile': appliance_profile
    }
    ctx.invoke(nfs_dataset_set_export, **nfs_kwargs)

    click.echo("Activating dataset {}".format(nfs_dataset_name))
    nfs_dataset_client.activate_nfs_dataset(nfs_dataset_name)
    click.echo("Dataset {} activated".format(nfs_dataset_name))
def configure_physical_appliance_export_job_extended(ctx, **kwargs):
    # Should do:
    #   - oci dts update the export job to be in CUSTOMER_PROCESSING
    #   - Get the passphrase by doing a show_appliance_export_job_extended and parsing the passphrase
    #       - Use the output in the init auth and unlock appliance commands
    #   - oci dts physical-appliance initialize-authentication
    #   - oci dts physical-appliance unlock
    #   - oci dts nfs-dataset list
    #   - oci dts nfs-dataset set-export
    #   - oci dts nfs-dataset activate
    if isinstance(kwargs['job_id'], six.string_types) and len(
            kwargs['job_id'].strip()) == 0:
        raise click.UsageError(
            'Parameter --appliance-export-job-id cannot be whitespace or empty string'
        )

    click.echo("Updating the state of the job to customer processing")
    kwargs_update = {
        'appliance_export_job_id': kwargs['job_id'],
        'lifecycle_state':
        UpdateApplianceExportJobDetails.LIFECYCLE_STATE_INPROGRESS,
        'lifecycle_state_details': LIFECYCLE_STATE_DETAILS_CUSTOMER_PROCESSING
    }
    ctx.invoke(applianceexportjob_cli.update_appliance_export_job,
               **kwargs_update)

    kwargs_request = {
        'opc_request_id':
        cli_util.use_or_generate_request_id(ctx.obj['request_id'])
    }
    client = cli_util.build_client('appliance_export_job', ctx)
    click.echo("Getting the serial number and passphrase of the appliance")
    result = client.get_appliance_export_job(
        appliance_export_job_id=kwargs['job_id'], **kwargs_request)
    serial_number = result.data.appliance_serial_number
    passphrase = result.data.appliance_decryption_passphrase
    appliance_profile = kwargs['appliance_profile']
    click.echo("Initializing authentication with the appliance")
    pa_init_auth_helper(ctx, appliance_profile,
                        kwargs['appliance_cert_fingerprint'],
                        kwargs['appliance_ip'], kwargs['appliance_port'],
                        serial_number, kwargs['access_token'])
    click.echo("Unlocking the appliance")
    pa_unlock_helper(ctx, appliance_profile, passphrase)

    # There is only one dataset. Get the name of that dataset and use it to set exports and activate it
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)
    click.echo("Getting the NFS dataset on the appliance")

    nfs_datasets = nfs_dataset_client.list_nfs_datasets()
    if len(nfs_datasets.data) != 1:
        raise exceptions.ClientError(
            "No/multiple datasets exist on the appliance. Contact Oracle Support"
        )
    nfs_dataset_name = nfs_datasets.data[0]['name']

    # Deactivate the dataset before setting the exports
    nfs_deactivate_kwargs = {
        'name': nfs_dataset_name,
        'appliance_profile': appliance_profile
    }
    ctx.invoke(nfs_dataset_deactivate, **nfs_deactivate_kwargs)
    nfs_kwargs = {
        'rw': kwargs['rw'],
        'world': kwargs['world'],
        'ip': kwargs['ip'],
        'subnet_mask_length': kwargs['subnet_mask_length'],
        'name': nfs_dataset_name,
        'appliance_profile': appliance_profile
    }
    ctx.invoke(nfs_dataset_set_export, **nfs_kwargs)

    click.echo("Activating dataset {}".format(nfs_dataset_name))
    nfs_dataset_client.activate_nfs_dataset(nfs_dataset_name)
    click.echo("Dataset {} activated".format(nfs_dataset_name))