1
# Copyright 2015 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Model for a partition in a partition table."""
6
from __future__ import (
19
from uuid import uuid4
21
from django.db.models import (
27
from maasserver import DefaultMeta
28
from maasserver.enum import PARTITION_TABLE_TYPE
29
from maasserver.models.cleansave import CleanSave
30
from maasserver.models.partitiontable import PartitionTable
31
from maasserver.models.timestampedmodel import TimestampedModel
34
class Partition(CleanSave, TimestampedModel):
35
"""A partition in a partition table.
37
:ivar partition_table: `PartitionTable` this partition belongs to.
38
:ivar uuid: UUID of the partition if it's part of a GPT partition.
39
:ivar start_offset: Offset in bytes the partition is from the start of
41
:ivar size: Size of the partition in bytes.
42
:ivar bootable: Whether the partition is set as bootable.
45
class Meta(DefaultMeta):
46
"""Needed for South to recognize this model."""
48
partition_table = ForeignKey(
49
PartitionTable, null=False, blank=False, related_name="partitions")
52
max_length=36, unique=True, null=True, blank=True)
54
start_offset = BigIntegerField(null=False)
56
size = BigIntegerField(null=False)
58
bootable = BooleanField(default=False)
61
"""`Node` this partition belongs to."""
62
return self.partition_table.get_node()
64
def get_block_size(self):
65
"""Block size of partition."""
66
return self.partition_table.get_block_size()
68
def save(self, *args, **kwargs):
70
if (self.partition_table.table_type == PARTITION_TABLE_TYPE.GPT and
72
# Partition is part of a GPT partition table and doesn't have
73
# a UUID set. Set the UUID so MAAS will know the UUID of the
74
# partition on the created machine.
76
return super(Partition, self).save(*args, **kwargs)