~ltrager/maas/remove_di_from_kernel_opts

« back to all changes in this revision

Viewing changes to src/maasserver/models/partition.py

  • Committer: Lee Trager
  • Date: 2016-10-22 06:06:12 UTC
  • mfrom: (5457.1.44 maas)
  • Revision ID: lee.trager@canonical.com-20161022060612-ukar20f6ffs45nas
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
 
173
173
    def get_partition_number(self):
174
174
        """Return the partition number in the table."""
 
175
        # Circular imports.
 
176
        from maasserver.models.partitiontable import GPT_REQUIRED_SIZE
175
177
        # Sort manually instead of with `order_by`, this will prevent django
176
178
        # from making a query if the partitions are already cached.
177
179
        partitions_in_table = self.partition_table.partitions.all()
178
180
        partitions_in_table = sorted(partitions_in_table, key=attrgetter('id'))
179
181
        idx = partitions_in_table.index(self)
180
182
        if self.partition_table.table_type == PARTITION_TABLE_TYPE.GPT:
181
 
            # ppc64el machines get part1 skipped when this partition is on
182
 
            # the boot disk. This is because the prep partition is part1 and
183
 
            # is added when the preseed for storage is generated.
 
183
            # In some instances the first partition is skipped because it
 
184
            # is used by the machine architecture for a specific reason.
 
185
            #   * ppc64el - reserved for prep partition
 
186
            #   * amd64 (disk >= 2TiB) - reserved for bios_grub partition
184
187
            node = self.get_node()
185
188
            arch, _ = node.split_arch()
186
189
            boot_disk = node.get_boot_disk()
 
190
            bios_boot_method = node.get_bios_boot_method()
187
191
            if (arch == "ppc64el" and
188
192
                    self.partition_table.block_device.id == boot_disk.id):
189
193
                return idx + 2
 
194
            elif (arch == "amd64" and
 
195
                    self.partition_table.block_device.id == boot_disk.id and
 
196
                    bios_boot_method != "uefi" and
 
197
                    boot_disk.size >= GPT_REQUIRED_SIZE):
 
198
                return idx + 2
190
199
            else:
191
200
                return idx + 1
192
201
        elif self.partition_table.table_type == PARTITION_TABLE_TYPE.MBR: