How to use the blivet.formats.getFormat function in blivet

To help you get started, we’ve selected a few blivet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github storaged-project / blivet / blivet / populator.py View on Github external
elif format_type == "vfat":
            # efi magic
            if isinstance(device, PartitionDevice) and device.bootable:
                efi = formats.getFormat("efi")
                if efi.minSize <= device.size <= efi.maxSize:
                    format_designator = "efi"
        elif format_type == "hfsplus":
            if isinstance(device, PartitionDevice):
                macefi = formats.getFormat("macefi")
                if macefi.minSize <= device.size <= macefi.maxSize and \
                   device.partedPartition.name == macefi.name:
                    format_designator = "macefi"
        elif format_type == "hfs":
            # apple bootstrap magic
            if isinstance(device, PartitionDevice) and device.bootable:
                apple = formats.getFormat("appleboot")
                if apple.minSize <= device.size <= apple.maxSize:
                    format_designator = "appleboot"
        elif format_type == "btrfs":
            # the format's uuid attr will contain the UUID_SUB, while the
            # overarching volume UUID will be stored as volUUID
            kwargs["uuid"] = info["ID_FS_UUID_SUB"]
            kwargs["volUUID"] = uuid
        elif format_type == "multipath_member":
            # blkid does not care that the UUID it sees on a multipath member is
            # for the multipath set's (and not the member's) formatting, so we
            # have to discard it.
            kwargs.pop("uuid")
            kwargs.pop("label")

        try:
            log.info("type detected on '%s' is '%s'", name, format_designator)
github storaged-project / blivet / blivet / devicefactory.py View on Github external
parent_container = getattr(self.parent_factory, "container", None)
        if isinstance(self.device, LUKSDevice) and not self.encrypted:
            orig_device = self.device
            raw_device = self.raw_device
            leaf_format = self.device.format
            if parent_container:
                parent_container.parents.remove(orig_device)
            self.storage.destroyDevice(self.device)
            self.storage.formatDevice(self.raw_device, leaf_format)
            self.device = raw_device
            if parent_container:
                parent_container.parents.append(self.device)
        elif self.encrypted and not isinstance(self.device, LUKSDevice):
            orig_device = self.device
            leaf_format = self.device.format
            self.storage.formatDevice(self.device, getFormat("luks",
                                                             min_luks_entropy=self.min_luks_entropy))
            luks_device = LUKSDevice("luks-%s" % self.device.name,
                                     fmt=leaf_format,
                                     parents=self.device)
            self.storage.createDevice(luks_device)
            self.device = luks_device
            if parent_container:
                parent_container.parents.replace(orig_device, self.device)
github storaged-project / blivet / blivet / osinstall.py View on Github external
def proc(self):
        if not self._proc:
            self._proc = NoDevice(fmt=getFormat("proc", device="proc", mountpoint="/proc"))
        return self._proc
github storaged-project / blivet / blivet / osinstall.py View on Github external
# find device in the tree
        device = self.devicetree.resolveDevice(devspec,
                                               cryptTab=self.cryptTab,
                                               blkidTab=self.blkidTab,
                                               options=options)

        if device:
            # fall through to the bottom of this block
            pass
        elif devspec.startswith("/dev/loop"):
            # FIXME: create devices.LoopDevice
            log.warning("completely ignoring your loop mount")
        elif ":" in devspec and fstype.startswith("nfs"):
            # NFS -- preserve but otherwise ignore
            device = NFSDevice(devspec,
                               fmt=getFormat(fstype,
                                                exists=True,
                                                device=devspec))
        elif devspec.startswith("/") and fstype == "swap":
            # swap file
            device = FileDevice(devspec,
                                parents=get_containing_device(devspec, self.devicetree),
                                fmt=getFormat(fstype,
                                                 device=devspec,
                                                 exists=True),
                                exists=True)
        elif fstype == "bind" or "bind" in options:
            # bind mount... set fstype so later comparison won't
            # turn up false positives
            fstype = "bind"

            # This is probably not going to do anything useful, so we'll
github rhinstaller / anaconda / pyanaconda / kickstart.py View on Github external
parents=[vg],
                                    size=self.size,
                                    grow=self.grow,
                                    maxsize=self.maxSizeMB,
                                    percent=self.percent)

            storage.createDevice(request)

        if self.encrypted:
            if self.passphrase and not storage.encryptionPassphrase:
                storage.encryptionPassphrase = self.passphrase

            cert = getEscrowCertificate(storage.escrowCertificates, self.escrowcert)
            if self.preexist:
                luksformat = format
                device.format = getFormat("luks", passphrase=self.passphrase, device=device.path,
                                          cipher=self.cipher,
                                          escrow_cert=cert,
                                          add_backup_passphrase=self.backuppassphrase)
                luksdev = LUKSDevice("luks%d" % storage.nextID,
                                     format=luksformat,
                                     parents=device)
            else:
                luksformat = request.format
                request.format = getFormat("luks", passphrase=self.passphrase,
                                           cipher=self.cipher,
                                           escrow_cert=cert,
                                           add_backup_passphrase=self.backuppassphrase)
                luksdev = LUKSDevice("luks%d" % storage.nextID,
                                     format=luksformat,
                                     parents=request)
            storage.createDevice(luksdev)
github QubesOS / qubes-installer-qubes-os / anaconda / pyanaconda / ui / gui / spokes / custom.py View on Github external
# DEVICE TYPE
        device_type = self._get_current_device_type()
        old_device_type = devicefactory.get_device_type(device)
        changed_device_type = (old_device_type != device_type)
        old_device_info["device_type"] = old_device_type
        new_device_info["device_type"] = device_type

        # REFORMAT
        reformat = self._reformatCheckbox.get_active()
        log.debug("reformat: %s", reformat)

        # FS TYPE
        old_fs_type = device.format.type
        fs_type_index = self._fsCombo.get_active()
        fs_type_str = self._fsCombo.get_model()[fs_type_index][0]
        new_fs = getFormat(fs_type_str)
        fs_type = new_fs.type
        changed_fs_type = (old_fs_type != fs_type)
        old_device_info["fstype"] = old_fs_type
        new_device_info["fstype"] = fs_type

        # ENCRYPTION
        old_encrypted = isinstance(device, LUKSDevice)
        encrypted = self._encryptCheckbox.get_active() and self._encryptCheckbox.is_sensitive()
        changed_encryption = (old_encrypted != encrypted)
        old_device_info["encrypted"] = old_encrypted
        new_device_info["encrypted"] = encrypted

        # FS LABEL
        label = self._labelEntry.get_text()
        old_label = getattr(device.format, "label", "")
        changed_label = (label != old_label)
github storaged-project / blivet / blivet / devicefactory.py View on Github external
def _get_base_size(self):
        if self.device:
            min_format_size = self.device.format.minSize
        else:
            min_format_size = getFormat(self.fstype).minSize

        # min_format_size may be None here, make sure it is a number
        min_format_size = min_format_size or 0
        if self.encrypted:
            min_format_size += getFormat("luks").minSize

        return max(Size("1MiB"), min_format_size)
github QubesOS / qubes-installer-qubes-os / anaconda / pyanaconda / ui / gui / spokes / custom.py View on Github external
def _handle_encryption_change(self, encrypted, device, old_device, selector):
        if not encrypted:
            log.info("removing encryption from %s", device.name)
            self._storage_playground.destroyDevice(device)
            self._devices.remove(device)
            old_device = device
            device = device.slave
            selector.device = device
            self._update_device_in_selectors(old_device, device)
        else:
            log.info("applying encryption to %s", device.name)
            old_device = device
            new_fmt = getFormat("luks", device=device.path)
            self._storage_playground.formatDevice(device, new_fmt)
            luks_dev = LUKSDevice("luks-" + device.name,
                                  parents=[device])
            self._storage_playground.createDevice(luks_dev)
            self._devices.append(luks_dev)
            device = luks_dev
            selector.device = device
            self._update_device_in_selectors(old_device, device)

        self._devices = self._storage_playground.devices

        # possibly changed device and old_device, need to return the new ones
        return (device, old_device)
github storaged-project / blivet / blivet / devicefactory.py View on Github external
log.error("device post-create method failed: %s", e)
        else:
            if not device.size:
                e = StorageError("failed to create device")

        if e:
            self.storage.destroyDevice(device)
            raise StorageError(e)

        ret = device
        if self.encrypted:
            fmt_args = {}
            if self.label:
                fmt_args["label"] = self.label

            fmt = getFormat(self.fstype,
                            mountpoint=self.mountpoint,
                            min_luks_entropy=self.min_luks_entropy,
                            **fmt_args)
            luks_device = LUKSDevice("luks-" + device.name,
                                     parents=[device], fmt=fmt)
            self.storage.createDevice(luks_device)
            ret = luks_device

        self.device = ret