Scott Baker | 171d35e | 2016-06-20 17:36:29 -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, NetworkParameter, NetworkParameterType, Port, AddressPool |
| 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 | from core.models import Tag |
| 10 | from core.models.service import LeastLoadedNodeScheduler |
| 11 | from services.volt.models import CordSubscriberRoot |
| 12 | import traceback |
| 13 | from xos.exceptions import * |
| 14 | from xos.config import Config |
Scott Baker | 5db44a9 | 2017-03-06 17:27:52 -0800 | [diff] [blame^] | 15 | from django.contrib.contenttypes.models import ContentType |
| 16 | from django.contrib.contenttypes.fields import GenericForeignKey |
Scott Baker | 171d35e | 2016-06-20 17:36:29 -0700 | [diff] [blame] | 17 | |
| 18 | class ConfigurationError(Exception): |
| 19 | pass |
| 20 | |
| 21 | VTR_KIND = "vTR" |
| 22 | |
| 23 | CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False) |
| 24 | |
| 25 | # ------------------------------------------- |
| 26 | # VOLT |
| 27 | # ------------------------------------------- |
| 28 | |
| 29 | class VTRService(Service): |
| 30 | KIND = VTR_KIND |
| 31 | |
| 32 | class Meta: |
| 33 | app_label = "vtr" |
Scott Baker | 171d35e | 2016-06-20 17:36:29 -0700 | [diff] [blame] | 34 | |
| 35 | class VTRTenant(Tenant): |
Scott Baker | 171d35e | 2016-06-20 17:36:29 -0700 | [diff] [blame] | 36 | KIND = VTR_KIND |
| 37 | |
Scott Baker | 5db44a9 | 2017-03-06 17:27:52 -0800 | [diff] [blame^] | 38 | class Meta: |
| 39 | app_label = "vtr" |
| 40 | |
Scott Baker | 171d35e | 2016-06-20 17:36:29 -0700 | [diff] [blame] | 41 | TEST_CHOICES = ( ("ping", "Ping"), ("traceroute", "Trace Route"), ("tcpdump", "Tcp Dump") ) |
| 42 | SCOPE_CHOICES = ( ("container", "Container"), ("vm", "VM") ) |
| 43 | |
Scott Baker | 5db44a9 | 2017-03-06 17:27:52 -0800 | [diff] [blame^] | 44 | test = StrippedCharField(help_text="type of test", max_length=30, choices=TEST_CHOICES, null=False, blank=False) |
| 45 | scope = StrippedCharField(help_text="scope of test", max_length=30, choices=SCOPE_CHOICES, null=False, blank=False) |
| 46 | argument = StrippedCharField(max_length=40, null=True, blank=True) |
| 47 | result = models.TextField(blank=True, null=True) |
| 48 | result_code = StrippedCharField(max_length=32, blank=True, null=True) |
| 49 | target_type = models.ForeignKey(ContentType) |
| 50 | target_id = models.PositiveIntegerField() |
| 51 | target = GenericForeignKey("target_type", "target_id") |
Scott Baker | 171d35e | 2016-06-20 17:36:29 -0700 | [diff] [blame] | 52 | |
| 53 | sync_attributes = ( 'test', 'argument', "scope" ) |
| 54 | |
| 55 | def __init__(self, *args, **kwargs): |
| 56 | vtr_services = VTRService.get_service_objects().all() |
| 57 | if vtr_services: |
| 58 | self._meta.get_field("provider_service").default = vtr_services[0].id |
| 59 | super(VTRTenant, self).__init__(*args, **kwargs) |
| 60 | |
Scott Baker | 171d35e | 2016-06-20 17:36:29 -0700 | [diff] [blame] | 61 | def save(self, *args, **kwargs): |
| 62 | super(VTRTenant, self).save(*args, **kwargs) |
| 63 | |
| 64 | def delete(self, *args, **kwargs): |
| 65 | super(VTRTenant, self).delete(*args, **kwargs) |
| 66 | |