blob: abec34a5e6bbdfa47acf8f4273bf0e2b125852da [file] [log] [blame]
Scott Baker7a327592016-06-20 17:34:06 -07001from django.db import models
Scott Baker755ff632017-03-20 19:16:02 -07002from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor
Scott Baker7a327592016-06-20 17:34:06 -07003from 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 install_dependencies = models.TextField(null=True, blank=True)
35 dependencies = models.TextField(null=True, blank=True)
36
37 # why is this necessary?
38 creator = models.ForeignKey(User, related_name='onos_apps', blank=True, null=True)
39
Scott Baker7a327592016-06-20 17:34:06 -070040 def __init__(self, *args, **kwargs):
41 onos_services = ONOSService.get_service_objects().all()
42 if onos_services:
43 self._meta.get_field("provider_service").default = onos_services[0].id
44 super(ONOSApp, self).__init__(*args, **kwargs)
45
Scott Baker7a327592016-06-20 17:34:06 -070046 def save(self, *args, **kwargs):
47 if not self.creator:
48 if not getattr(self, "caller", None):
49 # caller must be set when creating a vCPE since it creates a slice
50 raise XOSProgrammingError("ONOSApp's self.caller was not set")
51 self.creator = self.caller
52 if not self.creator:
53 raise XOSProgrammingError("ONOSApp's self.creator was not set")
54
55 super(ONOSApp, self).save(*args, **kwargs)
Scott Baker7a327592016-06-20 17:34:06 -070056
Scott Baker88b71092017-03-13 15:15:29 -070057
Scott Baker7a327592016-06-20 17:34:06 -070058
59