982 |
982 |
|
983 |
983 |
class Meta:
|
984 |
984 |
ordering = ['-created']
|
|
985 |
|
|
986 |
|
|
987 |
class Volume(models.Model):
|
|
988 |
"""Model representing a detachable block storage device."""
|
|
989 |
|
|
990 |
STATUS_VALUES = (
|
|
991 |
("CREATING", "The volume is being created"),
|
|
992 |
("AVAILABLE", "The volume is ready to be attached to an instance"),
|
|
993 |
("ATTACHING", "The volume is attaching to an instance"),
|
|
994 |
("DETACHING", "The volume is detaching from an instance"),
|
|
995 |
("IN_USE", "The volume is attached to an instance"),
|
|
996 |
("DELETING", "The volume is being deleted"),
|
|
997 |
("ERROR", "An error has occured with the volume"),
|
|
998 |
("ERROR_DELETING", "There was an error deleting this volume"),
|
|
999 |
("BACKING_UP", "The volume is being backed up"),
|
|
1000 |
("RESTORING_BACKUP", "A backup is being restored to the volume"),
|
|
1001 |
("ERROR_RESTORING", "There was an error restoring a backup from the"
|
|
1002 |
" volume")
|
|
1003 |
)
|
|
1004 |
|
|
1005 |
name = models.CharField("Name", max_length=255, null=True)
|
|
1006 |
description = models.CharField("Description", max_length=256, null=True)
|
|
1007 |
userid = models.CharField("Owner's UUID", max_length=100, null=False,
|
|
1008 |
db_index=True)
|
|
1009 |
size = models.IntegerField("Volume size in GB", null=False)
|
|
1010 |
source_image_id = models.CharField(max_length=100, null=True)
|
|
1011 |
source_snapshot_id = models.CharField(max_length=100, null=True)
|
|
1012 |
source_volume = models.ForeignKey("Volume",
|
|
1013 |
related_name="cloned_volumes",
|
|
1014 |
null=True)
|
|
1015 |
delete_on_termination = models.BooleanField("Delete on Server Termination",
|
|
1016 |
default=True, null=False)
|
|
1017 |
|
|
1018 |
# TODO: volume_type should be foreign key to VolumeType model
|
|
1019 |
volume_type = None
|
|
1020 |
deleted = models.BooleanField("Deleted", default=False, null=False)
|
|
1021 |
# Datetime fields
|
|
1022 |
created = models.DateTimeField(auto_now_add=True)
|
|
1023 |
updated = models.DateTimeField(auto_now=True)
|
|
1024 |
# Status
|
|
1025 |
status = models.CharField("Status", max_length=64,
|
|
1026 |
choices=STATUS_VALUES,
|
|
1027 |
default="CREATING", null=False)
|
|
1028 |
snapshot_counter = models.PositiveIntegerField(default=0, null=False)
|
|
1029 |
|
|
1030 |
machine = models.ForeignKey("VirtualMachine",
|
|
1031 |
related_name="volumes",
|
|
1032 |
null=True)
|
|
1033 |
index = models.IntegerField("Index", null=True)
|
|
1034 |
backendjobid = models.PositiveIntegerField(null=True)
|
|
1035 |
|
|
1036 |
@property
|
|
1037 |
def backend_volume_uuid(self):
|
|
1038 |
return u"%svolume-%d" % (settings.BACKEND_PREFIX_ID, self.id)
|
|
1039 |
|
|
1040 |
@property
|
|
1041 |
def backend_disk_uuid(self):
|
|
1042 |
return u"%sdisk-%d" % (settings.BACKEND_PREFIX_ID, self.id)
|
|
1043 |
|
|
1044 |
|
|
1045 |
class Metadata(models.Model):
|
|
1046 |
key = models.CharField("Metadata Key", max_length=64)
|
|
1047 |
value = models.CharField("Metadata Value", max_length=255)
|
|
1048 |
|
|
1049 |
class Meta:
|
|
1050 |
abstract = True
|
|
1051 |
|
|
1052 |
def __unicode__(self):
|
|
1053 |
return u"<%s: %s>" % (self.key, self.value)
|
|
1054 |
|
|
1055 |
|
|
1056 |
class VolumeMetadata(Metadata):
|
|
1057 |
volume = models.ForeignKey("Volume", related_name="metadata")
|
|
1058 |
|
|
1059 |
class Meta:
|
|
1060 |
unique_together = (("volume", "key"),)
|
|
1061 |
verbose_name = u"Key-Value pair of Volumes metadata"
|