CORD-879 eliminate proxy models in vtr service
Change-Id: Iab26025c87b18c26c83b5857138a17fc3b04b10d
diff --git a/xos/models.py b/xos/models.py
index ce2e345..f3f9f2b 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -12,6 +12,8 @@
import traceback
from xos.exceptions import *
from xos.config import Config
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.contenttypes.fields import GenericForeignKey
class ConfigurationError(Exception):
pass
@@ -29,24 +31,24 @@
class Meta:
app_label = "vtr"
- verbose_name = "vTR Service"
- proxy = True
class VTRTenant(Tenant):
- class Meta:
- proxy = True
-
KIND = VTR_KIND
+ class Meta:
+ app_label = "vtr"
+
TEST_CHOICES = ( ("ping", "Ping"), ("traceroute", "Trace Route"), ("tcpdump", "Tcp Dump") )
SCOPE_CHOICES = ( ("container", "Container"), ("vm", "VM") )
- simple_attributes = ( ("test", None),
- ("argument", None),
- ("result", None),
- ("result_code", None),
- ("target_id", None),
- ("scope", "container") )
+ test = StrippedCharField(help_text="type of test", max_length=30, choices=TEST_CHOICES, null=False, blank=False)
+ scope = StrippedCharField(help_text="scope of test", max_length=30, choices=SCOPE_CHOICES, null=False, blank=False)
+ argument = StrippedCharField(max_length=40, null=True, blank=True)
+ result = models.TextField(blank=True, null=True)
+ result_code = StrippedCharField(max_length=32, blank=True, null=True)
+ target_type = models.ForeignKey(ContentType)
+ target_id = models.PositiveIntegerField()
+ target = GenericForeignKey("target_type", "target_id")
sync_attributes = ( 'test', 'argument', "scope" )
@@ -56,34 +58,9 @@
self._meta.get_field("provider_service").default = vtr_services[0].id
super(VTRTenant, self).__init__(*args, **kwargs)
- @property
- def target(self):
- if getattr(self, "cached_target", None):
- return self.cached_target
- target_id=self.target_id
- if not target_id:
- return None
- users=CordSubscriberRoot.objects.filter(id=target_id)
- if not users:
- return None
- user=users[0]
- self.cached_target = users[0]
- return user
-
- @target.setter
- def target(self, value):
- if value:
- value = value.id
- if (value != self.get_attribute("target_id", None)):
- self.cached_target=None
- self.target_id = value
-
def save(self, *args, **kwargs):
super(VTRTenant, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
super(VTRTenant, self).delete(*args, **kwargs)
-
-VTRTenant.setup_simple_attributes()
-