blob: 69d0f0321baed7ec519d9491416398c52ed992e6 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2from django.db import models
Siobhan Tully30fd4292013-05-10 08:59:56 -04003from core.models import PlCoreBase
Tony Mackd84b1ff2015-03-09 13:03:56 -04004from core.models.plcorebase import StrippedCharField
Tony Mack5ff90fc2015-02-08 21:38:41 -05005from core.models import Deployment, DeploymentPrivilege, Controller,ControllerLinkManager,ControllerLinkDeletionManager
Siobhan Tully4bc09f22013-04-10 21:15:21 -04006
7# Create your models here.
8
9class Image(PlCoreBase):
Scott Baker0cefa532015-11-09 16:17:11 -080010 KIND_CHOICES = (('vm', 'Virtual Machine'), ('container', 'Container'), )
11
Tony Mackd84b1ff2015-03-09 13:03:56 -040012 name = StrippedCharField(max_length=256, unique=True)
Scott Baker0cefa532015-11-09 16:17:11 -080013 kind = models.CharField(null=False, blank=False, max_length=30, choices=KIND_CHOICES, default="vm")
Tony Mackd84b1ff2015-03-09 13:03:56 -040014 disk_format = StrippedCharField(max_length=256)
15 container_format = StrippedCharField(max_length=256)
16 path = StrippedCharField(max_length=256, null=True, blank=True, help_text="Path to image on local disk")
Scott Baker5308f0a2014-12-22 15:59:05 -080017 deployments = models.ManyToManyField('Deployment', through='ImageDeployments', blank=True, help_text="Select which images should be instantiated on this deployment", related_name='images')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040018
Scott Bakerac69b6a2015-12-14 09:25:57 -080019 tag = StrippedCharField(max_length=256, null=True, blank=True, help_text="For Docker Images, tag of image")
20
Siobhan Tully4bc09f22013-04-10 21:15:21 -040021 def __unicode__(self): return u'%s' % (self.name)
Tony Mackbf39d9f2014-05-06 21:42:36 -040022
Tony Mack336e0f92014-11-30 15:53:08 -050023class ImageDeployments(PlCoreBase):
24 image = models.ForeignKey(Image,related_name='imagedeployments')
25 deployment = models.ForeignKey(Deployment,related_name='imagedeployments')
26
Tony Mack549f7b12015-04-11 12:17:59 -040027 class Meta:
28 unique_together = ('image', 'deployment')
Tony Macka4736f52015-03-09 17:13:14 -040029
Tony Mack336e0f92014-11-30 15:53:08 -050030 def __unicode__(self): return u'%s %s' % (self.image, self.deployment)
31
Tony Mack5ff90fc2015-02-08 21:38:41 -050032 def can_update(self, user):
33 return user.can_update_deployment(self.deployment)
34
Tony Mackf3bbe472014-11-30 15:33:35 -050035class ControllerImages(PlCoreBase):
36 objects = ControllerLinkManager()
37 deleted_objects = ControllerLinkDeletionManager()
38 image = models.ForeignKey(Image,related_name='controllerimages')
39 controller = models.ForeignKey(Controller,related_name='controllerimages')
Tony Mackd84b1ff2015-03-09 13:03:56 -040040 glance_image_id = StrippedCharField(null=True, blank=True, max_length=200, help_text="Glance image id")
Tony Mack549f7b12015-04-11 12:17:59 -040041
42 class Meta:
43 unique_together = ('image', 'controller')
Tony Macka4736f52015-03-09 17:13:14 -040044
Tony Mackf3bbe472014-11-30 15:33:35 -050045 def __unicode__(self): return u'%s %s' % (self.image, self.controller)