Exemple #1
0
def appliance_unlock(ctx, appliance_profile, passphrase,
                     appliance_lock_status):
    '''
    Unlocks appliance if the lockStatus is LOCKED or NA
    :param ctx:
    :param appliance_profile: str
    :param passphrase: str
    :param appliance_lock_status: <state of appliance>
    :return: None if already in Unlocked state
    '''
    if appliance_lock_status in [APPLIANCE_STATE_LOCKED, APPLIANCE_STATUS_NA]:
        click.echo("Unlocking the appliance")
        pa_unlock_helper(ctx, appliance_profile, passphrase)
    else:
        click.echo("Appliance is already in UNLOCKED status")
        return None
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))