blob: 9f5409ec90ad9a97eb9c14094a11f1eab95a35ac [file] [log] [blame]
Scott Baker7a327592016-06-20 17:34:06 -07001from django.db import models
2from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber
3from core.models.plcorebase import StrippedCharField
4import os
5from django.db import models, transaction
6from django.forms.models import model_to_dict
7from django.db.models import Q
8from operator import itemgetter, attrgetter, methodcaller
9import traceback
10from xos.exceptions import *
11from core.models import SlicePrivilege, SitePrivilege
12from sets import Set
13
14ONOS_KIND = "onos"
15
16class ONOSService(Service):
17 KIND = ONOS_KIND
18
19 class Meta:
20 app_label = "onos"
21 verbose_name = "ONOS Service"
Scott Baker7a327592016-06-20 17:34:06 -070022
Scott Baker88b71092017-03-13 15:15:29 -070023 rest_hostname = StrippedCharField(max_length=255, null=True, blank=True)
24 rest_port = models.IntegerField(default=8181)
25 no_container = models.BooleanField(default=False)
26 node_key = StrippedCharField(max_length=1024, null=True, blank=True)
Scott Baker7a327592016-06-20 17:34:06 -070027
28class ONOSApp(Tenant): # aka 'ONOSTenant'
29 class Meta:
Scott Baker88b71092017-03-13 15:15:29 -070030 app_label = "onos"
Scott Baker7a327592016-06-20 17:34:06 -070031
32 KIND = ONOS_KIND
33
Scott Baker88b71092017-03-13 15:15:29 -070034 name = StrippedCharField(max_length=255, null=True, blank=True)
35 install_dependencies = models.TextField(null=True, blank=True)
36 dependencies = models.TextField(null=True, blank=True)
37
38 # why is this necessary?
39 creator = models.ForeignKey(User, related_name='onos_apps', blank=True, null=True)
40
Scott Baker7a327592016-06-20 17:34:06 -070041 def __init__(self, *args, **kwargs):
42 onos_services = ONOSService.get_service_objects().all()
43 if onos_services:
44 self._meta.get_field("provider_service").default = onos_services[0].id
45 super(ONOSApp, self).__init__(*args, **kwargs)
46
Scott Baker7a327592016-06-20 17:34:06 -070047 def save(self, *args, **kwargs):
48 if not self.creator:
49 if not getattr(self, "caller", None):
50 # caller must be set when creating a vCPE since it creates a slice
51 raise XOSProgrammingError("ONOSApp's self.caller was not set")
52 self.creator = self.caller
53 if not self.creator:
54 raise XOSProgrammingError("ONOSApp's self.creator was not set")
55
56 super(ONOSApp, self).save(*args, **kwargs)
Scott Baker7a327592016-06-20 17:34:06 -070057
Scott Baker88b71092017-03-13 15:15:29 -070058
Scott Baker7a327592016-06-20 17:34:06 -070059
60