コード例 #1
0
ファイル: utils.py プロジェクト: arslongavitabrevis/anaconda
def update_container_data(storage, request: DeviceFactoryRequest,
                          container_name):
    """Update the container data in the device factory request.

    :param storage: an instance of Blivet
    :param request: a device factory request
    :param container_name: a container name to apply
    """
    # Reset all container data.
    request.reset_container_data()

    # Check the device type.
    if request.device_type not in CONTAINER_DEVICE_TYPES:
        raise StorageError("Invalid device type.")

    # Find the container in the device tree if any.
    container = storage.devicetree.get_device_by_name(container_name)

    if container:
        # Set the request from the found container.
        request.container_spec = container.name
        request.container_name = container.name
        request.container_encrypted = container.encrypted
        request.container_raid_level = get_device_raid_level_name(container)
        request.container_size_policy = get_container_size_policy(container)

        # Use the container's disks.
        request.disks = [d.name for d in container.disks]
    else:
        # Set the request from the new container.
        request.container_name = container_name
        request.container_raid_level = get_default_container_raid_level_name(
            request.device_type)
コード例 #2
0
ファイル: utils.py プロジェクト: arslongavitabrevis/anaconda
def generate_container_data(storage, request: DeviceFactoryRequest):
    """Generate the container data for the device factory request.

    :param storage: an instance of Blivet
    :param request: a device factory request
    """
    # Reset all container data.
    request.reset_container_data()

    # Check the device type.
    if request.device_type not in CONTAINER_DEVICE_TYPES:
        return

    # Find a container of the requested type.
    device = storage.devicetree.resolve_device(request.device_spec)
    container = get_container(storage, request.device_type, device.raw_device)

    if container:
        # Set the request from the found container.
        request.container_spec = container.name
        request.container_name = container.name
        request.container_encrypted = container.encrypted
        request.container_raid_level = get_device_raid_level_name(container)
        request.container_size_policy = get_container_size_policy(container)
    else:
        # Set the request from a new container.
        request.container_name = storage.suggest_container_name()
        request.container_raid_level = get_default_container_raid_level_name(
            request.device_type)
コード例 #3
0
    def reset_device_factory_request_test(self):
        """Test reset_container_data."""
        default = DeviceFactoryRequest()
        request = DeviceFactoryRequest()

        request.container_spec = "dev1"
        request.container_name = "dev1"
        request.container_size_policy = 123
        request.container_encrypted = True
        request.container_raid_level = "raid1"
        request.reset_container_data()

        self.assertEqual(compare_data(request, default), True)
コード例 #4
0
def set_container_data(request: DeviceFactoryRequest, container):
    """Set the container data in the device factory request.

    :param request: a device factory request
    :param container: a container
    """
    request.container_spec = container.name
    request.container_name = container.name
    request.container_encrypted = container.encrypted
    request.container_raid_level = get_device_raid_level_name(container)
    request.container_size_policy = get_container_size_policy(container)

    if request.container_encrypted:
        request.luks_version = get_container_luks_version(container)
コード例 #5
0
ファイル: utils.py プロジェクト: arslongavitabrevis/anaconda
def generate_device_factory_request(storage, device) -> DeviceFactoryRequest:
    """Generate a device info for the given device.

    :param storage: an instance of Blivet
    :param device: a device
    :return: a device factory request
    """
    device_type = devicefactory.get_device_type(device)

    if device_type is None:
        raise UnsupportedDeviceError("Unsupported type of {}.".format(
            device.name))

    request = DeviceFactoryRequest()
    request.device_spec = device.name
    request.device_name = getattr(device.raw_device, "lvname",
                                  device.raw_device.name)
    request.device_size = device.size.get_bytes()
    request.device_type = device_type
    request.reformat = not device.format.exists
    request.format_type = device.format.type or ""
    request.device_encrypted = isinstance(device, LUKSDevice)
    request.luks_version = get_device_luks_version(device) or ""
    request.label = getattr(device.format, "label", "") or ""
    request.mount_point = getattr(device.format, "mountpoint", "") or ""
    request.device_raid_level = get_device_raid_level_name(device)

    if hasattr(device, "req_disks") and not device.exists:
        disks = device.req_disks
    else:
        disks = device.disks

    request.disks = [d.name for d in disks]

    factory = devicefactory.get_device_factory(storage,
                                               device_type=device_type,
                                               device=device.raw_device)
    container = factory.get_container()

    if container:
        request.container_spec = container.name
        request.container_name = container.name
        request.container_encrypted = container.encrypted
        request.container_raid_level = get_device_raid_level_name(container)
        request.container_size_policy = get_container_size_policy(container)

    return request