add ability to specify tenant model
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index 9202ff4..e8c360a 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -102,7 +102,11 @@
service_specific_attribute:
type: string
required: false
- description: Service-specific attribute, usually a string containing a json structure
+ description: Service-specific attribute, usually a string containing a json dictionary
+ model:
+ type: string
+ required: false
+ description: Name of model to use when instantiating tenant
tosca.nodes.ONOSService:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index 83ec418..1e60606 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -77,7 +77,11 @@
service_specific_attribute:
type: string
required: false
- description: Service-specific attribute, usually a string containing a json structure
+ description: Service-specific attribute, usually a string containing a json dictionary
+ model:
+ type: string
+ required: false
+ description: Name of model to use when instantiating tenant
tosca.nodes.ONOSService:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/resources/tenant.py b/xos/tosca/resources/tenant.py
index 8821ae2..bc1b6d2 100644
--- a/xos/tosca/resources/tenant.py
+++ b/xos/tosca/resources/tenant.py
@@ -1,3 +1,4 @@
+import importlib
import os
import pdb
import sys
@@ -32,6 +33,26 @@
return [ self.get_xos_object(provider_service=provider_service) ]
return []
+ def create(self):
+ model_class = self.get_property("model")
+ if model_class:
+ model_name = ".".join(model_class.split(".")[:-1])
+ class_name = model_class.split(".")[-1]
+ print "XXX", model_name, class_name
+ module = importlib.import_module(model_name)
+ xos_model = getattr(module, class_name)
+ else:
+ xos_model = self.xos_model
+
+ xos_args = self.get_xos_args()
+ xos_obj = xos_model(**xos_args)
+ xos_obj.caller = self.user
+ xos_obj.save()
+
+ self.info("Created %s '%s'" % (self.xos_model.__name__,str(xos_obj)))
+
+ self.postprocess(xos_obj)
+
def postprocess(self, obj):
pass