Exemple #1
0
    def execute(self, intf=None):
        self.device.setup()

        if isinstance(self.device, PartitionDevice):
            for flag in partitionFlag.keys():
                # Keep the LBA flag on pre-existing partitions
                if flag in [ PARTITION_LBA, self.format.partedFlag ]:
                    continue
                self.device.unsetFlag(flag)

            if self.format.partedFlag is not None:
                self.device.setFlag(self.format.partedFlag)

            if self.format.partedSystem is not None:
                self.device.partedPartition.system = self.format.partedSystem

            self.device.disk.format.commitToDisk()

        self.device.format.create(intf=intf,
                                  device=self.device.path,
                                  options=self.device.formatArgs)
        # Get the UUID now that the format is created
        udev_settle()
        self.device.updateSysfsPath()
        info = udev_get_block_device(self.device.sysfsPath)
        self.device.format.uuid = udev_device_get_uuid(info)
Exemple #2
0
    def execute(self):
        self.device.setup()

        if isinstance(self.device, Partition):
            for flag in partitionFlag.keys():
                # Keep the LBA flag on pre-existing partitions
                if flag in [ PARTITION_LBA, self.format.partedFlag ]:
                    continue
                self.device.unsetFlag(flag)

            if self.format.partedFlag is not None:
                self.device.setFlag(self.format.partedFlag)

            if self.format.partedSystem is not None:
                self.device.partedPartition.system = self.format.partedSystem

            self.device.disk.format.commitToDisk()

        self.device.format.create(device=self.device.path,
                                  options=self.device.formatArgs)

        # Get the UUID now that the format is created
        yali.baseudev.udev_settle()
        self.device.updateSysfsPath()
        info = udev_get_block_device(self.device.sysfsPath)
        self.device.format.uuid = udev_device_get_uuid(info)
Exemple #3
0
    def execute(self):
        super(ActionCreateFormat, self).execute()
        msg = _("Creating %(type)s on %(device)s") % {"type": self.device.format.type, "device": self.device.path}
        with progress_report(msg):
            self.device.setup()

            if isinstance(self.device, PartitionDevice):
                for flag in partitionFlag.keys():
                    # Keep the LBA flag on pre-existing partitions
                    if flag in [ PARTITION_LBA, self.format.partedFlag ]:
                        continue
                    self.device.unsetFlag(flag)

                if self.format.partedFlag is not None:
                    self.device.setFlag(self.format.partedFlag)

                if self.format.partedSystem is not None:
                    self.device.partedPartition.system = self.format.partedSystem

                self.device.disk.format.commitToDisk()

            self.device.format.create(device=self.device.path,
                                      options=self.device.formatArgs)
            # Get the UUID now that the format is created
            info = udev.get_device(self.device.sysfsPath)
            # only do this if the format has a device known to udev
            # (the format might not have a normal device at all)
            if info:
                if self.device.format.type != "btrfs":
                    self.device.format.uuid = udev.device_get_uuid(info)

                self.device.deviceLinks = udev.device_get_symlinks(info)
            elif self.device.format.type != "tmpfs":
                # udev lookup failing is a serious issue for anything other than tmpfs
                log.error("udev lookup failed for device: %s", self.device)
Exemple #4
0
    def execute(self, intf=None):
        self.device.setup()

        if isinstance(self.device, Partition):
            for flag in partitionFlag.keys():
                # Keep the LBA flag on pre-existing partitions
                if flag in [PARTITION_LBA, self.format.partedFlag]:
                    continue
                self.device.unsetFlag(flag)

            if self.format.partedFlag is not None:
                self.device.setFlag(self.format.partedFlag)

            if self.format.partedSystem is not None:
                self.device.partedPartition.system = self.format.partedSystem

            self.device.disk.format.commitToDisk()

        info = udev_get_block_device(self.device.sysfsPath)
        try:
            olduuid = udev_device_get_uuid(info)
        except AttributeError:
            olduuid = ""

        self.device.format.create(intf=intf,
                                  device=self.device.path,
                                  options=self.device.formatArgs)

        # Get the UUID now that the format is created
        yali.baseudev.udev_settle()
        self.device.updateSysfsPath()
        if olduuid:
            newuuid = olduuid
            # wait for new uuid
            while newuuid == olduuid:
                info = udev_get_block_device(self.device.sysfsPath)
                newuuid = udev_device_get_uuid(info)
            self.device.format.uuid = newuuid
        else:
            info = udev_get_block_device(self.device.sysfsPath)
            self.device.format.uuid = udev_device_get_uuid(info)
    def execute(self, intf=None):
        self.device.setup()

        if isinstance(self.device, Partition):
            for flag in partitionFlag.keys():
                # Keep the LBA flag on pre-existing partitions
                if flag in [ PARTITION_LBA, self.format.partedFlag ]:
                    continue
                self.device.unsetFlag(flag)

            if self.format.partedFlag is not None:
                self.device.setFlag(self.format.partedFlag)

            if self.format.partedSystem is not None:
                self.device.partedPartition.system = self.format.partedSystem

            self.device.disk.format.commitToDisk()

        info = udev_get_block_device(self.device.sysfsPath)
        try:
            olduuid = udev_device_get_uuid(info)
        except AttributeError:
            olduuid = ""

        self.device.format.create(intf=intf,
                                  device=self.device.path,
                                  options=self.device.formatArgs)

        # Get the UUID now that the format is created
        yali.baseudev.udev_settle()
        self.device.updateSysfsPath()
        if olduuid:
            newuuid = olduuid
            # wait for new uuid
            while newuuid == olduuid:
                info = udev_get_block_device(self.device.sysfsPath)
                newuuid = udev_device_get_uuid(info)
            self.device.format.uuid = newuuid
        else:
            info = udev_get_block_device(self.device.sysfsPath)
            self.device.format.uuid = udev_device_get_uuid(info)
Exemple #6
0
    def execute(self):
        super(ActionCreateFormat, self).execute()
        msg = _("Creating %(type)s on %(device)s") % {"type": self.device.format.type, "device": self.device.path}
        with progress_report(msg):
            self.device.setup()

            if isinstance(self.device, PartitionDevice):
                for flag in partitionFlag.keys():
                    # Keep the LBA flag on pre-existing partitions
                    if flag in [ PARTITION_LBA, self.format.partedFlag ]:
                        continue
                    self.device.unsetFlag(flag)

                if self.format.partedFlag is not None:
                    self.device.setFlag(self.format.partedFlag)

                if self.format.partedSystem is not None:
                    self.device.partedPartition.system = self.format.partedSystem

                self.device.disk.format.commitToDisk()

            self.device.format.create(device=self.device.path,
                                      options=self.device.formatArgs)
            # Get the UUID now that the format is created
            udev.udev_settle()
            self.device.updateSysfsPath()
            info = udev.udev_get_block_device(self.device.sysfsPath)
            # only do this if the format has a device known to udev
            # (the format might not have a normal device at all)
            if info:
                if self.device.format.type != "btrfs":
                    self.device.format.uuid = udev.udev_device_get_uuid(info)

                self.device.deviceLinks = udev.udev_device_get_symlinks(info)
            elif self.device.format.type != "tmpfs":
                # udev lookup failing is a serious issue for anything other than tmpfs
                log.error("udev lookup failed for device: %s", self.device)
Exemple #7
0
    def execute(self, callbacks=None):
        super(ActionCreateFormat, self).execute(callbacks=callbacks)
        if callbacks and callbacks.create_format_pre:
            msg = _("Creating %(type)s on %(device)s") % {"type": self.device.format.type, "device": self.device.path}
            callbacks.create_format_pre(CreateFormatPreData(msg))

        if isinstance(self.device, PartitionDevice) and self.device.disklabel_supported:
            for flag in partitionFlag.keys():
                # Keep the LBA flag on pre-existing partitions
                if flag in [PARTITION_LBA, self.format.parted_flag]:
                    continue
                self.device.unset_flag(flag)

            if self.format.parted_flag is not None:
                self.device.set_flag(self.format.parted_flag)

            if self.format.parted_system is not None:
                self.device.parted_partition.system = self.format.parted_system

            self.device.disk.format.commit_to_disk()
            udev.settle()

        if isinstance(self.device.format, luks.LUKS):
            if self.device.format.min_luks_entropy is None:
                min_required_entropy = luks_data.min_entropy
            else:
                min_required_entropy = self.device.format.min_luks_entropy

            # LUKS needs to wait for random data entropy if it is too low
            current_entropy = get_current_entropy()
            if current_entropy < min_required_entropy:
                force_cont = False
                if callbacks and callbacks.wait_for_entropy:
                    msg = _("Not enough entropy to create LUKS format. "
                            "%d bits are needed.") % min_required_entropy
                    force_cont = callbacks.wait_for_entropy(WaitForEntropyData(msg, min_required_entropy))

                if force_cont:
                    # log warning and set format's required entropy to 0
                    log.warning("Forcing LUKS creation regardless of enough "
                                "random data entropy (%d/%d)",
                                get_current_entropy(), min_required_entropy)
                    luks_data.min_entropy = 0

        self.device.setup()
        self.device.format.create(device=self.device.path,
                                  options=self.device.format_args)

        # Get the UUID now that the format is created
        udev.settle()
        self.device.update_sysfs_path()
        info = udev.get_device(self.device.sysfs_path)
        # only do this if the format has a device known to udev
        # (the format might not have a normal device at all)
        if info:
            if self.device.format.type != "btrfs":
                self.device.format.uuid = udev.device_get_uuid(info)
            self.device.device_links = udev.device_get_symlinks(info)
        elif self.device.format.type != "tmpfs":
            # udev lookup failing is a serious issue for anything other than tmpfs
            log.error("udev lookup failed for device: %s", self.device)

        if callbacks and callbacks.create_format_post:
            msg = _("Created %(type)s on %(device)s") % {"type": self.device.format.type, "device": self.device.path}
            callbacks.create_format_post(CreateFormatPostData(msg))
Exemple #8
0
    def execute(self, callbacks=None):
        super(ActionCreateFormat, self).execute(callbacks=callbacks)
        if callbacks and callbacks.create_format_pre:
            msg = _("Creating %(type)s on %(device)s") % {
                "type": self.device.format.type,
                "device": self.device.path
            }
            callbacks.create_format_pre(CreateFormatPreData(msg))

        if isinstance(self.device,
                      PartitionDevice) and self.device.disklabel_supported:
            for flag in partitionFlag.keys():
                # Keep the LBA flag on pre-existing partitions
                if flag in [PARTITION_LBA, self.format.parted_flag]:
                    continue
                self.device.unset_flag(flag)

            if self.format.parted_flag is not None:
                self.device.set_flag(self.format.parted_flag)

            if self.format.parted_system is not None:
                self.device.parted_partition.system = self.format.parted_system

            self.device.disk.format.commit_to_disk()
            udev.settle()

        if isinstance(self.device.format, luks.LUKS):
            if self.device.format.min_luks_entropy is None:
                min_required_entropy = luks_data.min_entropy
            else:
                min_required_entropy = self.device.format.min_luks_entropy

            # LUKS needs to wait for random data entropy if it is too low
            current_entropy = get_current_entropy()
            if current_entropy < min_required_entropy:
                force_cont = False
                if callbacks and callbacks.wait_for_entropy:
                    msg = _("Not enough entropy to create LUKS format. "
                            "%d bits are needed.") % min_required_entropy
                    force_cont = callbacks.wait_for_entropy(
                        WaitForEntropyData(msg, min_required_entropy))

                if force_cont:
                    # log warning and set format's required entropy to 0
                    log.warning(
                        "Forcing LUKS creation regardless of enough "
                        "random data entropy (%d/%d)", get_current_entropy(),
                        min_required_entropy)
                    luks_data.min_entropy = 0

        self.device.setup()
        self.device.format.create(device=self.device.path,
                                  options=self.device.format_args)

        # Get the UUID now that the format is created
        udev.settle()
        self.device.update_sysfs_path()
        info = udev.get_device(self.device.sysfs_path)
        # only do this if the format has a device known to udev
        # (the format might not have a normal device at all)
        if info:
            if self.device.format.type != "btrfs":
                self.device.format.uuid = udev.device_get_uuid(info)
            self.device.device_links = udev.device_get_symlinks(info)
        elif self.device.format.type != "tmpfs":
            # udev lookup failing is a serious issue for anything other than tmpfs
            log.error("udev lookup failed for device: %s", self.device)

        if callbacks and callbacks.create_format_post:
            msg = _("Created %(type)s on %(device)s") % {
                "type": self.device.format.type,
                "device": self.device.path
            }
            callbacks.create_format_post(CreateFormatPostData(msg))