Revision 01e9dcaf

b/snf-cyclades-app/synnefo/db/models.py
980 980

  
981 981
    class Meta:
982 982
        ordering = ['-created']
983

  
984

  
985
class Volume(models.Model):
986
    """Model representing a detachable block storage device."""
987

  
988
    STATUS_VALUES = (
989
        ("CREATING", "The volume is being created"),
990
        ("AVAILABLE", "The volume is ready to be attached to an instance"),
991
        ("ATTACHING", "The volume is attaching to an instance"),
992
        ("DETACHING", "The volume is detaching from an instance"),
993
        ("IN_USE", "The volume is attached to an instance"),
994
        ("DELETING", "The volume is being deleted"),
995
        ("ERROR", "An error has occured with the volume"),
996
        ("ERROR_DELETING", "There was an error deleting this volume"),
997
        ("BACKING_UP", "The volume is being backed up"),
998
        ("RESTORING_BACKUP", "A backup is being restored to the volume"),
999
        ("ERROR_RESTORING", "There was an error restoring a backup from the"
1000
                            " volume")
1001
    )
1002

  
1003
    name = models.CharField("Name", max_length=255, null=True)
1004
    description = models.CharField("Description", max_length=255, null=True)
1005
    userid = models.CharField("Owner's UUID", max_length=100, null=False,
1006
                              db_index=True)
1007
    size = models.IntegerField("Volume size in GB",  null=False)
1008
    source_image_id = models.CharField(max_length=100, null=True)
1009
    source_snapshot_id = models.CharField(max_length=100, null=True)
1010
    source_volume = models.ForeignKey("Volume",
1011
                                      related_name="cloned_volumes",
1012
                                      null=True)
1013
    # TODO: volume_type should be foreign key to VolumeType model
1014
    volume_type = None
1015
    deleted = models.BooleanField("Deleted", default=False, null=False)
1016
    # Datetime fields
1017
    created = models.DateTimeField(auto_now_add=True)
1018
    updated = models.DateTimeField(auto_now=True)
1019
    # Status
1020
    status = models.CharField("Status", max_length=64,
1021
                              choices=STATUS_VALUES,
1022
                              default="CREATING", null=False)
1023
    snapshot_counter = models.PositiveIntegerField(default=0, null=False)
1024

  
1025
    machine = models.ForeignKey("VirtualMachine",
1026
                                related_name="volumes",
1027
                                null=True)
1028
    index = models.IntegerField("Index", null=True)
1029
    backendjobid = models.PositiveIntegerField(null=True)
1030

  
1031
    @property
1032
    def backend_volume_uuid(self):
1033
        return u"%svolume-%d" % (settings.BACKEND_PREFIX_ID, self.id)
1034

  
1035
    @property
1036
    def backend_disk_uuid(self):
1037
        return u"%sdisk-%d" % (settings.BACKEND_PREFIX_ID, self.id)
1038

  
1039

  
1040
class Metadata(models.Model):
1041
    key = models.CharField("Metadata Key", max_length=64)
1042
    value = models.CharField("Metadata Value", max_length=255)
1043

  
1044
    class Meta:
1045
        abstract = True
1046

  
1047
    def __unicode__(self):
1048
        return u"<%s: %s>" % (self.key, self.value)
1049

  
1050

  
1051
class VolumeMetadata(Metadata):
1052
    volume = models.ForeignKey("Volume", related_name="metadata")
1053

  
1054
    class Meta:
1055
        unique_together = (("volume", "key"),)
1056
        verbose_name = u"Key-Value pair of Volumes metadata"
b/snf-cyclades-app/synnefo/db/models_factory.py
286 286
    server_id = 1
287 287
    network_id = 1
288 288
    active = True
289

  
290

  
291
class VolumeFactory(factory.DjangoModelFactory):
292
    FACTORY_FOR = models.Volume
293
    userid = factory.Sequence(user_seq())
294
    size = factory.Sequence(lambda x: x, type=int)
295
    name = factory.Sequence(lambda x: "volume-name-"+x, type=str)

Also available in: Unified diff