blob: 53b0d0ef5c66fc3736e39e3eacac0923bb6362a3 [file] [log] [blame]
Gabe Black90623222017-01-18 19:52:28 +00001# models.py - ExampleService Models
2
3from core.models import Service, TenantWithContainer
4from django.db import models, transaction
5
6PASSIVETEST_KIND = 'PassiveTest'
7PASSIVETEST_SERVICE_NAME = 'passivetest'
8PASSIVETEST_SERVICE_NAME_VERBOSE = 'PASSIVETEST Service'
9PASSIVETEST_SERVICE_NAME_VERBOSE_PLURAL = 'PASSIVETEST Services'
10PASSIVETEST_TENANT_NAME_VERBOSE = 'PASSIVETEST Tenant'
11PASSIVETEST_TENANT_NAME_VERBOSE_PLURAL = 'PASSIVETEST Tenants'
12
13class PassiveTestService(Service):
14
15 KIND = PASSIVETEST_KIND
16
17 class Meta:
18 app_label = PASSIVETEST_SERVICE_NAME
19 verbose_name = PASSIVETEST_SERVICE_NAME_VERBOSE
20
21 tap_ports = models.CharField(max_length=254, help_text="Neutron Port ids of the ports we want to tap (comma delimited)")
22 reset_viv = models.BooleanField(default=False, help_text="Reset the VIV's input and output configurations!")
23
24
25class PassiveTestTenant(TenantWithContainer):
26
27 KIND = PASSIVETEST_KIND
28
29 class Meta:
30 verbose_name = PASSIVETEST_TENANT_NAME_VERBOSE
31
32 def __init__(self, *args, **kwargs):
33 passivetestservice = PassiveTestService.get_service_objects().all()
34 if passivetestservice:
35 self._meta.get_field('provider_service').default = passivetestservice[0].id
36 super(PassiveTestTenant, self).__init__(*args, **kwargs)
37
38 def save(self, *args, **kwargs):
39 super(PassiveTestTenant, self).save(*args, **kwargs)
40 model_policy_passivetesttenant(self.pk)
41
42 def delete(self, *args, **kwargs):
43 self.cleanup_container()
44 super(PassiveTestTenant, self).delete(*args, **kwargs)
45
46 @property
47 def public_ip(self):
48 for port in self.instance.ports.all():
49 if "public" in port.network.name.lower():
50 return port.ip
51 return None
52
53 @property
54 def synchronizer_ip(self):
55 for port in self.instance.ports.all():
56 if "management" in port.network.name.lower():
57 return port.ip
58 return None
59
60def model_policy_passivetesttenant(pk):
61 with transaction.atomic():
62 tenant = PassiveTestTenant.objects.select_for_update().filter(pk=pk)
63 if not tenant:
64 return
65 tenant = tenant[0]
66 tenant.manage_container()
67