blob: 53b0d0ef5c66fc3736e39e3eacac0923bb6362a3 [file] [log] [blame]
# models.py - ExampleService Models
from core.models import Service, TenantWithContainer
from django.db import models, transaction
PASSIVETEST_KIND = 'PassiveTest'
PASSIVETEST_SERVICE_NAME = 'passivetest'
PASSIVETEST_SERVICE_NAME_VERBOSE = 'PASSIVETEST Service'
PASSIVETEST_SERVICE_NAME_VERBOSE_PLURAL = 'PASSIVETEST Services'
PASSIVETEST_TENANT_NAME_VERBOSE = 'PASSIVETEST Tenant'
PASSIVETEST_TENANT_NAME_VERBOSE_PLURAL = 'PASSIVETEST Tenants'
class PassiveTestService(Service):
KIND = PASSIVETEST_KIND
class Meta:
app_label = PASSIVETEST_SERVICE_NAME
verbose_name = PASSIVETEST_SERVICE_NAME_VERBOSE
tap_ports = models.CharField(max_length=254, help_text="Neutron Port ids of the ports we want to tap (comma delimited)")
reset_viv = models.BooleanField(default=False, help_text="Reset the VIV's input and output configurations!")
class PassiveTestTenant(TenantWithContainer):
KIND = PASSIVETEST_KIND
class Meta:
verbose_name = PASSIVETEST_TENANT_NAME_VERBOSE
def __init__(self, *args, **kwargs):
passivetestservice = PassiveTestService.get_service_objects().all()
if passivetestservice:
self._meta.get_field('provider_service').default = passivetestservice[0].id
super(PassiveTestTenant, self).__init__(*args, **kwargs)
def save(self, *args, **kwargs):
super(PassiveTestTenant, self).save(*args, **kwargs)
model_policy_passivetesttenant(self.pk)
def delete(self, *args, **kwargs):
self.cleanup_container()
super(PassiveTestTenant, self).delete(*args, **kwargs)
@property
def public_ip(self):
for port in self.instance.ports.all():
if "public" in port.network.name.lower():
return port.ip
return None
@property
def synchronizer_ip(self):
for port in self.instance.ports.all():
if "management" in port.network.name.lower():
return port.ip
return None
def model_policy_passivetesttenant(pk):
with transaction.atomic():
tenant = PassiveTestTenant.objects.select_for_update().filter(pk=pk)
if not tenant:
return
tenant = tenant[0]
tenant.manage_container()