Esempio n. 1
0
def summarize_device(device, part_filter=lambda p: True):
    """Return content for a table summarizing device.

    This (obj, cells) where obj is either device itself, a partition of
    device or None and cells is part of an argument to TableRow that
    will span 4 columns that describes device or a partition of
    device. This sounds a bit strange but hopefully you can figure it
    out by looking at the uses of this function.
    """
    label = labels.label(device)
    anns = labels.annotations(device)
    if anns:
        label = "{} ({})".format(label, ", ".join(anns))
    rows = [(device, [
        (2, Text(label)),
        Text(labels.desc(device)),
        Text(humanize_size(device.size), align="right"),
    ])]
    partitions = device.partitions()
    if partitions:
        for part in device.partitions():
            if not part_filter(part):
                continue
            details = ", ".join(
                labels.annotations(part) + labels.usage_labels(part))
            rows.append((part, [
                Text(labels.label(part, short=True)),
                (2, Text(details)),
                Text(humanize_size(part.size), align="right"),
            ]))
    else:
        rows.append((None, [
            (4, Color.info_minor(Text(", ".join(labels.usage_labels(device)))))
        ]))
    return rows
Esempio n. 2
0
 def desc(self):
     anns = labels.annotations(self.mount.device.volume)
     desc = labels.desc(self.mount.device.volume)
     if anns:
         desc = anns[0] + " " + desc
     return desc
Esempio n. 3
0
 def test_vg_encrypted_annotations(self):
     model, disk = make_model_and_disk()
     dm_crypt = model.add_dm_crypt(disk, key='passw0rd')
     vg = model.add_volgroup('vg-0', {dm_crypt})
     self.assertEqual(annotations(vg), ['new', 'encrypted'])
Esempio n. 4
0
 def test_vg_default_annotations(self):
     model, disk = make_model_and_disk()
     vg = model.add_volgroup('vg-0', {disk})
     self.assertEqual(annotations(vg), ['new'])
     vg.preserve = True
     self.assertEqual(annotations(vg), ['existing'])
Esempio n. 5
0
    def test_partition_annotations(self):
        model = make_model()
        part = make_partition(model)
        self.assertEqual(annotations(part), ['new'])
        part.preserve = True
        self.assertEqual(annotations(part), ['existing'])

        model = make_model()
        part = make_partition(model, flag="bios_grub")
        self.assertEqual(
            annotations(part), ['new', 'BIOS grub spacer'])
        part.preserve = True
        self.assertEqual(
            annotations(part),
            ['existing', 'unconfigured', 'BIOS grub spacer'])
        part.device.grub_device = True
        self.assertEqual(
            annotations(part),
            ['existing', 'configured', 'BIOS grub spacer'])

        model = make_model()
        part = make_partition(model, flag="boot", grub_device=True)
        self.assertEqual(annotations(part), ['new', 'backup ESP'])
        fs = model.add_filesystem(part, fstype="fat32")
        model.add_mount(fs, "/boot/efi")
        self.assertEqual(annotations(part), ['new', 'primary ESP'])

        model = make_model()
        part = make_partition(model, flag="boot", preserve=True)
        self.assertEqual(annotations(part), ['existing', 'unused ESP'])
        part.grub_device = True
        self.assertEqual(annotations(part), ['existing', 'backup ESP'])
        fs = model.add_filesystem(part, fstype="fat32")
        model.add_mount(fs, "/boot/efi")
        self.assertEqual(annotations(part), ['existing', 'primary ESP'])

        model = make_model()
        part = make_partition(model, flag="prep", grub_device=True)
        self.assertEqual(annotations(part), ['new', 'PReP'])

        model = make_model()
        part = make_partition(model, flag="prep", preserve=True)
        self.assertEqual(
            annotations(part), ['existing', 'PReP', 'unconfigured'])
        part.grub_device = True
        self.assertEqual(
            annotations(part), ['existing', 'PReP', 'configured'])
Esempio n. 6
0
 def test_disk_annotations(self):
     # disks never have annotations
     model, disk = make_model_and_disk()
     self.assertEqual(annotations(disk), [])
     disk.preserve = True
     self.assertEqual(annotations(disk), [])