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 |
| 15 | |
| 16 | class ConfigurationError(Exception): |
| 17 | pass |
| 18 | |
| 19 | VTR_KIND = "vTR" |
| 20 | |
| 21 | CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False) |
| 22 | |
| 23 | # ------------------------------------------- |
| 24 | # VOLT |
| 25 | # ------------------------------------------- |
| 26 | |
| 27 | class VTRService(Service): |
| 28 | KIND = VTR_KIND |
| 29 | |
| 30 | class Meta: |
| 31 | app_label = "vtr" |
| 32 | verbose_name = "vTR Service" |
| 33 | proxy = True |
| 34 | |
| 35 | class VTRTenant(Tenant): |
| 36 | class Meta: |
| 37 | proxy = True |
| 38 | |
| 39 | KIND = VTR_KIND |
| 40 | |
| 41 | TEST_CHOICES = ( ("ping", "Ping"), ("traceroute", "Trace Route"), ("tcpdump", "Tcp Dump") ) |
| 42 | SCOPE_CHOICES = ( ("container", "Container"), ("vm", "VM") ) |
| 43 | |
| 44 | simple_attributes = ( ("test", None), |
| 45 | ("argument", None), |
| 46 | ("result", None), |
| 47 | ("result_code", None), |
| 48 | ("target_id", None), |
| 49 | ("scope", "container") ) |
| 50 | |
| 51 | sync_attributes = ( 'test', 'argument', "scope" ) |
| 52 | |
| 53 | def __init__(self, *args, **kwargs): |
| 54 | vtr_services = VTRService.get_service_objects().all() |
| 55 | if vtr_services: |
| 56 | self._meta.get_field("provider_service").default = vtr_services[0].id |
| 57 | super(VTRTenant, self).__init__(*args, **kwargs) |
| 58 | |
| 59 | @property |
| 60 | def target(self): |
| 61 | if getattr(self, "cached_target", None): |
| 62 | return self.cached_target |
| 63 | target_id=self.target_id |
| 64 | if not target_id: |
| 65 | return None |
| 66 | users=CordSubscriberRoot.objects.filter(id=target_id) |
| 67 | if not users: |
| 68 | return None |
| 69 | user=users[0] |
| 70 | self.cached_target = users[0] |
| 71 | return user |
| 72 | |
| 73 | @target.setter |
| 74 | def target(self, value): |
| 75 | if value: |
| 76 | value = value.id |
| 77 | if (value != self.get_attribute("target_id", None)): |
| 78 | self.cached_target=None |
| 79 | self.target_id = value |
| 80 | |
| 81 | def save(self, *args, **kwargs): |
| 82 | super(VTRTenant, self).save(*args, **kwargs) |
| 83 | |
| 84 | def delete(self, *args, **kwargs): |
| 85 | super(VTRTenant, self).delete(*args, **kwargs) |
| 86 | |
| 87 | |
| 88 | VTRTenant.setup_simple_attributes() |
| 89 | |