CORD-1345: Rename PlCoreBase to XOSBase and generate xosbase through
xproto
Change-Id: I5cffb1ccc1a6a7eaba8c89aeec1c769a7c51f9a0
diff --git a/xos/core/models/addresspool.xproto b/xos/core/models/addresspool.xproto
index 737de26..e00dbb5 100644
--- a/xos/core/models/addresspool.xproto
+++ b/xos/core/models/addresspool.xproto
@@ -1,6 +1,6 @@
-message AddressPool (PlCoreBase){
+message AddressPool (XOSBase){
required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
optional string addresses = 2 [db_index = False, null = True, blank = True];
optional string gateway_ip = 3 [db_index = False, max_length = 32, null = True, blank = False];
diff --git a/xos/core/models/attic/header.py b/xos/core/models/attic/header.py
index 6a19856..300f57f 100644
--- a/xos/core/models/attic/header.py
+++ b/xos/core/models/attic/header.py
@@ -4,7 +4,7 @@
import json
import operator
from operator import attrgetter
-from core.models.plcorebase import *
+from core.models.xosbase import *
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.utils.timezone import now
@@ -97,5 +97,3 @@
return flavor
return flavors[0]
-
-
diff --git a/xos/core/models/attic/service_header.py b/xos/core/models/attic/service_header.py
index 04e7353..09019b8 100644
--- a/xos/core/models/attic/service_header.py
+++ b/xos/core/models/attic/service_header.py
@@ -1,7 +1,7 @@
from __future__ import absolute_import
from core.models.xos import XOS
-from core.models.plcorebase import *
+from core.models.xosbase import *
from django.core.validators import URLValidator
import urlparse
from operator import attrgetter
diff --git a/xos/core/models/attic/xosbase_header.py b/xos/core/models/attic/xosbase_header.py
new file mode 100644
index 0000000..d67b56a
--- /dev/null
+++ b/xos/core/models/attic/xosbase_header.py
@@ -0,0 +1,272 @@
+import datetime
+import json
+import pytz
+import inspect
+import sys
+import threading
+from django.db import models
+from django.utils.timezone import now
+from django.db.models import *
+from django.db import transaction
+from django.forms.models import model_to_dict
+from django.utils import timezone
+from django.core.exceptions import PermissionDenied
+from cgi import escape as html_escape
+from journal import journal_object
+from django.db.models.deletion import Collector
+from django.db import router
+from django.contrib.contenttypes.models import ContentType
+
+import redis
+from redis import ConnectionError
+
+def date_handler(obj):
+ if isinstance(obj, pytz.tzfile.DstTzInfo):
+ # json can't serialize DstTzInfo
+ return str(obj)
+ return obj.isoformat() if hasattr(obj, 'isoformat') else obj
+
+try:
+ # This is a no-op if observer_disabled is set to 1 in the config file
+ from synchronizers.base import *
+except:
+ print >> sys.stderr, "import of observer failed! printing traceback and disabling observer:"
+ import traceback
+ traceback.print_exc()
+
+ # guard against something failing
+ def notify_observer(*args, **kwargs):
+ pass
+
+class StrippedCharField(models.CharField):
+ """ CharField that strips trailing and leading spaces."""
+ def clean(self, value, *args, **kwds):
+ if value is not None:
+ value = value.strip()
+ return super(StrippedCharField, self).clean(value, *args, **kwds)
+
+
+# This manager will be inherited by all subclasses because
+# the core model is abstract.
+class XOSBaseDeletionManager(models.Manager):
+ def get_queryset(self):
+ parent=super(XOSBaseDeletionManager, self)
+ if hasattr(parent, "get_queryset"):
+ return parent.get_queryset().filter(deleted=True)
+ else:
+ return parent.get_query_set().filter(deleted=True)
+
+ # deprecated in django 1.7 in favor of get_queryset().
+ def get_query_set(self):
+ return self.get_queryset()
+
+# This manager will be inherited by all subclasses because
+# the core model is abstract.
+class XOSBaseManager(models.Manager):
+ def get_queryset(self):
+ parent=super(XOSBaseManager, self)
+ if hasattr(parent, "get_queryset"):
+ return parent.get_queryset().filter(deleted=False)
+ else:
+ return parent.get_query_set().filter(deleted=False)
+
+ # deprecated in django 1.7 in favor of get_queryset().
+ def get_query_set(self):
+ return self.get_queryset()
+
+class PlModelMixIn(object):
+ # Provides useful methods for computing which objects in a model have
+ # changed. Make sure to do self._initial = self._dict in the __init__
+ # method.
+
+ # Also includes useful utility, like getValidators
+
+ # This is broken out of XOSBase into a Mixin so the User model can
+ # also make use of it.
+
+ @property
+ def _dict(self):
+ return model_to_dict(self, fields=[field.name for field in
+ self._meta.fields])
+
+ def fields_differ(self,f1,f2):
+ if isinstance(f1,datetime.datetime) and isinstance(f2,datetime.datetime) and (timezone.is_aware(f1) != timezone.is_aware(f2)):
+ return True
+ else:
+ return (f1 != f2)
+
+ @property
+ def diff(self):
+ d1 = self._initial
+ d2 = self._dict
+ diffs = [(k, (v, d2[k])) for k, v in d1.items() if self.fields_differ(v,d2[k])]
+ return dict(diffs)
+
+ @property
+ def has_changed(self):
+ return bool(self.diff)
+
+ @property
+ def changed_fields(self):
+ return self.diff.keys()
+
+ def has_field_changed(self, field_name):
+ return field_name in self.diff.keys()
+
+ def get_field_diff(self, field_name):
+ return self.diff.get(field_name, None)
+
+ #classmethod
+ def getValidators(cls):
+ """ primarily for REST API, return a dictionary of field names mapped
+ to lists of the type of validations that need to be applied to
+ those fields.
+ """
+ validators = {}
+ for field in cls._meta.fields:
+ l = []
+ if field.blank==False:
+ l.append("notBlank")
+ if field.__class__.__name__=="URLField":
+ l.append("url")
+ validators[field.name] = l
+ return validators
+
+ def get_backend_register(self, k, default=None):
+ try:
+ return json.loads(self.backend_register).get(k, default)
+ except AttributeError:
+ return default
+
+ def set_backend_register(self, k, v):
+ br = {}
+ try:
+ br=json.loads(self.backend_register)
+ except AttributeError:
+ br={}
+
+ br[k] = v
+ self.backend_register = json.dumps(br)
+
+ def get_backend_details(self):
+ try:
+ scratchpad = json.loads(self.backend_register)
+ except AttributeError:
+ return (None, None, None, None)
+
+ try:
+ exponent = scratchpad['exponent']
+ except KeyError:
+ exponent = None
+
+ try:
+ last_success_time = scratchpad['last_success']
+ dt = datetime.datetime.fromtimestamp(last_success_time)
+ last_success = dt.strftime("%Y-%m-%d %H:%M")
+ except KeyError:
+ last_success = None
+
+ try:
+ failures = scratchpad['failures']
+ except KeyError:
+ failures=None
+
+ try:
+ last_failure_time = scratchpad['last_failure']
+ dt = datetime.datetime.fromtimestamp(last_failure_time)
+ last_failure = dt.strftime("%Y-%m-%d %H:%M")
+ except KeyError:
+ last_failure = None
+
+ return (exponent, last_success, last_failure, failures)
+
+ def get_backend_icon(self):
+ is_perfect = (self.backend_status is not None) and self.backend_status.startswith("1 -")
+ is_good = (self.backend_status is not None) and (self.backend_status.startswith("0 -") or self.backend_status.startswith("1 -"))
+ is_provisioning = self.backend_status is None or self.backend_status == "Provisioning in progress" or self.backend_status==""
+
+ # returns (icon_name, tooltip)
+ if (self.enacted is not None) and (self.enacted >= self.updated and is_good) or is_perfect:
+ return ("success", "successfully enacted")
+ else:
+ if is_good or is_provisioning:
+ return ("clock", "Pending sync, last_status = " + html_escape(self.backend_status, quote=True))
+ else:
+ return ("error", html_escape(self.backend_status, quote=True))
+
+ def enforce_choices(self, field, choices):
+ choices = [x[0] for x in choices]
+ for choice in choices:
+ if field==choice:
+ return
+ if (choice==None) and (field==""):
+ # allow "" and None to be equivalent
+ return
+ raise Exception("Field value %s is not in %s" % (field, str(choices)))
+
+ def serialize_for_redis(self):
+ """ Serialize the object for posting to redis.
+
+ The API serializes ForeignKey fields by naming them <name>_id
+ whereas model_to_dict leaves them with the original name. Modify
+ the results of model_to_dict to provide the same fieldnames.
+ """
+
+ field_types = {}
+ for f in self._meta.fields:
+ field_types[f.name] = f.get_internal_type()
+
+ fields = model_to_dict(self)
+ for k in fields.keys():
+ if field_types.get(k,None) == "ForeignKey":
+ new_key_name = "%s_id" % k
+ if (k in fields) and (new_key_name not in fields):
+ fields[new_key_name] = fields[k]
+ del fields[k]
+
+ return fields
+
+ def push_redis_event(self):
+ # Transmit update via Redis
+ changed_fields = []
+
+ if self.pk is not None:
+ my_model = type(self)
+ try:
+ orig = my_model.objects.get(pk=self.pk)
+
+ for f in my_model._meta.fields:
+ oval = getattr(orig, f.name)
+ nval = getattr(self, f.name)
+ if oval != nval:
+ changed_fields.append(f.name)
+ except:
+ changed_fields.append('__lookup_error')
+
+ try:
+ r = redis.Redis("redis")
+ # NOTE the redis event has been extended with model properties to facilitate the support of real time notification in the UI
+ # keep this monitored for performance reasons and eventually revert it back to fetch model properties via the REST API
+ model = self.serialize_for_redis()
+ bases = inspect.getmro(self.__class__)
+ # bases = [x for x in bases if issubclass(x, XOSBase)]
+ class_names = ",".join([x.__name__ for x in bases])
+ model['class_names'] = class_names
+ payload = json.dumps({'pk': self.pk, 'changed_fields': changed_fields, 'object': model}, default=date_handler)
+ r.publish(self.__class__.__name__, payload)
+ except ConnectionError:
+ # Redis not running.
+ pass
+
+# For cascading deletes, we need a Collector that doesn't do fastdelete,
+# so we get a full list of models.
+class XOSCollector(Collector):
+ def can_fast_delete(self, *args, **kwargs):
+ return False
+
+class ModelLink:
+ def __init__(self,dest,via,into=None):
+ self.dest=dest
+ self.via=via
+ self.into=into
+
diff --git a/xos/core/models/attic/xosbase_model.py b/xos/core/models/attic/xosbase_model.py
new file mode 100644
index 0000000..094c466
--- /dev/null
+++ b/xos/core/models/attic/xosbase_model.py
@@ -0,0 +1,148 @@
+objects = XOSBaseManager()
+deleted_objects = XOSBaseDeletionManager()
+
+class Meta:
+ # Changing abstract to False would require the managers of subclasses of
+ # XOSBase to be customized individually.
+ abstract = True
+ app_label = "core"
+
+def __init__(self, *args, **kwargs):
+ super(XOSBase, self).__init__(*args, **kwargs)
+ self._initial = self._dict # for PlModelMixIn
+ self.silent = False
+
+def get_controller(self):
+ return self.controller
+
+def can_update(self, user):
+ return user.can_update_root()
+
+def delete(self, *args, **kwds):
+ # so we have something to give the observer
+ purge = kwds.get('purge',False)
+ if purge:
+ del kwds['purge']
+ silent = kwds.get('silent',False)
+ if silent:
+ del kwds['silent']
+ try:
+ purge = purge or observer_disabled
+ except NameError:
+ pass
+
+ if (purge):
+ journal_object(self, "delete.purge")
+ super(XOSBase, self).delete(*args, **kwds)
+ else:
+ if (not self.write_protect ):
+ self.deleted = True
+ self.enacted=None
+ self.policed=None
+ journal_object(self, "delete.mark_deleted")
+ self.save(update_fields=['enacted','deleted','policed'], silent=silent)
+
+ collector = XOSCollector(using=router.db_for_write(self.__class__, instance=self))
+ collector.collect([self])
+ with transaction.atomic():
+ for (k, models) in collector.data.items():
+ for model in models:
+ if model.deleted:
+ # in case it's already been deleted, don't delete again
+ continue
+ model.deleted = True
+ model.enacted=None
+ model.policed=None
+ journal_object(model, "delete.cascade.mark_deleted", msg="root = %r" % self)
+ model.save(update_fields=['enacted','deleted','policed'], silent=silent)
+
+def save(self, *args, **kwargs):
+ journal_object(self, "xosbase.save")
+
+ # let the user specify silence as either a kwarg or an instance varible
+ silent = self.silent
+ if "silent" in kwargs:
+ silent=silent or kwargs.pop("silent")
+
+ caller_kind = "unknown"
+
+ if ('synchronizer' in threading.current_thread().name):
+ caller_kind = "synchronizer"
+
+ if "caller_kind" in kwargs:
+ caller_kind = kwargs.pop("caller_kind")
+
+ always_update_timestamp = False
+ if "always_update_timestamp" in kwargs:
+ always_update_timestamp = always_update_timestamp or kwargs.pop("always_update_timestamp")
+
+ # SMBAKER: if an object is trying to delete itself, or if the observer
+ # is updating an object's backend_* fields, then let it slip past the
+ # composite key check.
+ ignore_composite_key_check=False
+ if "update_fields" in kwargs:
+ ignore_composite_key_check=True
+ for field in kwargs["update_fields"]:
+ if not (field in ["backend_register", "backend_status", "deleted", "enacted", "updated"]):
+ ignore_composite_key_check=False
+
+ if (caller_kind!="synchronizer") or always_update_timestamp:
+ self.updated = timezone.now()
+
+ journal_object(self, "xosbase.save.super_save")
+
+ super(XOSBase, self).save(*args, **kwargs)
+
+ journal_object(self, "xosbase.save.super_save_returned")
+
+ self.push_redis_event()
+
+ # This is a no-op if observer_disabled is set
+ # if not silent:
+ # notify_observer()
+
+ self._initial = self._dict
+
+def save_by_user(self, user, *args, **kwds):
+ if not self.can_update(user):
+ if getattr(self, "_cant_update_fieldName", None) is not None:
+ raise PermissionDenied("You do not have permission to update field %s on object %s" % (self._cant_update_fieldName, self.__class__.__name__))
+ else:
+ raise PermissionDenied("You do not have permission to update %s objects" % self.__class__.__name__)
+
+ self.save(*args, **kwds)
+
+def delete_by_user(self, user, *args, **kwds):
+ if not self.can_update(user):
+ raise PermissionDenied("You do not have permission to delete %s objects" % self.__class__.__name__)
+ self.delete(*args, **kwds)
+
+@classmethod
+def select_by_user(cls, user):
+ # This should be overridden by descendant classes that want to perform
+ # filtering of visible objects by user.
+ return cls.objects.all()
+
+def tologdict(self):
+ try:
+ d = {'model_name':self.__class__.__name__, 'pk': self.pk}
+ except:
+ d = {}
+
+ return d
+
+def get_content_type_key(self):
+ ct = ContentType.objects.get_for_model(self.__class__)
+ return "%s.%s" % (ct.app_label, ct.model)
+
+@staticmethod
+def get_content_type_from_key(key):
+ (app_name, model_name) = key.split(".")
+ return ContentType.objects.get_by_natural_key(app_name, model_name)
+
+@staticmethod
+def get_content_object(content_type, object_id):
+ ct = XOSBase.get_content_type_from_key(content_type)
+ cls = ct.model_class()
+ return cls.objects.get(id=object_id)
+
diff --git a/xos/core/models/controller.xproto b/xos/core/models/controller.xproto
index da2d1e3..760ccc5 100644
--- a/xos/core/models/controller.xproto
+++ b/xos/core/models/controller.xproto
@@ -1,6 +1,6 @@
-message Controller (PlCoreBase){
+message Controller (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the Controller", null = False, db_index = False];
required string backend_type = 2 [max_length = 200, content_type = "stripped", blank = False, help_text = "Type of compute controller, e.g. EC2, OpenStack, or OpenStack version", null = False, db_index = False];
required string version = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Controller version", null = False, db_index = False];
diff --git a/xos/core/models/controllerdashboardview.xproto b/xos/core/models/controllerdashboardview.xproto
index ed4229c..ff84b95 100644
--- a/xos/core/models/controllerdashboardview.xproto
+++ b/xos/core/models/controllerdashboardview.xproto
@@ -1,6 +1,6 @@
-message ControllerDashboardView (PlCoreBase){
+message ControllerDashboardView (XOSBase){
required manytoone controller->Controller:controllerdashboardviews = 1 [db_index = True, null = False, blank = False];
required manytoone dashboardView->DashboardView:controllerdashboardviews = 2 [db_index = True, null = False, blank = False];
required bool enabled = 3 [default = True, null = False, db_index = False, blank = True];
diff --git a/xos/core/models/controllerimages.xproto b/xos/core/models/controllerimages.xproto
index 38d6237..aae8361 100644
--- a/xos/core/models/controllerimages.xproto
+++ b/xos/core/models/controllerimages.xproto
@@ -1,6 +1,6 @@
-message ControllerImages (PlCoreBase){
+message ControllerImages (XOSBase){
required manytoone image->Image:controllerimages = 1 [db_index = True, null = False, blank = False];
required manytoone controller->Controller:controllerimages = 2 [db_index = True, null = False, blank = False];
optional string glance_image_id = 3 [max_length = 200, content_type = "stripped", blank = True, help_text = "Glance image id", null = True, db_index = False];
diff --git a/xos/core/models/controllernetwork.xproto b/xos/core/models/controllernetwork.xproto
index ba6acec..e6d2ef4 100644
--- a/xos/core/models/controllernetwork.xproto
+++ b/xos/core/models/controllernetwork.xproto
@@ -1,6 +1,6 @@
-message ControllerNetwork (PlCoreBase){
+message ControllerNetwork (XOSBase){
required manytoone network->Network:controllernetworks = 1 [db_index = True, null = False, blank = False];
required manytoone controller->Controller:controllernetworks = 2 [db_index = True, null = False, blank = False];
required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
diff --git a/xos/core/models/controllerrole.xproto b/xos/core/models/controllerrole.xproto
index 4ae4bb2..e2b586c 100644
--- a/xos/core/models/controllerrole.xproto
+++ b/xos/core/models/controllerrole.xproto
@@ -1,5 +1,5 @@
-message ControllerRole (PlCoreBase){
+message ControllerRole (XOSBase){
required string role = 1 [choices = "(('admin', 'Admin'),)", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
}
diff --git a/xos/core/models/controllersite.xproto b/xos/core/models/controllersite.xproto
index 6fb4be8..c092629 100644
--- a/xos/core/models/controllersite.xproto
+++ b/xos/core/models/controllersite.xproto
@@ -1,6 +1,6 @@
-message ControllerSite (PlCoreBase){
+message ControllerSite (XOSBase){
required manytoone site->Site:controllersite = 1 [db_index = True, null = False, blank = False];
optional manytoone controller->Controller:controllersite = 2 [db_index = True, null = True, blank = True];
optional string tenant_id = 3 [max_length = 200, content_type = "stripped", blank = True, help_text = "Keystone tenant id", null = True, db_index = True];
diff --git a/xos/core/models/controllersiteprivilege.xproto b/xos/core/models/controllersiteprivilege.xproto
index ca5ca75..0bfd962 100644
--- a/xos/core/models/controllersiteprivilege.xproto
+++ b/xos/core/models/controllersiteprivilege.xproto
@@ -1,6 +1,6 @@
-message ControllerSitePrivilege (PlCoreBase){
+message ControllerSitePrivilege (XOSBase){
required manytoone controller->Controller:controllersiteprivileges = 1 [db_index = True, null = False, blank = False];
required manytoone site_privilege->SitePrivilege:controllersiteprivileges = 2 [db_index = True, null = False, blank = False];
optional string role_id = 3 [max_length = 200, content_type = "stripped", blank = True, help_text = "Keystone id", null = True, db_index = True];
diff --git a/xos/core/models/controllerslice.xproto b/xos/core/models/controllerslice.xproto
index 46e15ae..022835a 100644
--- a/xos/core/models/controllerslice.xproto
+++ b/xos/core/models/controllerslice.xproto
@@ -1,6 +1,6 @@
-message ControllerSlice (PlCoreBase){
+message ControllerSlice (XOSBase){
required manytoone controller->Controller:controllerslices = 1 [db_index = True, null = False, blank = False];
required manytoone slice->Slice:controllerslices = 2 [db_index = True, null = False, blank = False];
optional string tenant_id = 3 [max_length = 200, content_type = "stripped", blank = True, help_text = "Keystone tenant id", null = True, db_index = False];
diff --git a/xos/core/models/controllersliceprivilege.xproto b/xos/core/models/controllersliceprivilege.xproto
index c1308dc..5895519 100644
--- a/xos/core/models/controllersliceprivilege.xproto
+++ b/xos/core/models/controllersliceprivilege.xproto
@@ -1,6 +1,6 @@
-message ControllerSlicePrivilege (PlCoreBase){
+message ControllerSlicePrivilege (XOSBase){
required manytoone controller->Controller:controllersliceprivileges = 1 [db_index = True, null = False, blank = False];
required manytoone slice_privilege->SlicePrivilege:controllersliceprivileges = 2 [db_index = True, null = False, blank = False];
optional string role_id = 3 [max_length = 200, content_type = "stripped", blank = True, help_text = "Keystone id", null = True, db_index = True];
diff --git a/xos/core/models/controlleruser.xproto b/xos/core/models/controlleruser.xproto
index 5560d6d..14737eb 100644
--- a/xos/core/models/controlleruser.xproto
+++ b/xos/core/models/controlleruser.xproto
@@ -1,6 +1,6 @@
-message ControllerUser (PlCoreBase){
+message ControllerUser (XOSBase){
required manytoone user->User:controllerusers = 1 [db_index = True, null = False, blank = False];
required manytoone controller->Controller:controllersusers = 2 [db_index = True, null = False, blank = False];
optional string kuser_id = 3 [max_length = 200, content_type = "stripped", blank = True, help_text = "Keystone user id", null = True, db_index = False];
diff --git a/xos/core/models/dashboardview.xproto b/xos/core/models/dashboardview.xproto
index 76e4f30..ed67e5a 100644
--- a/xos/core/models/dashboardview.xproto
+++ b/xos/core/models/dashboardview.xproto
@@ -1,6 +1,6 @@
-message DashboardView (PlCoreBase){
+message DashboardView (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the View", null = False, db_index = False];
required string url = 2 [max_length = 1024, content_type = "stripped", blank = False, help_text = "URL of Dashboard", null = False, db_index = False];
required bool enabled = 3 [default = True, null = False, db_index = False, blank = True];
diff --git a/xos/core/models/deployment.xproto b/xos/core/models/deployment.xproto
index 779f74d..3a0e03b 100644
--- a/xos/core/models/deployment.xproto
+++ b/xos/core/models/deployment.xproto
@@ -1,6 +1,6 @@
-message Deployment (PlCoreBase){
+message Deployment (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the Deployment", null = False, db_index = False];
required string accessControl = 2 [default = "allow all", max_length = 200, blank = False, help_text = "Access control list that specifies which sites/users may use nodes in this deployment", null = False, db_index = False];
}
diff --git a/xos/core/models/deploymentprivilege.xproto b/xos/core/models/deploymentprivilege.xproto
index 33efc2a..2bd0286 100644
--- a/xos/core/models/deploymentprivilege.xproto
+++ b/xos/core/models/deploymentprivilege.xproto
@@ -1,6 +1,6 @@
-message DeploymentPrivilege (PlCoreBase){
+message DeploymentPrivilege (XOSBase){
required manytoone user->User:deploymentprivileges = 1 [db_index = True, null = False, blank = False];
required manytoone deployment->Deployment:deploymentprivileges = 2 [db_index = True, null = False, blank = False];
required manytoone role->DeploymentRole:deploymentprivileges = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/core/models/deploymentrole.xproto b/xos/core/models/deploymentrole.xproto
index 61adab5..fa483f7 100644
--- a/xos/core/models/deploymentrole.xproto
+++ b/xos/core/models/deploymentrole.xproto
@@ -1,5 +1,5 @@
-message DeploymentRole (PlCoreBase){
+message DeploymentRole (XOSBase){
required string role = 1 [choices = "(('admin', 'Admin'),)", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
}
diff --git a/xos/core/models/diag.xproto b/xos/core/models/diag.xproto
index 7869f50..6396bb4 100644
--- a/xos/core/models/diag.xproto
+++ b/xos/core/models/diag.xproto
@@ -1,5 +1,5 @@
-message Diag (PlCoreBase){
+message Diag (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the synchronizer", null = False, db_index = False];
}
diff --git a/xos/core/models/flavor.xproto b/xos/core/models/flavor.xproto
index d30a7c2..08714d0 100644
--- a/xos/core/models/flavor.xproto
+++ b/xos/core/models/flavor.xproto
@@ -1,6 +1,6 @@
-message Flavor (PlCoreBase){
+message Flavor (XOSBase){
required string name = 1 [max_length = 32, content_type = "stripped", blank = False, help_text = "name of this flavor, as displayed to users", null = False, db_index = False];
optional string description = 2 [db_index = False, max_length = 1024, null = True, content_type = "stripped", blank = True];
required string flavor = 3 [max_length = 32, content_type = "stripped", blank = False, help_text = "flavor string used to configure deployments", null = False, db_index = False];
diff --git a/xos/core/models/image.xproto b/xos/core/models/image.xproto
index f810e0d..a06070d 100644
--- a/xos/core/models/image.xproto
+++ b/xos/core/models/image.xproto
@@ -1,6 +1,6 @@
-message Image (PlCoreBase){
+message Image (XOSBase){
required string name = 1 [db_index = False, max_length = 256, null = False, content_type = "stripped", blank = False];
required string kind = 2 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'))", max_length = 30, blank = False, null = False, db_index = False];
required string disk_format = 3 [db_index = False, max_length = 256, null = False, content_type = "stripped", blank = False];
diff --git a/xos/core/models/imagedeployments.xproto b/xos/core/models/imagedeployments.xproto
index e11fedb..6d985ce 100644
--- a/xos/core/models/imagedeployments.xproto
+++ b/xos/core/models/imagedeployments.xproto
@@ -1,6 +1,6 @@
-message ImageDeployments (PlCoreBase){
+message ImageDeployments (XOSBase){
required manytoone image->Image:imagedeployments = 1 [db_index = True, null = False, blank = False];
required manytoone deployment->Deployment:imagedeployments = 2 [db_index = True, null = False, blank = False];
}
diff --git a/xos/core/models/instance.xproto b/xos/core/models/instance.xproto
index bc86813..b34291e 100644
--- a/xos/core/models/instance.xproto
+++ b/xos/core/models/instance.xproto
@@ -1,6 +1,6 @@
-message Instance (PlCoreBase){
+message Instance (XOSBase){
optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
diff --git a/xos/core/models/network.xproto b/xos/core/models/network.xproto
index 5305416..ffd1eb1 100644
--- a/xos/core/models/network.xproto
+++ b/xos/core/models/network.xproto
@@ -1,6 +1,6 @@
-message Network (PlCoreBase,ParameterMixin){
+message Network (XOSBase,ParameterMixin){
required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
diff --git a/xos/core/models/networkparameter.xproto b/xos/core/models/networkparameter.xproto
index a162d9a..01ce43e 100644
--- a/xos/core/models/networkparameter.xproto
+++ b/xos/core/models/networkparameter.xproto
@@ -1,6 +1,6 @@
-message NetworkParameter (PlCoreBase){
+message NetworkParameter (XOSBase){
required manytoone parameter->NetworkParameterType:networkparameters = 1 [help_text = "The type of the parameter", null = False, db_index = True, blank = False];
required string value = 2 [help_text = "The value of this parameter", max_length = 1024, null = False, db_index = False, blank = False];
required string content_type = 4 [max_length = 1024, content_type = "stripped", blank = False, help_text = "Content type id linked to this network parameter", null = False, db_index = False];
diff --git a/xos/core/models/networkparametertype.xproto b/xos/core/models/networkparametertype.xproto
index 6eb7804..840a345 100644
--- a/xos/core/models/networkparametertype.xproto
+++ b/xos/core/models/networkparametertype.xproto
@@ -1,6 +1,6 @@
-message NetworkParameterType (PlCoreBase){
+message NetworkParameterType (XOSBase){
required string name = 1 [help_text = "The name of this parameter", max_length = 128, null = False, db_index = True, blank = False];
required string description = 2 [db_index = False, max_length = 1024, null = False, blank = False];
}
diff --git a/xos/core/models/networkslice.xproto b/xos/core/models/networkslice.xproto
index 7ae04a2..1697fec 100644
--- a/xos/core/models/networkslice.xproto
+++ b/xos/core/models/networkslice.xproto
@@ -1,6 +1,6 @@
-message NetworkSlice (PlCoreBase){
+message NetworkSlice (XOSBase){
required manytoone network->Network:networkslices = 1 [db_index = True, null = False, blank = False];
required manytoone slice->Slice:networkslices = 2 [db_index = True, null = False, blank = False];
}
diff --git a/xos/core/models/networktemplate.xproto b/xos/core/models/networktemplate.xproto
index 4957784..d9653ab 100644
--- a/xos/core/models/networktemplate.xproto
+++ b/xos/core/models/networktemplate.xproto
@@ -1,6 +1,6 @@
-message NetworkTemplate (PlCoreBase,ParameterMixin){
+message NetworkTemplate (XOSBase,ParameterMixin){
required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
optional string description = 2 [db_index = False, max_length = 1024, null = True, blank = True];
required string visibility = 4 [default = "private", choices = "(('public', 'public'), ('private', 'private'))", max_length = 30, blank = False, null = False, db_index = False];
diff --git a/xos/core/models/node.xproto b/xos/core/models/node.xproto
index 9000fbb..36495d5 100644
--- a/xos/core/models/node.xproto
+++ b/xos/core/models/node.xproto
@@ -1,6 +1,4 @@
-
-
-message Node (PlCoreBase){
+message Node (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the Node", null = False, db_index = False];
required manytoone site_deployment->SiteDeployment:nodes = 2 [db_index = True, null = False, blank = False];
optional manytoone site->Site:nodes = 3 [db_index = True, null = True, blank = True];
diff --git a/xos/core/models/nodelabel.xproto b/xos/core/models/nodelabel.xproto
index fc89a46..bf00ae7 100644
--- a/xos/core/models/nodelabel.xproto
+++ b/xos/core/models/nodelabel.xproto
@@ -1,6 +1,4 @@
-
-
-message NodeLabel (PlCoreBase){
+message NodeLabel (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "label name", null = False, db_index = False];
required manytomany node->Node/NodeLabel_node:nodelabels = 2 [db_index = False, null = False, blank = True];
}
diff --git a/xos/core/models/plcorebase.py b/xos/core/models/plcorebase.py
deleted file mode 100644
index aa80718..0000000
--- a/xos/core/models/plcorebase.py
+++ /dev/null
@@ -1,464 +0,0 @@
-import datetime
-import json
-import pytz
-import inspect
-import sys
-import threading
-from django.db import models
-from django.db import transaction
-from django.forms.models import model_to_dict
-from django.utils import timezone
-from django.core.exceptions import PermissionDenied
-from cgi import escape as html_escape
-from journal import journal_object
-from django.db.models.deletion import Collector
-from django.db import router
-from django.contrib.contenttypes.models import ContentType
-
-import redis
-from redis import ConnectionError
-
-def date_handler(obj):
- if isinstance(obj, pytz.tzfile.DstTzInfo):
- # json can't serialize DstTzInfo
- return str(obj)
- return obj.isoformat() if hasattr(obj, 'isoformat') else obj
-
-try:
- # This is a no-op if observer_disabled is set to 1 in the config file
- from synchronizers.base import *
-except:
- print >> sys.stderr, "import of observer failed! printing traceback and disabling observer:"
- import traceback
- traceback.print_exc()
-
- # guard against something failing
- def notify_observer(*args, **kwargs):
- pass
-
-class StrippedCharField(models.CharField):
- """ CharField that strips trailing and leading spaces."""
- def clean(self, value, *args, **kwds):
- if value is not None:
- value = value.strip()
- return super(StrippedCharField, self).clean(value, *args, **kwds)
-
-
-# This manager will be inherited by all subclasses because
-# the core model is abstract.
-class PlCoreBaseDeletionManager(models.Manager):
- def get_queryset(self):
- parent=super(PlCoreBaseDeletionManager, self)
- if hasattr(parent, "get_queryset"):
- return parent.get_queryset().filter(deleted=True)
- else:
- return parent.get_query_set().filter(deleted=True)
-
- # deprecated in django 1.7 in favor of get_queryset().
- def get_query_set(self):
- return self.get_queryset()
-
-# This manager will be inherited by all subclasses because
-# the core model is abstract.
-class PlCoreBaseManager(models.Manager):
- def get_queryset(self):
- parent=super(PlCoreBaseManager, self)
- if hasattr(parent, "get_queryset"):
- return parent.get_queryset().filter(deleted=False)
- else:
- return parent.get_query_set().filter(deleted=False)
-
- # deprecated in django 1.7 in favor of get_queryset().
- def get_query_set(self):
- return self.get_queryset()
-
-class PlModelMixIn(object):
- # Provides useful methods for computing which objects in a model have
- # changed. Make sure to do self._initial = self._dict in the __init__
- # method.
-
- # Also includes useful utility, like getValidators
-
- # This is broken out of PlCoreBase into a Mixin so the User model can
- # also make use of it.
-
- @property
- def _dict(self):
- return model_to_dict(self, fields=[field.name for field in
- self._meta.fields])
-
- def fields_differ(self,f1,f2):
- if isinstance(f1,datetime.datetime) and isinstance(f2,datetime.datetime) and (timezone.is_aware(f1) != timezone.is_aware(f2)):
- return True
- else:
- return (f1 != f2)
-
- @property
- def diff(self):
- d1 = self._initial
- d2 = self._dict
- diffs = [(k, (v, d2[k])) for k, v in d1.items() if self.fields_differ(v,d2[k])]
- return dict(diffs)
-
- @property
- def has_changed(self):
- return bool(self.diff)
-
- @property
- def changed_fields(self):
- return self.diff.keys()
-
- def has_field_changed(self, field_name):
- return field_name in self.diff.keys()
-
- def get_field_diff(self, field_name):
- return self.diff.get(field_name, None)
-
- #classmethod
- def getValidators(cls):
- """ primarily for REST API, return a dictionary of field names mapped
- to lists of the type of validations that need to be applied to
- those fields.
- """
- validators = {}
- for field in cls._meta.fields:
- l = []
- if field.blank==False:
- l.append("notBlank")
- if field.__class__.__name__=="URLField":
- l.append("url")
- validators[field.name] = l
- return validators
-
- def get_backend_register(self, k, default=None):
- try:
- return json.loads(self.backend_register).get(k, default)
- except AttributeError:
- return default
-
- def set_backend_register(self, k, v):
- br = {}
- try:
- br=json.loads(self.backend_register)
- except AttributeError:
- br={}
-
- br[k] = v
- self.backend_register = json.dumps(br)
-
- def get_backend_details(self):
- try:
- scratchpad = json.loads(self.backend_register)
- except AttributeError:
- return (None, None, None, None)
-
- try:
- exponent = scratchpad['exponent']
- except KeyError:
- exponent = None
-
- try:
- last_success_time = scratchpad['last_success']
- dt = datetime.datetime.fromtimestamp(last_success_time)
- last_success = dt.strftime("%Y-%m-%d %H:%M")
- except KeyError:
- last_success = None
-
- try:
- failures = scratchpad['failures']
- except KeyError:
- failures=None
-
- try:
- last_failure_time = scratchpad['last_failure']
- dt = datetime.datetime.fromtimestamp(last_failure_time)
- last_failure = dt.strftime("%Y-%m-%d %H:%M")
- except KeyError:
- last_failure = None
-
- return (exponent, last_success, last_failure, failures)
-
- def get_backend_icon(self):
- is_perfect = (self.backend_status is not None) and self.backend_status.startswith("1 -")
- is_good = (self.backend_status is not None) and (self.backend_status.startswith("0 -") or self.backend_status.startswith("1 -"))
- is_provisioning = self.backend_status is None or self.backend_status == "Provisioning in progress" or self.backend_status==""
-
- # returns (icon_name, tooltip)
- if (self.enacted is not None) and (self.enacted >= self.updated and is_good) or is_perfect:
- return ("success", "successfully enacted")
- else:
- if is_good or is_provisioning:
- return ("clock", "Pending sync, last_status = " + html_escape(self.backend_status, quote=True))
- else:
- return ("error", html_escape(self.backend_status, quote=True))
-
- def enforce_choices(self, field, choices):
- choices = [x[0] for x in choices]
- for choice in choices:
- if field==choice:
- return
- if (choice==None) and (field==""):
- # allow "" and None to be equivalent
- return
- raise Exception("Field value %s is not in %s" % (field, str(choices)))
-
- def serialize_for_redis(self):
- """ Serialize the object for posting to redis.
-
- The API serializes ForeignKey fields by naming them <name>_id
- whereas model_to_dict leaves them with the original name. Modify
- the results of model_to_dict to provide the same fieldnames.
- """
-
- field_types = {}
- for f in self._meta.fields:
- field_types[f.name] = f.get_internal_type()
-
- fields = model_to_dict(self)
- for k in fields.keys():
- if field_types.get(k,None) == "ForeignKey":
- new_key_name = "%s_id" % k
- if (k in fields) and (new_key_name not in fields):
- fields[new_key_name] = fields[k]
- del fields[k]
-
- return fields
-
- def push_redis_event(self):
- # Transmit update via Redis
- changed_fields = []
-
- if self.pk is not None:
- my_model = type(self)
- try:
- orig = my_model.objects.get(pk=self.pk)
-
- for f in my_model._meta.fields:
- oval = getattr(orig, f.name)
- nval = getattr(self, f.name)
- if oval != nval:
- changed_fields.append(f.name)
- except:
- changed_fields.append('__lookup_error')
-
- try:
- r = redis.Redis("redis")
- # NOTE the redis event has been extended with model properties to facilitate the support of real time notification in the UI
- # keep this monitored for performance reasons and eventually revert it back to fetch model properties via the REST API
- model = self.serialize_for_redis()
- bases = inspect.getmro(self.__class__)
- bases = [x for x in bases if issubclass(x, PlCoreBase)]
- class_names = ",".join([x.__name__ for x in bases])
- model['class_names'] = class_names
- payload = json.dumps({'pk': self.pk, 'changed_fields': changed_fields, 'object': model}, default=date_handler)
- r.publish(self.__class__.__name__, payload)
- except ConnectionError:
- # Redis not running.
- pass
-
-# For cascading deletes, we need a Collector that doesn't do fastdelete,
-# so we get a full list of models.
-class XOSCollector(Collector):
- def can_fast_delete(self, *args, **kwargs):
- return False
-
-class PlCoreBase(models.Model, PlModelMixIn):
- objects = PlCoreBaseManager()
- deleted_objects = PlCoreBaseDeletionManager()
-
- # default values for created and updated are only there to keep evolution
- # from failing.
- created = models.DateTimeField(auto_now_add=True)
- updated = models.DateTimeField(default=timezone.now)
- enacted = models.DateTimeField(null=True, blank=True, default=None)
- policed = models.DateTimeField(null=True, blank=True, default=None)
-
- # This is a scratchpad used by the Observer
- backend_register = models.CharField(max_length=1024,
- default="{}", null=True)
-
- # backend_need_delete and backend_need_reap are used by the synchronizer to
- # handle deleting and reaping objects.
- #
- # backend_need_delete is set by a syncstep when it starts to work on an
- # object. It indicates that the syncstep will, in the future, want an
- # opportunity to delete the object. This bit prevents the reaper from
- # auto-deleting the object.
- #
- # backend_need_reap is set when a syncstep has successfully enacted a delete
- # and is ready for it to be permanently deleted. The reaper will, assuming
- # the object has no cascades to other objects that need deleting, permanently
- # delete the object.
-
- backend_need_delete = models.BooleanField(default=False)
- backend_need_reap = models.BooleanField(default=False)
-
- backend_status = models.CharField(max_length=1024,
- default="0 - Provisioning in progress")
- deleted = models.BooleanField(default=False)
- write_protect = models.BooleanField(default=False)
- lazy_blocked = models.BooleanField(default=False)
- no_sync = models.BooleanField(default=False) # prevent object sync
- no_policy = models.BooleanField(default=False) # prevent model_policy run
-
- class Meta:
- # Changing abstract to False would require the managers of subclasses of
- # PlCoreBase to be customized individually.
- abstract = True
- app_label = "core"
-
- def __init__(self, *args, **kwargs):
- super(PlCoreBase, self).__init__(*args, **kwargs)
- self._initial = self._dict # for PlModelMixIn
- self.silent = False
-
- def get_controller(self):
- return self.controller
-
- def can_update(self, user):
- return user.can_update_root()
-
- def delete(self, *args, **kwds):
- # so we have something to give the observer
- purge = kwds.get('purge',False)
- if purge:
- del kwds['purge']
- silent = kwds.get('silent',False)
- if silent:
- del kwds['silent']
- try:
- purge = purge or observer_disabled
- except NameError:
- pass
-
- if (purge):
- journal_object(self, "delete.purge")
- super(PlCoreBase, self).delete(*args, **kwds)
- else:
- if (not self.write_protect ):
- self.deleted = True
- self.enacted=None
- self.policed=None
- journal_object(self, "delete.mark_deleted")
- self.save(update_fields=['enacted','deleted','policed'], silent=silent)
-
- collector = XOSCollector(using=router.db_for_write(self.__class__, instance=self))
- collector.collect([self])
- with transaction.atomic():
- for (k, models) in collector.data.items():
- for model in models:
- if model.deleted:
- # in case it's already been deleted, don't delete again
- continue
- model.deleted = True
- model.enacted=None
- model.policed=None
- journal_object(model, "delete.cascade.mark_deleted", msg="root = %r" % self)
- model.save(update_fields=['enacted','deleted','policed'], silent=silent)
-
- def save(self, *args, **kwargs):
- journal_object(self, "plcorebase.save")
-
- # let the user specify silence as either a kwarg or an instance varible
- silent = self.silent
- if "silent" in kwargs:
- silent=silent or kwargs.pop("silent")
-
- caller_kind = "unknown"
-
- if ('synchronizer' in threading.current_thread().name):
- caller_kind = "synchronizer"
-
- if "caller_kind" in kwargs:
- caller_kind = kwargs.pop("caller_kind")
-
- always_update_timestamp = False
- if "always_update_timestamp" in kwargs:
- always_update_timestamp = always_update_timestamp or kwargs.pop("always_update_timestamp")
-
- # SMBAKER: if an object is trying to delete itself, or if the observer
- # is updating an object's backend_* fields, then let it slip past the
- # composite key check.
- ignore_composite_key_check=False
- if "update_fields" in kwargs:
- ignore_composite_key_check=True
- for field in kwargs["update_fields"]:
- if not (field in ["backend_register", "backend_status", "deleted", "enacted", "updated"]):
- ignore_composite_key_check=False
-
- if (caller_kind!="synchronizer") or always_update_timestamp:
- self.updated = timezone.now()
-
- journal_object(self, "plcorebase.save.super_save")
-
- super(PlCoreBase, self).save(*args, **kwargs)
-
- journal_object(self, "plcorebase.save.super_save_returned")
-
- self.push_redis_event()
-
- # This is a no-op if observer_disabled is set
- # if not silent:
- # notify_observer()
-
- self._initial = self._dict
-
- def save_by_user(self, user, *args, **kwds):
- if not self.can_update(user):
- if getattr(self, "_cant_update_fieldName", None) is not None:
- raise PermissionDenied("You do not have permission to update field %s on object %s" % (self._cant_update_fieldName, self.__class__.__name__))
- else:
- raise PermissionDenied("You do not have permission to update %s objects" % self.__class__.__name__)
-
- self.save(*args, **kwds)
-
- def delete_by_user(self, user, *args, **kwds):
- if not self.can_update(user):
- raise PermissionDenied("You do not have permission to delete %s objects" % self.__class__.__name__)
- self.delete(*args, **kwds)
-
- @classmethod
- def select_by_user(cls, user):
- # This should be overridden by descendant classes that want to perform
- # filtering of visible objects by user.
- return cls.objects.all()
-
- def tologdict(self):
- try:
- d = {'model_name':self.__class__.__name__, 'pk': self.pk}
- except:
- d = {}
-
- return d
-
- # for the old django admin UI
- def __unicode__(self):
- if hasattr(self, "name") and self.name:
- return u'%s' % self.name
- elif hasattr(self, "id") and self.id:
- return u'%s-%s' % (self.__class__.__name__, self.id)
- else:
- return u'%s-unsaved' % self.__class__.__name__
-
- def get_content_type_key(self):
- ct = ContentType.objects.get_for_model(self.__class__)
- return "%s.%s" % (ct.app_label, ct.model)
-
- @staticmethod
- def get_content_type_from_key(key):
- (app_name, model_name) = key.split(".")
- return ContentType.objects.get_by_natural_key(app_name, model_name)
-
- @staticmethod
- def get_content_object(content_type, object_id):
- ct = PlCoreBase.get_content_type_from_key(content_type)
- cls = ct.model_class()
- return cls.objects.get(id=object_id)
-
-class ModelLink:
- def __init__(self,dest,via,into=None):
- self.dest=dest
- self.via=via
- self.into=into
-
-
diff --git a/xos/core/models/port.xproto b/xos/core/models/port.xproto
index a3a9cdc..115b0db 100644
--- a/xos/core/models/port.xproto
+++ b/xos/core/models/port.xproto
@@ -1,6 +1,6 @@
-message Port (PlCoreBase,ParameterMixin){
+message Port (XOSBase,ParameterMixin){
required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
diff --git a/xos/core/models/role.xproto b/xos/core/models/role.xproto
index 9e48abc..d55dcc0 100644
--- a/xos/core/models/role.xproto
+++ b/xos/core/models/role.xproto
@@ -1,6 +1,6 @@
-message Role (PlCoreBase){
+message Role (XOSBase){
required string role_type = 1 [db_index = False, max_length = 80, null = False, content_type = "stripped", blank = False];
optional string role = 2 [db_index = False, max_length = 80, null = True, content_type = "stripped", blank = True];
required string description = 3 [db_index = False, max_length = 120, null = False, content_type = "stripped", blank = False];
diff --git a/xos/core/models/service.xproto b/xos/core/models/service.xproto
index 74bb66d..daaddf6 100644
--- a/xos/core/models/service.xproto
+++ b/xos/core/models/service.xproto
@@ -1,6 +1,6 @@
-message Service (PlCoreBase,AttributeMixin){
+message Service (XOSBase,AttributeMixin){
optional string description = 1 [help_text = "Description of Service", max_length = 254, null = True, db_index = False, blank = True];
required bool enabled = 2 [default = True, null = False, db_index = False, blank = True];
required string kind = 3 [default = "generic", max_length = 30, content_type = "stripped", blank = False, help_text = "Kind of service", null = False, db_index = False];
diff --git a/xos/core/models/serviceattribute.xproto b/xos/core/models/serviceattribute.xproto
index d333aa2..8c9d209 100644
--- a/xos/core/models/serviceattribute.xproto
+++ b/xos/core/models/serviceattribute.xproto
@@ -1,6 +1,6 @@
-message ServiceAttribute (PlCoreBase){
+message ServiceAttribute (XOSBase){
required string name = 1 [help_text = "Attribute Name", max_length = 128, null = False, db_index = False, blank = False];
required string value = 2 [help_text = "Attribute Value", null = False, db_index = False, blank = False];
required manytoone service->Service:serviceattributes = 3 [help_text = "The Service this attribute is associated with", null = False, db_index = True, blank = False];
diff --git a/xos/core/models/servicemonitoringagentinfo.xproto b/xos/core/models/servicemonitoringagentinfo.xproto
index 4a4e466..59ce1c8 100644
--- a/xos/core/models/servicemonitoringagentinfo.xproto
+++ b/xos/core/models/servicemonitoringagentinfo.xproto
@@ -1,6 +1,6 @@
-message ServiceMonitoringAgentInfo (PlCoreBase){
+message ServiceMonitoringAgentInfo (XOSBase){
required string name = 1 [help_text = "Monitoring Agent Name", max_length = 128, null = False, db_index = False, blank = False];
optional manytoone service->Service:servicemonitoringagents = 2 [help_text = "The Service this attribute is associated with", null = True, db_index = True, blank = True];
required string target_uri = 3 [help_text = "Monitoring collector URI to be used by agents to publish the data", null = False, db_index = False, blank = False];
diff --git a/xos/core/models/serviceprivilege.xproto b/xos/core/models/serviceprivilege.xproto
index f88acef..6714b17 100644
--- a/xos/core/models/serviceprivilege.xproto
+++ b/xos/core/models/serviceprivilege.xproto
@@ -1,6 +1,6 @@
-message ServicePrivilege (PlCoreBase){
+message ServicePrivilege (XOSBase){
required manytoone user->User:serviceprivileges = 1 [db_index = True, null = False, blank = False];
required manytoone service->Service:serviceprivileges = 2 [db_index = True, null = False, blank = False];
required manytoone role->ServiceRole:serviceprivileges = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/core/models/servicerole.xproto b/xos/core/models/servicerole.xproto
index 3661df4..74c9bb9 100644
--- a/xos/core/models/servicerole.xproto
+++ b/xos/core/models/servicerole.xproto
@@ -1,5 +1,5 @@
-message ServiceRole (PlCoreBase){
+message ServiceRole (XOSBase){
required string role = 1 [choices = "(('admin', 'Admin'),)", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
}
diff --git a/xos/core/models/site.xproto b/xos/core/models/site.xproto
index ce2fbd1..c71fa20 100644
--- a/xos/core/models/site.xproto
+++ b/xos/core/models/site.xproto
@@ -1,6 +1,6 @@
-message Site (PlCoreBase){
+message Site (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name for this Site", null = False, db_index = False];
optional string site_url = 2 [max_length = 512, content_type = "url", blank = True, help_text = "Site's Home URL Page", null = True, db_index = False];
required bool enabled = 3 [help_text = "Status for this Site", default = True, null = False, db_index = False, blank = True];
diff --git a/xos/core/models/sitedeployment.xproto b/xos/core/models/sitedeployment.xproto
index ae12aa1..ff23abf 100644
--- a/xos/core/models/sitedeployment.xproto
+++ b/xos/core/models/sitedeployment.xproto
@@ -1,6 +1,6 @@
-message SiteDeployment (PlCoreBase){
+message SiteDeployment (XOSBase){
required manytoone site->Site:sitedeployments = 1 [db_index = True, null = False, blank = False];
required manytoone deployment->Deployment:sitedeployments = 2 [db_index = True, null = False, blank = False];
optional manytoone controller->Controller:sitedeployments = 3 [db_index = True, null = True, blank = True];
diff --git a/xos/core/models/siteprivilege.xproto b/xos/core/models/siteprivilege.xproto
index c63677a..0f277c2 100644
--- a/xos/core/models/siteprivilege.xproto
+++ b/xos/core/models/siteprivilege.xproto
@@ -1,6 +1,6 @@
-message SitePrivilege (PlCoreBase){
+message SitePrivilege (XOSBase){
required manytoone user->User:siteprivileges = 1 [db_index = True, null = False, blank = False];
required manytoone site->Site:siteprivileges = 2 [db_index = True, null = False, blank = False];
required manytoone role->SiteRole:siteprivileges = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/core/models/siterole.xproto b/xos/core/models/siterole.xproto
index a42ef5c..58b638e 100644
--- a/xos/core/models/siterole.xproto
+++ b/xos/core/models/siterole.xproto
@@ -1,5 +1,5 @@
-message SiteRole (PlCoreBase){
+message SiteRole (XOSBase){
required string role = 1 [choices = "(('admin', 'Admin'), ('pi', 'PI'), ('tech', 'Tech'), ('billing', 'Billing'))", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
}
diff --git a/xos/core/models/slice.xproto b/xos/core/models/slice.xproto
index 222813d..9adf2a9 100644
--- a/xos/core/models/slice.xproto
+++ b/xos/core/models/slice.xproto
@@ -1,4 +1,4 @@
-message Slice (PlCoreBase){
+message Slice (XOSBase){
required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
required string description = 4 [help_text = "High level description of the slice and expected activities", max_length = 1024, null = False, db_index = False, blank = True];
diff --git a/xos/core/models/sliceprivilege.xproto b/xos/core/models/sliceprivilege.xproto
index 587f423..6c85a8c 100644
--- a/xos/core/models/sliceprivilege.xproto
+++ b/xos/core/models/sliceprivilege.xproto
@@ -1,6 +1,6 @@
-message SlicePrivilege (PlCoreBase){
+message SlicePrivilege (XOSBase){
required manytoone user->User:sliceprivileges = 1 [db_index = True, null = False, blank = False];
required manytoone slice->Slice:sliceprivileges = 2 [db_index = True, null = False, blank = False];
required manytoone role->SliceRole:sliceprivileges = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/core/models/slicerole.xproto b/xos/core/models/slicerole.xproto
index 6396518..7d6eb19 100644
--- a/xos/core/models/slicerole.xproto
+++ b/xos/core/models/slicerole.xproto
@@ -1,5 +1,5 @@
-message SliceRole (PlCoreBase){
+message SliceRole (XOSBase){
required string role = 1 [choices = "(('admin', 'Admin'), ('default', 'Default'))", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
}
diff --git a/xos/core/models/tag.xproto b/xos/core/models/tag.xproto
index 6e5daef..a2cd9b2 100644
--- a/xos/core/models/tag.xproto
+++ b/xos/core/models/tag.xproto
@@ -1,6 +1,6 @@
-message Tag (PlCoreBase){
+message Tag (XOSBase){
required manytoone service->Service:tags = 1 [help_text = "The Service this Tag is associated with", null = False, db_index = True, blank = False];
required string name = 2 [help_text = "The name of this tag", max_length = 128, null = False, db_index = True, blank = False];
required string value = 3 [max_length = 1024, content_type = "stripped", blank = False, help_text = "The value of this tag", null = False, db_index = False];
diff --git a/xos/core/models/tenant.xproto b/xos/core/models/tenant.xproto
index 91de112..384d119 100644
--- a/xos/core/models/tenant.xproto
+++ b/xos/core/models/tenant.xproto
@@ -1,6 +1,6 @@
-message Tenant (PlCoreBase,AttributeMixin){
+message Tenant (XOSBase,AttributeMixin){
optional string name = 1 [db_index = False, max_length = 200, null = True, content_type = "stripped", blank = True];
required string kind = 2 [default = "generic", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
required manytoone provider_service->Service:provided_tenants = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/core/models/tenantattribute.xproto b/xos/core/models/tenantattribute.xproto
index f9a3abe..82c35d5 100644
--- a/xos/core/models/tenantattribute.xproto
+++ b/xos/core/models/tenantattribute.xproto
@@ -1,6 +1,6 @@
-message TenantAttribute (PlCoreBase){
+message TenantAttribute (XOSBase){
required string name = 1 [help_text = "Attribute Name", max_length = 128, null = False, db_index = False, blank = False];
required string value = 2 [help_text = "Attribute Value", null = False, db_index = False, blank = False];
required manytoone tenant->Tenant:tenantattributes = 3 [help_text = "The Tenant this attribute is associated with", null = False, db_index = True, blank = False];
diff --git a/xos/core/models/tenantprivilege.xproto b/xos/core/models/tenantprivilege.xproto
index 9d90981..e98aaec 100644
--- a/xos/core/models/tenantprivilege.xproto
+++ b/xos/core/models/tenantprivilege.xproto
@@ -1,6 +1,6 @@
-message TenantPrivilege (PlCoreBase){
+message TenantPrivilege (XOSBase){
required manytoone user->User:tenantprivileges = 1 [db_index = True, null = False, blank = False];
required manytoone tenant->Tenant:tenantprivileges = 2 [db_index = True, null = False, blank = False];
required manytoone role->TenantRole:tenantprivileges = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/core/models/tenantrole.xproto b/xos/core/models/tenantrole.xproto
index 646809e..54ed436 100644
--- a/xos/core/models/tenantrole.xproto
+++ b/xos/core/models/tenantrole.xproto
@@ -1,5 +1,5 @@
-message TenantRole (PlCoreBase){
+message TenantRole (XOSBase){
required string role = 1 [choices = "(('admin', 'Admin'), ('access', 'Access'))", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
}
diff --git a/xos/core/models/tenantroot.xproto b/xos/core/models/tenantroot.xproto
index 3c01492..00c3154 100644
--- a/xos/core/models/tenantroot.xproto
+++ b/xos/core/models/tenantroot.xproto
@@ -1,6 +1,6 @@
-message TenantRoot (PlCoreBase,AttributeMixin){
+message TenantRoot (XOSBase,AttributeMixin){
required string kind = 1 [default = "generic", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
optional string name = 2 [max_length = 255, content_type = "stripped", blank = True, help_text = "name", null = True, db_index = False];
optional string service_specific_attribute = 3 [db_index = False, null = True, blank = True];
diff --git a/xos/core/models/tenantrootprivilege.xproto b/xos/core/models/tenantrootprivilege.xproto
index cf86119..39e8b5c 100644
--- a/xos/core/models/tenantrootprivilege.xproto
+++ b/xos/core/models/tenantrootprivilege.xproto
@@ -1,6 +1,6 @@
-message TenantRootPrivilege (PlCoreBase){
+message TenantRootPrivilege (XOSBase){
required manytoone user->User:tenant_root_privileges = 1 [db_index = True, null = False, blank = False];
required manytoone tenant_root->TenantRoot:tenant_root_privileges = 2 [db_index = True, null = False, blank = False];
required manytoone role->TenantRootRole:tenant_root_privileges = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/core/models/tenantrootrole.xproto b/xos/core/models/tenantrootrole.xproto
index 87346ac..2297b33 100644
--- a/xos/core/models/tenantrootrole.xproto
+++ b/xos/core/models/tenantrootrole.xproto
@@ -1,5 +1,5 @@
-message TenantRootRole (PlCoreBase){
+message TenantRootRole (XOSBase){
required string role = 1 [choices = "(('admin', 'Admin'), ('access', 'Access'))", max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
}
diff --git a/xos/core/models/user.py b/xos/core/models/user.py
index eb11c18..8a191f5 100644
--- a/xos/core/models/user.py
+++ b/xos/core/models/user.py
@@ -7,8 +7,8 @@
from operator import attrgetter, itemgetter
from core.middleware import get_request
-from core.models import DashboardView, PlCoreBase, PlModelMixIn, Site, ModelLink
-from core.models.plcorebase import StrippedCharField, XOSCollector
+from core.models import DashboardView, XOSBase, PlModelMixIn, Site, ModelLink
+from core.models.xosbase import StrippedCharField, XOSCollector
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from django.core.exceptions import PermissionDenied
from django.core.mail import EmailMultiAlternatives
@@ -25,7 +25,7 @@
import redis
from redis import ConnectionError
-# ------ from plcorebase.py ------
+# ------ from xosbase.py ------
try:
# This is a no-op if observer_disabled is set to 1 in the config file
from synchronizers.base import *
@@ -277,7 +277,7 @@
model.save(update_fields=['enacted','deleted','policed'], silent=silent)
def save(self, *args, **kwargs):
- journal_object(self, "plcorebase.save")
+ journal_object(self, "xosbase.save")
if not self.id:
self.set_password(self.password)
@@ -317,11 +317,11 @@
self.username = self.email
- journal_object(self, "plcorebase.save.super_save")
+ journal_object(self, "xosbase.save.super_save")
super(User, self).save(*args, **kwargs)
- journal_object(self, "plcorebase.save.super_save_returned")
+ journal_object(self, "xosbase.save.super_save_returned")
self.push_redis_event()
@@ -625,7 +625,7 @@
return cls.objects.get(id=object_id)
-class UserDashboardView(PlCoreBase):
+class UserDashboardView(XOSBase):
user = models.ForeignKey(User, related_name='userdashboardviews')
dashboardView = models.ForeignKey(
DashboardView, related_name='userdashboardviews')
diff --git a/xos/core/models/xos.xproto b/xos/core/models/xos.xproto
index 2335b0d..32ed1d7 100644
--- a/xos/core/models/xos.xproto
+++ b/xos/core/models/xos.xproto
@@ -1,5 +1,5 @@
-message XOS (PlCoreBase){
+message XOS (XOSBase){
required string name = 1 [default = "XOS", max_length = 200, content_type = "stripped", blank = False, help_text = "Name of XOS", null = False, db_index = False];
}
diff --git a/xos/core/models/xosbase.xproto b/xos/core/models/xosbase.xproto
new file mode 100644
index 0000000..f3def66
--- /dev/null
+++ b/xos/core/models/xosbase.xproto
@@ -0,0 +1,15 @@
+message XOSBase {
+ required string created = 1 [content_type = "date", auto_now_add = True];
+ required string updated = 2 [default = "now()", content_type = "date"];
+ optional string enacted = 3 [null = True, content_type = "date", blank = True, default = None];
+ optional string policed = 4 [null = True, content_type = "date", blank = True, default = None];
+ optional string backend_register = 5 [default = "{}", max_length = 1024, null = True];
+ required bool backend_need_delete = 6 [default = False];
+ required bool backend_need_reap = 7 [default = False];
+ required string backend_status = 8 [default = "0 - Provisioning in progress", max_length = 1024];
+ required bool deleted = 9 [default = False];
+ required bool write_protect = 10 [default = False];
+ required bool lazy_blocked = 11 [default = False];
+ required bool no_sync = 12 [default = False];
+ required bool no_policy = 13 [default = False];
+}
diff --git a/xos/core/models/xosbase_header.py b/xos/core/models/xosbase_header.py
new file mode 120000
index 0000000..dd654e6
--- /dev/null
+++ b/xos/core/models/xosbase_header.py
@@ -0,0 +1 @@
+attic/xosbase_header.py
\ No newline at end of file
diff --git a/xos/core/models/xosguiextension.xproto b/xos/core/models/xosguiextension.xproto
index 774de4e..5d0c58e 100644
--- a/xos/core/models/xosguiextension.xproto
+++ b/xos/core/models/xosguiextension.xproto
@@ -1,6 +1,6 @@
-message XOSGuiExtension (PlCoreBase){
+message XOSGuiExtension (XOSBase){
required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the GUI Extensions", null = False, db_index = False];
required string files = 2 [max_length = 1024, content_type = "stripped", blank = False, help_text = "List of comma separated file composing the view", null = False, db_index = False];
}
diff --git a/xos/coreapi/apihelper.py b/xos/coreapi/apihelper.py
index e64a8a2..e76bf97 100644
--- a/xos/coreapi/apihelper.py
+++ b/xos/coreapi/apihelper.py
@@ -185,11 +185,11 @@
getattr(p_obj,related_name+"_ids").append(rel_obj.id)
# Generate a list of class names for the object. This includes its
- # ancestors. Anything that is a descendant of PlCoreBase or User
+ # ancestors. Anything that is a descendant of XOSBase or User
# counts.
bases = inspect.getmro(obj.__class__)
- bases = [x for x in bases if issubclass(x, PlCoreBase) or issubclass(x, User)]
+ bases = [x for x in bases if issubclass(x, XOSBase) or issubclass(x, User)]
p_obj.class_names = ",".join( [x.__name__ for x in bases] )
p_obj.self_content_type_id = obj.get_content_type_key()
diff --git a/xos/coreapi/reaper.py b/xos/coreapi/reaper.py
index f7adb06..879831e 100644
--- a/xos/coreapi/reaper.py
+++ b/xos/coreapi/reaper.py
@@ -25,7 +25,7 @@
from django.dispatch import receiver
from django.utils import timezone
from django.db import models as django_models
-from core.models.plcorebase import XOSCollector
+from core.models.xosbase import XOSCollector
from django.db import router
from xos.logger import Logger, logging
diff --git a/xos/generate/dependency_walker.py b/xos/generate/dependency_walker.py
index 210ec0f..65721a9 100644
--- a/xos/generate/dependency_walker.py
+++ b/xos/generate/dependency_walker.py
@@ -85,7 +85,7 @@
peer_objects = []
for o in peer_objects:
- #if (isinstance(o,PlCoreBase)):
+ #if (isinstance(o,XOSBase)):
if (hasattr(o,'updated')):
fn(o, object)
ret.append(o)
diff --git a/xos/genx/targets/django-split.xtarget b/xos/genx/targets/django-split.xtarget
index f3a998b..af3a8cc 100644
--- a/xos/genx/targets/django-split.xtarget
+++ b/xos/genx/targets/django-split.xtarget
@@ -1,7 +1,6 @@
-from header import *
{% for m in proto.messages %}
-{% if file_exists(xproto_base_name(m.name)|lower+'_header.py') -%}from {{xproto_base_name(m.name)|lower }}_header import *{% endif %}
+{% if file_exists(xproto_base_name(m.name)|lower+'_header.py') -%}from {{xproto_base_name(m.name)|lower }}_header import *{%- else -%}from header import *{% endif %}
{% if file_exists(xproto_base_name(m.name)|lower+'_top.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_top.py') }} {% endif %}
{%- for l in m.links %}
@@ -12,13 +11,13 @@
{%- endfor %}
{% for b in m.bases %}
-{% if b!='PlCoreBase' and 'Mixin' not in b%}
+{% if b!='XOSBase' and 'Mixin' not in b%}
from core.models.{{b | lower}} import {{ b }}
{% endif %}
{% endfor %}
-class {{ m.name }}{{ xproto_base_def(m.bases) }}:
+class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}:
# Primitive Fields (Not Relations)
{% for f in m.fields %}
{%- if not f.link -%}
diff --git a/xos/genx/targets/django.xtarget b/xos/genx/targets/django.xtarget
index 131676a..8ebd2a7 100644
--- a/xos/genx/targets/django.xtarget
+++ b/xos/genx/targets/django.xtarget
@@ -12,13 +12,13 @@
{%- endfor %}
{% for b in m.bases %}
-{% if b!='PlCoreBase' and 'Mixin' not in b%}
+{% if b!='XOSBase' and 'Mixin' not in b%}
from core.models.{{b | lower}} import {{ b }}
{% endif %}
{% endfor %}
-class {{ m.name }}{{ xproto_base_def(m.bases) }}:
+class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}:
# Primitive Fields (Not Relations)
{% for f in m.fields %}
{%- if not f.link -%}
diff --git a/xos/genx/targets/init.xtarget b/xos/genx/targets/init.xtarget
index 770502d..b089e53 100644
--- a/xos/genx/targets/init.xtarget
+++ b/xos/genx/targets/init.xtarget
@@ -1,7 +1,7 @@
# The hardcoded entries cannot be inferred from the models. To get rid of in the long run
#
-from .plcorebase import PlCoreBase,PlCoreBaseManager,PlCoreBaseDeletionManager,PlModelMixIn,ModelLink
+from .xosbase import XOSBase,XOSBaseManager,XOSBaseDeletionManager,PlModelMixIn,ModelLink
from .contenttype import ContentType
from .site import Site
from .dashboardview import DashboardView
diff --git a/xos/genx/targets/service.xtarget b/xos/genx/targets/service.xtarget
index c2256d2..e5bf019 100644
--- a/xos/genx/targets/service.xtarget
+++ b/xos/genx/targets/service.xtarget
@@ -10,7 +10,7 @@
{%- endif -%}
{%- endfor -%}
{%- for b in m.bases -%}
-{%- if b!='PlCoreBase' and 'Mixin' not in b -%}
+{%- if b!='XOSBase' and 'Mixin' not in b -%}
#from core.models.{{b | lower}} import {{ b }}
from core.models import {{ b }}
{%- endif -%}
@@ -20,7 +20,7 @@
{% for m in proto.messages %}
-class {{ m.name }}{{ xproto_base_def(m.bases) }}:
+class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}:
KIND = {{ xproto_first_non_empty([m.options.kind, options.kind, options.name, "Set a kind in your xproto!"]) }}
diff --git a/xos/genx/tool/lib.py b/xos/genx/tool/lib.py
index 1e0cf4d..6a5409b 100644
--- a/xos/genx/tool/lib.py
+++ b/xos/genx/tool/lib.py
@@ -62,8 +62,10 @@
else:
return 'TextField'
-def xproto_base_def(base):
- if (not base):
+def xproto_base_def(model_name, base):
+ if (model_name=='XOSBase'):
+ return '(models.Model, PlModelMixIn)'
+ elif (not base):
return ''
else:
return '(' + ','.join(base) + ')'
@@ -137,7 +139,7 @@
return ', '.join(lst)
def map_xproto_to_django(f):
- allowed_keys=['help_text','default','max_length','modifier','blank','choices','db_index','null','editable','on_delete','verbose_name']
+ allowed_keys=['help_text','default','max_length','modifier','blank','choices','db_index','null','editable','on_delete','verbose_name', 'auto_now_add']
m = {'modifier':{'optional':True, 'required':False, '_target':'null'}}
out = {}
@@ -183,7 +185,7 @@
if (n.startswith('NetworkParameter')):
return '_'
- expr = r'^[A-Z][a-z]+'
+ expr = r'^[A-Z]+[a-z]*'
try:
match = re.findall(expr, n)[0]
diff --git a/xos/genx/tool/tests/counts b/xos/genx/tool/tests/counts
index c08e39b..8ab44d4 100755
--- a/xos/genx/tool/tests/counts
+++ b/xos/genx/tool/tests/counts
@@ -2,7 +2,7 @@
import core.models
import inspect
-from core.models import PlCoreBase, PlModelMixIn
+from core.models import XOSBase, PlModelMixIn
import pdb
def count(lst):
@@ -21,7 +21,7 @@
return False
bases = inspect.getmro(model)
bases = [x.__name__ for x in bases]
- if ("PlCoreBase" in bases) or ("PlModelMixIn" in bases):
+ if ("XOSBase" in bases) or ("PlModelMixIn" in bases):
return True
return False
diff --git a/xos/genx/tool/tests/django_generator_test.py b/xos/genx/tool/tests/django_generator_test.py
index 4ea339a..052a48f 100644
--- a/xos/genx/tool/tests/django_generator_test.py
+++ b/xos/genx/tool/tests/django_generator_test.py
@@ -5,7 +5,7 @@
def test_proto_generator(self):
xproto = \
"""
-message VRouterPort (PlCoreBase){
+message VRouterPort (XOSBase){
optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True];
required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False];
required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False];
@@ -27,7 +27,7 @@
{%- endfor %}
{% for b in m.bases %}
-{% if b!='PlCoreBase' and 'Mixin' not in b%}
+{% if b!='XOSBase' and 'Mixin' not in b%}
from core.models.{{b | lower}} import {{ b }}
{% endif %}
{% endfor %}
diff --git a/xos/genx/tool/tests/proto_generator_test.py b/xos/genx/tool/tests/proto_generator_test.py
index b36f109..f9c2d69 100644
--- a/xos/genx/tool/tests/proto_generator_test.py
+++ b/xos/genx/tool/tests/proto_generator_test.py
@@ -9,7 +9,7 @@
def __disabled_test_proto_generator(self):
xproto = \
"""
-message VRouterPort (PlCoreBase){
+message VRouterPort (XOSBase){
optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True];
required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False];
required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False];
diff --git a/xos/genx/tool/tests/pure_proto_test.py b/xos/genx/tool/tests/pure_proto_test.py
index 8402c93..e6153a3 100644
--- a/xos/genx/tool/tests/pure_proto_test.py
+++ b/xos/genx/tool/tests/pure_proto_test.py
@@ -5,7 +5,7 @@
def test_pure_proto(self):
xproto = \
"""
-message VRouterPort (PlCoreBase){
+message VRouterPort (XOSBase){
optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True];
required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False];
required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False];
@@ -16,7 +16,7 @@
proto = \
"""
message VRouterPort {
- option bases = "PlCoreBase";
+ option bases = "XOSBase";
optional string name = 1 [ null = "True", max_length = "20", blank = "True", help_text = "port friendly name", modifier = "optional", db_index = "False" ];
required string openflow_id = 2 [ null = "False", max_length = "21", blank = "False", help_text = "port identifier in ONOS", modifier = "required", db_index = "False" ];
required int32 vrouter_device = 3 [ null = "False", blank = "False", model = "VRouterDevice", modifier = "required", type = "link", port = "ports", db_index = "True", link = "manytoone"];
@@ -38,7 +38,7 @@
{%- endfor %}
{% for b in m.bases %}
-{% if b!='PlCoreBase' and 'Mixin' not in b%}
+{% if b!='XOSBase' and 'Mixin' not in b%}
from core.models.{{b | lower}} import {{ b }}
{% endif %}
{% endfor %}
diff --git a/xos/services/syndicate_storage/models.py b/xos/services/syndicate_storage/models.py
index 6ea9c41..ccaf813 100644
--- a/xos/services/syndicate_storage/models.py
+++ b/xos/services/syndicate_storage/models.py
@@ -1,4 +1,4 @@
-from core.models import User,Site,Service,PlCoreBase,Slice,SlicePrivilege
+from core.models import User,Site,Service,XOSBase,Slice,SlicePrivilege
import os
from django.db import models
from django.db.models import Q
@@ -16,7 +16,7 @@
def __unicode__(self): return u'Syndicate Service'
-class SyndicatePrincipal(PlCoreBase):
+class SyndicatePrincipal(XOSBase):
class Meta:
app_label = "syndicate_storage"
@@ -28,7 +28,7 @@
def __unicode__self(self): return "%s" % self.principal_id
-class Volume(PlCoreBase):
+class Volume(XOSBase):
class Meta:
app_label = "syndicate_storage"
@@ -64,7 +64,7 @@
return qs
-class VolumeAccessRight(PlCoreBase):
+class VolumeAccessRight(XOSBase):
class Meta:
app_label = "syndicate_storage"
@@ -171,7 +171,7 @@
raise syndicatelib.SyndicateObserverError( "Internal Syndicate Observer error: No slice secret generated" )
-class SliceSecret(models.Model): # NOTE: not a PlCoreBase
+class SliceSecret(models.Model): # NOTE: not a XOSBase
class Meta:
app_label = "syndicate_storage"
@@ -195,7 +195,7 @@
return qs
-class VolumeSlice(PlCoreBase):
+class VolumeSlice(XOSBase):
class Meta:
app_label = "syndicate_storage"
diff --git a/xos/synchronizers/ec2/dmdot b/xos/synchronizers/ec2/dmdot
index de07a78..9b2b587 100644
--- a/xos/synchronizers/ec2/dmdot
+++ b/xos/synchronizers/ec2/dmdot
@@ -21,7 +21,7 @@
model_classes = []
class_names = []
for c in g.values():
- if type(c)==type(PlCoreBase):
+ if type(c)==type(XOSBase):
model_classes.append(c)
class_names.append(c.__name__)
diff --git a/xos/synchronizers/new_base/modelaccessor.py b/xos/synchronizers/new_base/modelaccessor.py
index 9b9e657..51c326e 100644
--- a/xos/synchronizers/new_base/modelaccessor.py
+++ b/xos/synchronizers/new_base/modelaccessor.py
@@ -94,7 +94,7 @@
for (k, v) in model_accessor.all_model_classes.items():
globals()[k] = v
- # plcorebase doesn't exist from the synchronizer's perspective, so fake out
+ # xosbase doesn't exist from the synchronizer's perspective, so fake out
# ModelLink.
if "ModelLink" not in globals():
class ModelLink:
diff --git a/xos/tools/apigen/modelgen b/xos/tools/apigen/modelgen
index 7ef76a4..215feb9 100755
--- a/xos/tools/apigen/modelgen
+++ b/xos/tools/apigen/modelgen
@@ -22,7 +22,7 @@
django.setup()
-from core.models import PlCoreBase
+from core.models import XOSBase
options = None
@@ -34,7 +34,7 @@
return False
bases = inspect.getmro(model)
bases = [x.__name__ for x in bases]
- if ("PlCoreBase" in bases) or ("PlModelMixIn" in bases):
+ if ("XOSBase" in bases) or ("PlModelMixIn" in bases):
return True
return False
@@ -127,7 +127,6 @@
self.refs = []
self.reverse_refs = []
self.plural_name = None
- self.content_type_id = ContentType.objects.get_for_model(m).id
def plural(self):
if (self.plural_name):
@@ -204,7 +203,7 @@
self[str(obj).lower()]=obj
def compute_links(self):
- base_props = [f.name for f in PlCoreBase._meta.fields]
+ base_props = [f.name for f in XOSBase._meta.fields]
for obj in self.values():
#if (str(obj)=='network'):
@@ -290,9 +289,9 @@
parser.add_option("-a", "--app", dest="apps",
help="list of applications to parse", metavar="APP", default=[], action="append")
parser.add_option("-b", "--blacklist", dest="blacklist",
- help="add model name to blacklist", metavar="MODEL", default=["SingletonModel", "PlCoreBase"], action="append")
+ help="add model name to blacklist", metavar="MODEL", default=["SingletonModel", "XOSBase"], action="append")
parser.add_option("-n", "--no-rest", dest="norest",
- help="do not generate rest api for model", metavar="MODEL", default=["SingletonModel", "PlCoreBase"], action="append")
+ help="do not generate rest api for model", metavar="MODEL", default=["SingletonModel", "XOSBase"], action="append")
(options, args) = parser.parse_args(sys.argv[1:])
diff --git a/xos/tools/apigen/modelgen2 b/xos/tools/apigen/modelgen2
index b78719a..5620f9f 100755
--- a/xos/tools/apigen/modelgen2
+++ b/xos/tools/apigen/modelgen2
@@ -24,7 +24,7 @@
django.setup()
-from core.models import PlCoreBase
+from core.models import XOSBase
options = None
@@ -37,7 +37,7 @@
return False
bases = inspect.getmro(model)
bases = [x.__name__ for x in bases]
- if ("PlCoreBase" in bases) or ("PlModelMixIn" in bases):
+ if ("XOSBase" in bases) or ("PlModelMixIn" in bases):
return True
return False
@@ -307,9 +307,9 @@
parser.add_option("-a", "--app", dest="apps",
help="list of applications to parse", metavar="APP", default=[], action="append")
parser.add_option("-b", "--blacklist", dest="blacklist",
- help="add model name to blacklist", metavar="MODEL", default=["SingletonModel", "PlCoreBase"], action="append")
+ help="add model name to blacklist", metavar="MODEL", default=["SingletonModel", "XOSBase"], action="append")
parser.add_option("-n", "--no-rest", dest="norest",
- help="do not generate rest api for model", metavar="MODEL", default=["SingletonModel", "PlCoreBase"], action="append")
+ help="do not generate rest api for model", metavar="MODEL", default=["SingletonModel", "XOSBase"], action="append")
parser.add_option("-l", "--local", dest="local",
help="skip base models", metavar="MODEL", default=False, action="store_true")
(options, args) = parser.parse_args(sys.argv[1:])
diff --git a/xos/tools/dmdot b/xos/tools/dmdot
index 9cde0ed..d0e6566 100755
--- a/xos/tools/dmdot
+++ b/xos/tools/dmdot
@@ -44,15 +44,15 @@
#models_module = imp.load_source(app, ".")
models_module = __import__(app)
for part in app.split(".")[1:]:
- if hasattr(models_module, "PlCoreBase"):
+ if hasattr(models_module, "XOSBase"):
break
models_module = getattr(models_module,part)
- PlCoreBase = getattr(models_module,"PlCoreBase")
+ XOSBase = getattr(models_module,"XOSBase")
for classname in dir(models_module):
c = getattr(models_module, classname, None)
- if type(c)==type(PlCoreBase):
+ if type(c)==type(XOSBase):
model_classes.append(c)
class_names.append(c.__name__)
lower_class_names[c.__name__.lower()] = c
diff --git a/xos/tools/mldeps b/xos/tools/mldeps
index c4dc68a..12a0edc 100755
--- a/xos/tools/mldeps
+++ b/xos/tools/mldeps
@@ -46,15 +46,15 @@
#models_module = imp.load_source(app, ".")
models_module = __import__(app)
for part in app.split(".")[1:]:
- if hasattr(models_module, "PlCoreBase"):
+ if hasattr(models_module, "XOSBase"):
break
models_module = getattr(models_module,part)
- PlCoreBase = getattr(models_module,"PlCoreBase")
+ XOSBase = getattr(models_module,"XOSBase")
for classname in dir(models_module):
c = getattr(models_module, classname, None)
- if type(c)==type(PlCoreBase):
+ if type(c)==type(XOSBase):
model_classes.append(c)
class_names.append(c.__name__)
lower_class_names[c.__name__.lower()] = c