blob: 2980ce7a6d50185c942fc2227984eb8b0e97953d [file] [log] [blame]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001from django.db import models
Siobhan Tullycf04fb62014-01-11 11:25:57 -05002from core.models import User, Service, SingletonModel, PlCoreBase
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04003import os
4from django.db import models
5from django.forms.models import model_to_dict
6
7
8# Create your models here.
9
Siobhan Tullycf04fb62014-01-11 11:25:57 -050010class HpcService(SingletonModel,Service):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040011
12 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040013 app_label = "hpc"
Siobhan Tullycf04fb62014-01-11 11:25:57 -050014 verbose_name = "HPC Service"
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040015
Siobhan Tullycf04fb62014-01-11 11:25:57 -050016class ServiceProvider(PlCoreBase):
17 class Meta:
18 app_label = "hpc"
Scott Bakere728c892014-01-12 11:41:09 -080019
20 service_provider_id = models.IntegerField(null=True, blank=True)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040021 name = models.CharField(max_length=254,help_text="Service Provider Name")
22 description = models.TextField(max_length=254,null=True, blank=True, help_text="Description of Service Provider")
23 enabled = models.BooleanField(default=True)
24
25 def __unicode__(self): return u'%s' % (self.name)
26
Siobhan Tullycf04fb62014-01-11 11:25:57 -050027class ContentProvider(PlCoreBase):
28 class Meta:
29 app_label = "hpc"
Scott Bakere728c892014-01-12 11:41:09 -080030
Scott Baker7a090762014-05-07 09:04:07 -070031 # legacy vicci content providers already have names.
32 CP_TO_ACCOUNT = {"ON.LAB": "onlabcp",
33 "Syndicate": "syndicatecp"}
34
Scott Bakere728c892014-01-12 11:41:09 -080035 content_provider_id = models.IntegerField(null=True, blank=True)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040036 name = models.CharField(max_length=254)
37 enabled = models.BooleanField(default=True)
38 description = models.TextField(max_length=254,null=True, blank=True,help_text="Description of Content Provider")
39 serviceProvider = models.ForeignKey(ServiceProvider)
40
41 # Note user relationships are directed not requiring a role.
42 users = models.ManyToManyField(User)
43
44 def __unicode__(self): return u'%s' % (self.name)
45
Scott Baker7a090762014-05-07 09:04:07 -070046 @property
47 def account(self):
48 return self.CP_TO_ACCOUNT.get(self.name, self.name)
49
Siobhan Tullycf04fb62014-01-11 11:25:57 -050050class OriginServer(PlCoreBase):
51 class Meta:
52 app_label = "hpc"
Scott Bakere728c892014-01-12 11:41:09 -080053
54 origin_server_id = models.IntegerField(null=True, blank=True)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040055 url = models.URLField()
56 contentProvider = models.ForeignKey(ContentProvider)
57
58 authenticated = models.BooleanField(default=False, help_text="Status for this Site")
59 enabled = models.BooleanField(default=True, help_text="Status for this Site")
60 PROTOCOL_CHOICES = (('http', 'HTTP'),('rtmp', 'RTMP'), ('rtp', 'RTP'),('shout', 'SHOUTcast'))
61 protocol = models.CharField(default="HTTP", max_length = 12, choices=PROTOCOL_CHOICES)
62 redirects = models.BooleanField(default=True, help_text="Indicates whether Origin Server redirects should be used for this Origin Server")
63 description = models.TextField(null=True, blank=True, max_length=255)
64
65 def __unicode__(self): return u'%s' % (self.url)
66
Siobhan Tullycf04fb62014-01-11 11:25:57 -050067class CDNPrefix(PlCoreBase):
68 class Meta:
69 app_label = "hpc"
Scott Bakere728c892014-01-12 11:41:09 -080070
71 cdn_prefix_id = models.IntegerField(null=True, blank=True)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040072 prefix = models.CharField(max_length=200, help_text="Registered Prefix for Domain")
73 contentProvider = models.ForeignKey(ContentProvider)
74 description = models.TextField(max_length=254,null=True, blank=True,help_text="Description of Content Provider")
75
76 defaultOriginServer = models.ForeignKey(OriginServer)
77 enabled = models.BooleanField(default=True)
78
79 def __unicode__(self): return u'%s' % (self.prefix)
80
Scott Baker53491082014-03-13 23:15:19 -070081class AccessMap(models.Model):
82 contentProvider = models.ForeignKey(ContentProvider)
83 name = models.CharField(max_length=64, help_text="Name of the Access Map")
84 description = models.TextField(null=True, blank=True,max_length=130)
85 map = models.FileField(upload_to="maps/", help_text="specifies which client requests are allowed")
86
87 def __unicode__(self): return self.name
88
89class SiteMap(models.Model):
90 """ can be bound to a ContentProvider, ServiceProvider, or neither """
91 contentProvider = models.ForeignKey(ContentProvider, blank=True, null=True)
92 serviceProvider = models.ForeignKey(ServiceProvider, blank=True, null=True)
93 name = models.CharField(max_length=64, help_text="Name of the Site Map")
94 description = models.TextField(null=True, blank=True,max_length=130)
95 map = models.FileField(upload_to="maps/", help_text="specifies how to map requests to hpc instances")
96
97 def __unicode__(self): return self.name