コード例 #1
0
ファイル: utils.py プロジェクト: hans-erickson/anaconda
def verify_root(storage, constraints, report_error, report_warning):
    """ Verify the root.

    :param storage: a storage to check
    :param constraints: a dictionary of constraints
    :param report_error: a function for error reporting
    :param report_warning: a function for warning reporting
    """
    root = storage.fsset.root_device

    if not root:
        report_error(
            _("You have not defined a root partition (/), "
              "which is required for installation of %s"
              " to continue.") % (productName, ))

    if root and root.format.exists and root.format.mountable and root.format.mountpoint == "/":
        report_error(
            _("You must create a new file system on the root device."))

    if storage.root_device and constraints[STORAGE_ROOT_DEVICE_TYPES]:
        device_type = get_device_type(storage.root_device)
        device_types = constraints[STORAGE_ROOT_DEVICE_TYPES]
        if device_type not in device_types:
            report_error(
                _("Your root partition must be on a device of type: %s.") %
                ", ".join(DEVICE_TEXT_MAP[t] for t in device_types))
コード例 #2
0
ファイル: devicefactory_test.py プロジェクト: yurchor/blivet
    def _validate_factory_device(self, *args, **kwargs):
        """ Validate the factory device against the factory args. """
        device = args[0]
        device_type = args[1]

        if kwargs.get("encrypted"):
            device_class = LUKSDevice
        else:
            device_class = self.device_class

        self.assertIsInstance(device, device_class)
        self.assertEqual(devicefactory.get_device_type(device), device_type)
        self.assertEqual(device.format.type, kwargs['fstype'])

        if hasattr(device.format, "mountpoint"):
            self.assertEqual(device.format.mountpoint,
                             kwargs.get('mountpoint'))

        if hasattr(device.format, "label"):
            self.assertEqual(device.format.label, kwargs.get('label'))

        self.assertLessEqual(device.size, kwargs.get("size"))
        self.assertGreaterEqual(device.size, device.format.min_size)
        if device.format.max_size:
            self.assertLessEqual(device.size, device.format.max_size)

        self.assertEqual(
            device.encrypted,
            kwargs.get("encrypted", False)
            or kwargs.get("container_encrypted", False))

        self.assertTrue(set(device.disks).issubset(kwargs["disks"]))
コード例 #3
0
    def _validate_factory_device(self, *args, **kwargs):
        """ Validate the factory device against the factory args. """
        device = args[0]
        device_type = args[1]
        size = args[2]

        if kwargs.get("encrypted"):
            device_class = LUKSDevice
        else:
            device_class = self.device_class

        self.assertIsInstance(device, device_class)
        self.assertEqual(devicefactory.get_device_type(device), device_type)
        self.assertEqual(device.format.type, kwargs['fstype'])

        if hasattr(device.format, "mountpoint"):
            self.assertEqual(device.format.mountpoint,
                             kwargs.get('mountpoint'))

        if hasattr(device.format, "label"):
            self.assertEqual(device.format.label,
                             kwargs.get('label'))

        self.assertLessEqual(device.size, size)
        self.assertGreaterEqual(device.size, device.format.min_size)
        if device.format.max_size:
            self.assertLessEqual(device.size, device.format.max_size)

        self.assertEqual(device.encrypted,
                         kwargs.get("encrypted", False) or
                         kwargs.get("container_encrypted", False))

        self.assertTrue(set(device.disks).issubset(kwargs["disks"]))
コード例 #4
0
ファイル: interactive_utils.py プロジェクト: carlzhc/anaconda
def collect_device_types(device, disks):
    """Collect supported device types for the given device.

    :param device: a device
    :param disks: a list of selected disks
    :return: a list of device types
    """
    # Collect the supported device types.
    supported_types = set(SUPPORTED_DEVICE_TYPES)

    # Include the type of the given device.
    supported_types.add(devicefactory.get_device_type(device))

    # Include md only if there are two or more disks.
    if len(disks) > 1:
        supported_types.add(devicefactory.DEVICE_TYPE_MD)

    # Include btrfs if it is both allowed and supported.
    fmt = get_format("btrfs")

    if fmt.supported \
            and fmt.formattable \
            and device.raw_device.format.type not in PARTITION_ONLY_FORMAT_TYPES + ("swap",):
        supported_types.add(devicefactory.DEVICE_TYPE_BTRFS)

    return sorted(
        filter(devicefactory.is_supported_device_type, supported_types))
コード例 #5
0
    def is_device_editable(self, device_name):
        """Is the specified device editable?

        :param device_name: a name of the device
        :return: True or False
        """
        device = self._get_device(device_name)
        return devicefactory.get_device_type(device) is not None
コード例 #6
0
ファイル: utils.py プロジェクト: zhoupeng/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))

    # Generate the device data.
    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)
    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]

    if request.device_type not in CONTAINER_DEVICE_TYPES:
        return request

    # Generate the container data.
    factory = devicefactory.get_device_factory(storage,
                                               device_type=device_type,
                                               device=device.raw_device)
    container = factory.get_container()

    if container:
        set_container_data(request, container)

    return request
コード例 #7
0
ファイル: interactive_utils.py プロジェクト: carlzhc/anaconda
def generate_device_info(storage, device):
    """Generate a device info for the given device.

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

    dev_info = dict()
    dev_info["device"] = device
    dev_info["name"] = getattr(device.raw_device, "lvname",
                               device.raw_device.name)
    dev_info["size"] = device.size
    dev_info["device_type"] = device_type
    dev_info["fstype"] = device.format.type
    dev_info["encrypted"] = isinstance(device, LUKSDevice)
    dev_info["luks_version"] = get_device_luks_version(device)
    dev_info["label"] = getattr(device.format, "label", "")
    dev_info["mountpoint"] = getattr(device.format, "mountpoint", None) or None
    dev_info["raid_level"] = get_device_raid_level(device)

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

    dev_info["disks"] = disks

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

    if container:
        dev_info["container_name"] = container.name
        dev_info["container_encrypted"] = container.encrypted
        dev_info["container_raid_level"] = get_device_raid_level(container)
        dev_info["container_size"] = getattr(container, "size_policy",
                                             container.size)
    else:
        dev_info["container_name"] = None
        dev_info["container_encrypted"] = False
        dev_info["container_raid_level"] = None
        dev_info["container_size"] = devicefactory.SIZE_POLICY_AUTO

    return dev_info
コード例 #8
0
ファイル: utils.py プロジェクト: arslongavitabrevis/anaconda
def get_container(storage, device_type, device=None):
    """Get a container of the given type.

    :param storage: an instance of Blivet
    :param device_type: a device type
    :param device: a defined factory device or None
    :return: a container device
    """
    if device_type not in CONTAINER_DEVICE_TYPES:
        raise StorageError("Invalid device type {}".format(device_type))

    if device and devicefactory.get_device_type(device) != device_type:
        device = None

    factory = devicefactory.get_device_factory(
        storage,
        device_type=device_type,
        size=Size(0),
    )

    return factory.get_container(device=device)
コード例 #9
0
    def _validate_factory_device(self, *args, **kwargs):
        """ Validate the factory device against the factory args. """
        device = args[0]
        device_type = args[1]

        if kwargs.get("encrypted"):
            device_class = LUKSDevice
        else:
            device_class = self.device_class

        self.assertIsInstance(device, device_class)
        self.assertEqual(devicefactory.get_device_type(device), device_type)
        self.assertEqual(device.format.type, kwargs['fstype'])

        if hasattr(device.format, "mountpoint"):
            self.assertEqual(device.format.mountpoint,
                             kwargs.get('mountpoint'))

        if hasattr(device.format, "label"):
            self.assertEqual(device.format.label, kwargs.get('label'))

        # sizes with VDO are special, we have a special check in LVMVDOFactoryTestCase._validate_factory_device
        if device_type != devicefactory.DEVICE_TYPE_LVM_VDO:
            self.assertLessEqual(device.size, kwargs.get("size"))
            self.assertGreaterEqual(device.size, device.format.min_size)
            if device.format.max_size:
                self.assertLessEqual(device.size, device.format.max_size)

        self.assertEqual(
            device.encrypted,
            kwargs.get("encrypted", False)
            or kwargs.get("container_encrypted", False))
        if kwargs.get("encrypted", False):
            self.assertEqual(
                device.parents[0].format.luks_version,
                kwargs.get("luks_version", crypto.DEFAULT_LUKS_VERSION))
            self.assertEqual(device.raw_device.format.luks_sector_size,
                             kwargs.get("luks_sector_size", 0))

        self.assertTrue(set(device.disks).issubset(kwargs["disks"]))
コード例 #10
0
ファイル: utils.py プロジェクト: arslongavitabrevis/anaconda
def _destroy_device(storage, device):
    """Destroy the given device in the storage model.

    :param storage: an instance of Blivet
    :param device: an instance of a device
    """
    # Remove the device.
    if device.is_disk and device.partitioned and not device.format.supported:
        storage.recursive_remove(device)
    elif device.direct and not device.isleaf:
        # We shouldn't call this method for with non-leaf devices
        # except for those which are also directly accessible like
        # lvm snapshot origins and btrfs subvolumes that contain
        # other subvolumes.
        storage.recursive_remove(device)
    else:
        storage.destroy_device(device)

    # Initialize the disk.
    if device.is_disk:
        storage.initialize_disk(device)

    # Remove empty extended partitions.
    if getattr(device, "is_logical", False):
        storage.remove_empty_extended_partitions()

    # If we've just removed the last partition and the disk label
    # is preexisting, reinitialize the disk.
    if device.type == "partition" and device.exists and device.disk.format.exists:
        config = DiskInitializationConfig()

        if config.can_initialize(storage, device.disk):
            storage.initialize_disk(device.disk)

    # Get the device container.
    if hasattr(device, "vg"):
        container = device.vg
        device_type = devicefactory.get_device_type(device)
    elif hasattr(device, "volume"):
        container = device.volume
        device_type = devicefactory.DEVICE_TYPE_BTRFS
    else:
        container = None
        device_type = None

    # Adjust container to size of remaining devices, if auto-sized.
    if (container and not container.exists and container.children
            and container.size_policy == devicefactory.SIZE_POLICY_AUTO):
        # Create the device factory.
        factory = devicefactory.get_device_factory(
            storage,
            device_type=device_type,
            size=Size(0),
            disks=container.disks,
            container_name=container.name,
            container_encrypted=container.encrypted,
            container_raid_level=get_device_raid_level(container),
            container_size=container.size_policy,
        )

        # Configure the factory's devices.
        factory.configure()

    # Finally, remove empty parents of the device.
    for parent in device.parents:
        if not parent.children and not parent.is_disk:
            destroy_device(storage, parent)