| from core.models.plcorebase import * |
| from models_decl import VPGWUService_decl |
| from models_decl import VPGWUTenant_decl |
| |
| from django.db import models |
| from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool, SlicePrivilege, SitePrivilege |
| from core.models.plcorebase import StrippedCharField |
| import os |
| from django.db import models, transaction |
| from django.forms.models import model_to_dict |
| from django.db.models import * |
| from operator import itemgetter, attrgetter, methodcaller |
| from core.models import Tag |
| from core.models.service import LeastLoadedNodeScheduler |
| import traceback |
| from xos.exceptions import * |
| from sets import Set |
| from xos.config import Config |
| from django.contrib.contenttypes.models import ContentType |
| from django.contrib.contenttypes.fields import GenericForeignKey |
| |
| class VPGWUService(VPGWUService_decl): |
| class Meta: |
| proxy = True |
| |
| class VPGWUTenant(VPGWUTenant_decl): |
| class Meta: |
| proxy = True |
| |
| def __init__(self, *args, **kwargs): |
| vpgwuservice = VPGWUService.get_service_objects().all() |
| # When the tenant is created the default service in the form is set |
| # to be the first created HelloWorldServiceComplete |
| if vpgwuservice: |
| self._meta.get_field( |
| "provider_service").default = vpgwuservice[0].id |
| super(VPGWUTenant, self).__init__(*args, **kwargs) |
| |
| def save(self, *args, **kwargs): |
| # Update the instance that was created for this tenant |
| super(VPGWUTenant, self).save(*args, **kwargs) |
| model_policy_vpgwutenant(self.pk) |
| |
| def delete(self, *args, **kwargs): |
| # Delete the instance that was created for this tenant |
| self.cleanup_container() |
| super(VPGWUTenant, self).delete(*args, **kwargs) |
| |
| def model_policy_vpgwutenant(pk): |
| # This section of code is atomic to prevent race conditions |
| with transaction.atomic(): |
| # We find all of the tenants that are waiting to update |
| tenant = VPGWUTenant.objects.select_for_update().filter(pk=pk) |
| if not tenant: |
| return |
| # Since this code is atomic it is safe to always use the first tenant |
| tenant = tenant[0] |
| tenant.manage_container() |