Beispiel #1
0
def nfs_dataset_seal(ctx, from_json, wait, name, appliance_profile):
    """
    1. Get the datasets. Since there is only one dataset, deactivate it if present, else throw a not found error
    2. If the dataset is ACTIVE, deactivate it
    3. Seal the dataset
    """
    nfs_dataset_client = create_nfs_dataset_client(ctx, appliance_profile)

    click.echo("Initiating Seal .... \n(Track progress using 'oci dts nfs-dataset seal-status' command)")
    click.echo("Fetching all the datasets ...\n")
    nfs_datasets = nfs_dataset_client.list_nfs_datasets().data
    if len(nfs_datasets) < 1:
        raise exceptions.ClientError("No datasets exist. Create a Dataset first")
    nfs_dataset = nfs_datasets[0]
    if name is not None:
        if name != nfs_dataset['name']:
            raise exceptions.ClientError("The dataset {} does not exist".format(name))
    name = nfs_dataset['name']
    if nfs_dataset['state'] == NfsDatasetInfo.STATE_ACTIVE:
        click.echo("Deactivating the dataset {}".format(name))
        nfs_dataset_client.deactivate_nfs_dataset(name)

    click.echo("Triggering seal on dataset {}".format(name))
    click.echo("This performs a pre-walk of the file system to check for invalid files before walking again "
               "to do the actual seal. This process can be time consuming depending on the size and number of files. "
               "Progress will be displayed once the pre-walk is done.")
    nfs_dataset_client.initiate_seal_on_nfs_dataset(name)
    seal_status = nfs_dataset_client.get_nfs_dataset_seal_status(name).data
    if wait:
        _seal_progress_display(seal_status)
        while seal_status['completed'] is None or not seal_status['completed']:
            time.sleep(0.5)
            seal_status = nfs_dataset_client.get_nfs_dataset_seal_status(name).data
            _seal_progress_display(seal_status)
        cli_util.render(seal_status, None, ctx)
Beispiel #2
0
def appliance_encryption_check(encryptionConfigured):
    '''
    :param encryptionConfigured: bool
    :return: raises exception if the encryptionConfigured is False
    '''
    if encryptionConfigured == 'False':
        raise exceptions.ClientError(
            "The Appliance is not configured for export. Contact Oracle Support"
        )
    else:
        click.echo("Appliance encryption is configured")
Beispiel #3
0
def _create_nfs_dataset_helper(nfs_dataset_client, rw, world, ip, subnet_mask_length, name):
    click.echo("Creating dataset with NFS export details {}".format(name))
    if (rw is None and world is not None) or (rw is not None and world is None):
        raise exceptions.ClientError("--rw and --world have to be passed together. You cannot set only one of them")
    export_configs = [{
        'readWrite': rw,
        'world': world,
        'ipAddress': ip,
        'subnetMaskLength': subnet_mask_length,
        'hostname': None
    }] if rw is not None and world is not None else None
    details = {
        'name': name,
        'nfsExportDetails': {
            'exportConfigs': export_configs
        }
    }
    return nfs_dataset_client.create_nfs_dataset(details)
Beispiel #4
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))