blob: 8d392a33c914120163237e21f61eef71fab81fd6 [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 Mack5ff90fc2015-02-08 21:38:41 -05004from core.models import Deployment, DeploymentPrivilege, Controller,ControllerLinkManager,ControllerLinkDeletionManager
Siobhan Tully4bc09f22013-04-10 21:15:21 -04005
6# Create your models here.
7
8class Image(PlCoreBase):
Siobhan Tully4bc09f22013-04-10 21:15:21 -04009 name = models.CharField(max_length=256, unique=True)
10 disk_format = models.CharField(max_length=256)
11 container_format = models.CharField(max_length=256)
Tony Mackbf39d9f2014-05-06 21:42:36 -040012 path = models.CharField(max_length=256, null=True, blank=True, help_text="Path to image on local disk")
Scott Baker5308f0a2014-12-22 15:59:05 -080013 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 -040014
15 def __unicode__(self): return u'%s' % (self.name)
Tony Mackbf39d9f2014-05-06 21:42:36 -040016
Tony Mack336e0f92014-11-30 15:53:08 -050017class ImageDeployments(PlCoreBase):
18 image = models.ForeignKey(Image,related_name='imagedeployments')
19 deployment = models.ForeignKey(Deployment,related_name='imagedeployments')
20
21 def __unicode__(self): return u'%s %s' % (self.image, self.deployment)
22
Tony Mack5ff90fc2015-02-08 21:38:41 -050023 def can_update(self, user):
24 return user.can_update_deployment(self.deployment)
25
Tony Mackf3bbe472014-11-30 15:33:35 -050026class ControllerImages(PlCoreBase):
27 objects = ControllerLinkManager()
28 deleted_objects = ControllerLinkDeletionManager()
29 image = models.ForeignKey(Image,related_name='controllerimages')
30 controller = models.ForeignKey(Controller,related_name='controllerimages')
Tony Mackbf39d9f2014-05-06 21:42:36 -040031 glance_image_id = models.CharField(null=True, blank=True, max_length=200, help_text="Glance image id")
32
Tony Mackf3bbe472014-11-30 15:33:35 -050033 def __unicode__(self): return u'%s %s' % (self.image, self.controller)