blob: d3e601077142c1aaed8da4b92cde157de9f86c46 [file] [log] [blame]
Scott Baker5a963142016-03-06 16:50:25 -08001from django.db import models
2from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber, NetworkParameter, NetworkParameterType, Port, AddressPool
3from 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
9from core.models import Tag
10from core.models.service import LeastLoadedNodeScheduler
11from services.cord.models import CordSubscriberRoot
12import traceback
13from xos.exceptions import *
14from xos.config import Config
15
16class ConfigurationError(Exception):
17 pass
18
19VTR_KIND = "vTR"
20
21CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False)
22
23# -------------------------------------------
24# VOLT
25# -------------------------------------------
26
27class VTRService(Service):
28 KIND = VTR_KIND
29
30 class Meta:
31 app_label = "vtr"
32 verbose_name = "vTR Service"
33 proxy = True
34
35class 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") )
Scott Bakeredb93f42016-03-07 14:44:22 -080042 SCOPE_CHOICES = ( ("container", "Container"), ("vm", "VM") )
Scott Baker5a963142016-03-06 16:50:25 -080043
44 simple_attributes = ( ("test", None),
45 ("argument", None),
Scott Baker27662d52016-03-06 22:13:39 -080046 ("result", None),
Scott Bakeredb93f42016-03-07 14:44:22 -080047 ("target_id", None),
48 ("scope", "container") )
Scott Baker5a963142016-03-06 16:50:25 -080049
Scott Bakeredb93f42016-03-07 14:44:22 -080050 sync_attributes = ( 'test', 'argument', "scope" )
Scott Baker5a963142016-03-06 16:50:25 -080051
52 def __init__(self, *args, **kwargs):
53 vtr_services = VTRService.get_service_objects().all()
54 if vtr_services:
55 self._meta.get_field("provider_service").default = vtr_services[0].id
56 super(VTRTenant, self).__init__(*args, **kwargs)
57
58 @property
59 def target(self):
60 if getattr(self, "cached_target", None):
61 return self.cached_target
Scott Baker27662d52016-03-06 22:13:39 -080062 target_id=self.target_id
Scott Baker5a963142016-03-06 16:50:25 -080063 if not target_id:
64 return None
65 users=CordSubscriberRoot.objects.filter(id=target_id)
66 if not users:
67 return None
68 user=users[0]
69 self.cached_target = users[0]
70 return user
71
72 @target.setter
73 def target(self, value):
74 if value:
75 value = value.id
76 if (value != self.get_attribute("target_id", None)):
77 self.cached_target=None
Scott Baker27662d52016-03-06 22:13:39 -080078 self.target_id = value
Scott Baker5a963142016-03-06 16:50:25 -080079
80 def save(self, *args, **kwargs):
81 super(VTRTenant, self).save(*args, **kwargs)
82
83 def delete(self, *args, **kwargs):
84 super(VTRTenant, self).delete(*args, **kwargs)
85
86
87VTRTenant.setup_simple_attributes()
88