move all 3.0 files to 4.1 as the first step
Change-Id: Iab7810a02bfdf25bffca4e144fcae994f72e0048
diff --git a/xos/models.py b/xos/models.py
index bba7aac..7acdc6e 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,69 +12,85 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from core.models.plcorebase import *
+from models_decl import VMMEService_decl
+from models_decl import VMMEVendor_decl
+from models_decl import VMMETenant_decl
-# models.py - ExampleService Models
-
-from core.models import Service, TenantWithContainer, Image
+from django.db import models
+from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool
+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 xos.config import Config
+class VMMEService(VMMEService_decl):
+ class Meta:
+ proxy = True
-MCORD_KIND = "EPC" #added from vBBU
+ def create_tenant(self, **kwargs):
+ t = VMMETenant(kind="vEPC", provider_service=self, connect_method="na", **kwargs)
+ t.save()
+ return t
-#these macros are currently not used, names hard-coded manually
-SERVICE_NAME = 'vmme'
-SERVICE_NAME_VERBOSE = 'VMME Service'
-SERVICE_NAME_VERBOSE_PLURAL = 'VMME Services'
-TENANT_NAME_VERBOSE = 'VMME Service Tenant'
-TENANT_NAME_VERBOSE_PLURAL = 'VMME Service Tenants'
+class VMMEVendor(VMMEVendor_decl):
+ class Meta:
+ proxy = True
-class VMMEService(Service):
+class VMMETenant(VMMETenant_decl):
+ class Meta:
+ proxy = True
- KIND = MCORD_KIND
+ def __init__(self, *args, **kwargs):
+ vmmeservices = VMMEService.get_service_objects().all()
+ if vmmeservices:
+ self._meta.get_field("provider_service").default = vmmeservices[0].id
+ super(VMMETenant, self).__init__(*args, **kwargs)
- class Meta:
- proxy = True
- app_label = "vmme"
- verbose_name = "VMME Service"
+ @property
+ def image(self):
+ if not self.vmme_vendor:
+ return super(VMMETenant, self).image
+ return self.vmme_vendor.image
+
+ def save_instance(self, instance):
+ if self.vmme_vendor:
+ instance.flavor = self.vmme_vendor.flavor
+ super(VMMETenant, self).save_instance(instance)
-class VMMETenant(TenantWithContainer):
+ def save(self, *args, **kwargs):
+ if not self.creator:
+ if not getattr(self, "caller", None):
+ raise XOSProgrammingError("VMMETenant's self.caller was not set")
+ self.creator = self.caller
+ if not self.creator:
+ raise XOSProgrammingError("VMMETenant's self.creator was not set")
- KIND = 'vmme'
- class Meta:
- verbose_name = "VMME Service Tenant"
+ super(VMMETenant, self).save(*args, **kwargs)
+ # This call needs to happen so that an instance is created for this
+ # tenant is created in the slice. One instance is created per tenant.
+ model_policy_vmmetenant(self.pk)
- tenant_message = models.CharField(max_length=254, help_text="vMME message")
- image_name = models.CharField(max_length=254, help_text="Name of VM image")
-
- def __init__(self, *args, **kwargs):
- vmme_services = VMMEService.get_service_objects().all()
- if vmme_services:
- self._meta.get_field('provider_service').default = vmme_services[0].id
- super(VMMETenant, self).__init__(*args, **kwargs)
-
- def save(self, *args, **kwargs):
- super(VMMETenant, self).save(*args, **kwargs)
- model_policy_vmmetenant(self.pk) #defined below
-
- def delete(self, *args, **kwargs):
- self.cleanup_container()
- super(VMMETenant, self).delete(*args, **kwargs)
-
- @property
- def image(self):
- img = self.image_name.strip()
- if img.lower() != "default":
- return Image.objects.get(name=img)
- else:
- return super(VMMETenant, self).image
-
-
+ def delete(self, *args, **kwargs):
+ # Delete the instance that was created for this tenant
+ self.cleanup_container()
+ super(VMMETenant, self).delete(*args, **kwargs)
def model_policy_vmmetenant(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 = VMMETenant.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()