Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 1 | from django.db import models |
| 2 | from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber |
| 3 | from core.models.plcorebase import StrippedCharField |
| 4 | import os |
| 5 | from django.db import models, transaction |
| 6 | from django.forms.models import model_to_dict |
| 7 | from django.db.models import Q |
| 8 | from operator import itemgetter, attrgetter, methodcaller |
| 9 | import traceback |
| 10 | from xos.exceptions import * |
| 11 | from core.models import SlicePrivilege, SitePrivilege |
| 12 | from sets import Set |
| 13 | |
| 14 | ONOS_KIND = "onos" |
| 15 | |
| 16 | class ONOSService(Service): |
| 17 | KIND = ONOS_KIND |
| 18 | |
| 19 | class Meta: |
| 20 | app_label = "onos" |
| 21 | verbose_name = "ONOS Service" |
Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 22 | |
Scott Baker | 88b7109 | 2017-03-13 15:15:29 -0700 | [diff] [blame^] | 23 | 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 Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 27 | |
| 28 | class ONOSApp(Tenant): # aka 'ONOSTenant' |
| 29 | class Meta: |
Scott Baker | 88b7109 | 2017-03-13 15:15:29 -0700 | [diff] [blame^] | 30 | app_label = "onos" |
Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 31 | |
| 32 | KIND = ONOS_KIND |
| 33 | |
Scott Baker | 88b7109 | 2017-03-13 15:15:29 -0700 | [diff] [blame^] | 34 | 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 Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 41 | 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 Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 47 | 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 Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 57 | |
Scott Baker | 88b7109 | 2017-03-13 15:15:29 -0700 | [diff] [blame^] | 58 | |
Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 59 | |
| 60 | |