Exemplo n.º 1
0
    def configure_storage(self, allow_fallback):
        # Circular imports.
        from maasserver.models import VMFS
        from maasserver.models.partition import Partition
        from maasserver.models.partitiontable import PartitionTable

        boot_partition_table = PartitionTable.objects.create(
            block_device=self.get_root_device(),
            table_type=PARTITION_TABLE_TYPE.GPT,
        )
        now = datetime.now()
        # The model rounds partition sizes for performance and has a min size
        # of 4MB. VMware ESXi does not conform to these constraints so add each
        # partition directly to get around the model. VMware ESXi always uses
        # the same UUIDs which is a constraint set at database level we can't
        # get around so leave them unset.
        # See https://kb.vmware.com/s/article/1036609
        Partition.objects.bulk_create([
            Partition(partition_table=boot_partition_table,
                      created=now,
                      updated=now,
                      **partition) for partition in self.base_partitions
        ])
        vmfs_part = boot_partition_table.partitions.get(size=0)
        root_size = self.get_root_size()
        if root_size is not None:
            vmfs_part.size = root_size
        else:
            vmfs_part.size = boot_partition_table.get_available_size()
        vmfs_part.save()
        # datastore1 is the default name VMware uses.
        VMFS.objects.create_vmfs(name="datastore1", partitions=[vmfs_part])
        return "VMFS6"
Exemplo n.º 2
0
    def add_partition(self, size=None, bootable=False, uuid=None):
        """Adds a partition to this partition table, returns the added
        partition.

        If size is omitted, the partition will extend to the end of the device.

        All partition sizes will be aligned down to PARTITION_ALIGNMENT_SIZE.
        """
        if size is None:
            size = self.get_available_size()
            if self.table_type == PARTITION_TABLE_TYPE.MBR:
                size = min(
                    size,
                    Partition._get_mbr_max_for_block_device(self.block_device))
        size = round_size_to_nearest_block(size, PARTITION_ALIGNMENT_SIZE,
                                           False)
        return Partition.objects.create(partition_table=self,
                                        size=size,
                                        uuid=uuid,
                                        bootable=bootable)
Exemplo n.º 3
0
 def test_remove_tag_deletes_tag(self):
     partition = Partition()
     tag = factory.make_name("tag")
     partition.add_tag(tag)
     partition.remove_tag(tag)
     self.assertItemsEqual([], partition.tags)
Exemplo n.º 4
0
 def test_add_tag_doesnt_duplicate(self):
     partition = Partition()
     tag = factory.make_name("tag")
     partition.add_tag(tag)
     partition.add_tag(tag)
     self.assertItemsEqual([tag], partition.tags)
Exemplo n.º 5
0
 def test_add_tag_adds_new_tag(self):
     partition = Partition()
     tag = factory.make_name("tag")
     partition.add_tag(tag)
     self.assertItemsEqual([tag], partition.tags)
Exemplo n.º 6
0
    def create_basic_layout(self, boot_size=None):
        """Create the basic layout that is similar for all layout types.

        :return: The created root partition.
        """
        # Circular imports.
        from maasserver.models.filesystem import Filesystem
        from maasserver.models.partitiontable import PartitionTable
        boot_partition_table = PartitionTable.objects.create(
            block_device=self.boot_disk)
        bios_boot_method = self.node.get_bios_boot_method()
        node_arch, _ = self.node.split_arch()
        if (boot_partition_table.table_type == PARTITION_TABLE_TYPE.GPT and
                bios_boot_method == "uefi" and node_arch != "ppc64el"):
            # Add EFI partition only if booting UEFI and not a ppc64el
            # architecture.
            efi_partition = boot_partition_table.add_partition(
                size=EFI_PARTITION_SIZE, bootable=True)
            Filesystem.objects.create(
                partition=efi_partition,
                fstype=FILESYSTEM_TYPE.FAT32,
                label="efi",
                mount_point="/boot/efi")
        elif (bios_boot_method != "uefi" and node_arch == "arm64" and
                boot_size is None):
            # Add boot partition only if booting an arm64 architecture and
            # not UEFI and boot_size is None.
            boot_partition = boot_partition_table.add_partition(
                size=MIN_BOOT_PARTITION_SIZE, bootable=True)
            Filesystem.objects.create(
                partition=boot_partition,
                fstype=FILESYSTEM_TYPE.EXT4,
                label="boot",
                mount_point="/boot")
        if boot_size is None:
            boot_size = self.get_boot_size()
        if boot_size > 0:
            boot_partition = boot_partition_table.add_partition(
                size=boot_size, bootable=True)
            Filesystem.objects.create(
                partition=boot_partition,
                fstype=FILESYSTEM_TYPE.EXT4,
                label="boot",
                mount_point="/boot")
        root_device = self.get_root_device()
        root_size = self.get_root_size()
        if root_device is None or root_device == self.boot_disk:
            # Fix the maximum root_size for MBR.
            max_mbr_size = Partition._get_mbr_max_for_block_device(
                self.boot_disk)
            if (boot_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and
                    root_size is not None and root_size > max_mbr_size):
                root_size = max_mbr_size
            root_partition = boot_partition_table.add_partition(
                size=root_size)
            return root_partition, boot_partition_table
        else:
            root_partition_table = PartitionTable.objects.create(
                block_device=root_device)
            # Fix the maximum root_size for MBR.
            max_mbr_size = Partition._get_mbr_max_for_block_device(
                root_device)
            if (root_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and
                    root_size is not None and root_size > max_mbr_size):
                root_size = max_mbr_size
            root_partition = root_partition_table.add_partition(
                size=root_size)
            return root_partition, root_partition_table