Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 1 | from django.db import models |
Scott Baker | 755ff63 | 2017-03-20 19:16:02 -0700 | [diff] [blame] | 2 | from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor |
Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 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 | 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 Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 40 | 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 Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 46 | 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 Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 56 | |
Scott Baker | 88b7109 | 2017-03-13 15:15:29 -0700 | [diff] [blame] | 57 | |
Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 58 | |
| 59 | |