blob: ce2e3459fa24f9354d529259c6830c9c0c38e6bc [file] [log] [blame]
Scott Baker171d35e2016-06-20 17:36:29 -07001from 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.volt.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") )
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
88VTRTenant.setup_simple_attributes()
89