def lost_focus(self): val = self.value if not val: return suffixes = ''.join(HUMAN_UNITS) + ''.join(HUMAN_UNITS).lower() if val[-1] not in suffixes: unit = self.form.size_str[-1] val += unit self.value = val try: sz = self.form.size.value except ValueError: return if sz > self.form.max_size: self.value = self.form.size_str self.form.size.show_extra( ('info_minor', _("Capped partition size at {size}").format( size=self.form.size_str))) elif (align_up(sz) != sz and humanize_size(align_up(sz)) != self.form.size.value): sz_str = humanize_size(align_up(sz)) self.value = sz_str self.form.size.show_extra( ('info_minor', _("Rounded size up to {size}").format(size=sz_str)))
def partition_disk_handler(self, disk, partition, spec): log.debug('partition_disk_handler: %s %s %s', disk, partition, spec) log.debug('disk.freespace: {}'.format(disk.free_for_partitions)) if partition is not None: if 'size' in spec: partition.size = align_up(spec['size']) if disk.free_for_partitions < 0: raise Exception("partition size too large") self.delete_filesystem(partition.fs()) self.create_filesystem(partition, spec) return if len(disk.partitions()) == 0: if disk.type == "disk": disk.preserve = False disk.wipe = 'superblock-recursive' needs_boot = self.model.needs_bootloader_partition() log.debug('model needs a bootloader partition? {}'.format(needs_boot)) can_be_boot = DeviceAction.TOGGLE_BOOT in disk.supported_actions if needs_boot and len(disk.partitions()) == 0 and can_be_boot: part = self._create_boot_partition(disk) # adjust downward the partition size (if necessary) to accommodate # bios/grub partition if spec['size'] > disk.free_for_partitions: log.debug("Adjusting request down: %s - %s = %s", spec['size'], part.size, disk.free_for_partitions) spec['size'] = disk.free_for_partitions self.create_partition(disk, spec) log.debug("Successfully added partition")
def partition_disk_handler(self, disk, partition, spec): log.debug('partition_disk_handler: %s %s %s', disk, partition, spec) log.debug('disk.freespace: {}'.format(disk.free_for_partitions)) if partition is not None: partition.size = align_up(spec['size']) if disk.free_for_partitions < 0: raise Exception("partition size too large") self.delete_filesystem(partition.fs()) self.create_filesystem(partition, spec) return bootable = self.model.bootable() log.debug('model has bootable device? {}'.format(bootable)) can_be_boot = disk.supports_action(DeviceAction.MAKE_BOOT) if not bootable and len(disk.partitions()) == 0 and can_be_boot: part = self._create_boot_partition(disk) # adjust downward the partition size (if necessary) to accommodate # bios/grub partition if spec['size'] > disk.free_for_partitions: log.debug( "Adjusting request down: %s - %s = %s", spec['size'], part.size, disk.free_for_partitions) spec['size'] = disk.free_for_partitions self.create_partition(disk, spec) log.info("Successfully added partition")
def partition_disk_handler(self, disk, partition, spec): log.debug('spec: {}'.format(spec)) log.debug('disk.freespace: {}'.format(disk.free)) if partition is not None: partition.size = align_up(spec['size']) if disk.free < 0: raise Exception("partition size too large") old_fs = partition.fs() if old_fs is not None: self.model._filesystems.remove(old_fs) partition._fs = None mount = old_fs.mount() if mount is not None: old_fs._mount = None self.model._mounts.remove(mount) if spec['fstype'].label is not None: fs = self.model.add_filesystem(partition, spec['fstype'].label) if spec['mount']: self.model.add_mount(fs, spec['mount']) self.partition_disk(disk) return system_bootable = self.model.bootable() log.debug('model has bootable device? {}'.format(system_bootable)) if not system_bootable and len(disk.partitions()) == 0: if self.is_uefi(): part_size = UEFI_GRUB_SIZE_BYTES if UEFI_GRUB_SIZE_BYTES * 2 >= disk.size: part_size = disk.size // 2 log.debug('Adding EFI partition first') part = self.model.add_partition(disk=disk, size=part_size, flag='boot') fs = self.model.add_filesystem(part, 'fat32') self.model.add_mount(fs, '/boot/efi') else: log.debug('Adding grub_bios gpt partition first') part = self.model.add_partition(disk=disk, size=BIOS_GRUB_SIZE_BYTES, flag='bios_grub') disk.grub_device = True # adjust downward the partition size (if necessary) to accommodate # bios/grub partition if spec['size'] > disk.free: log.debug( "Adjusting request down:" + "{} - {} = {}".format(spec['size'], part.size, disk.free)) spec['size'] = disk.free part = self.model.add_partition(disk=disk, size=spec["size"]) if spec['fstype'].label is not None: fs = self.model.add_filesystem(part, spec['fstype'].label) if spec['mount']: self.model.add_mount(fs, spec['mount']) log.info("Successfully added partition") self.partition_disk(disk)
def logical_volume_handler(self, vg, lv, spec): log.debug('logical_volume_handler: %s %s %s', vg, lv, spec) log.debug('vg.freespace: {}'.format(vg.free_for_partitions)) if lv is not None: lv.name = spec['name'] lv.size = align_up(spec['size']) if vg.free_for_partitions < 0: raise Exception("lv size too large") self.delete_filesystem(lv.fs()) self.create_filesystem(lv, spec) return self.create_logical_volume(vg, spec)