tosca support for service attributes
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index d4e96ce..a806327 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -101,6 +101,10 @@
xos_base_service_caps
properties:
xos_base_service_props
+ rest_onos/v1/network/configuration/:
+ type: string
+ required: false
+
tosca.nodes.ONOSApp:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index 0c20211..3339fdf 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -102,6 +102,10 @@
type: string
required: false
description: Version number of Service.
+ rest_onos/v1/network/configuration/:
+ type: string
+ required: false
+
tosca.nodes.ONOSApp:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/resources/onosservice.py b/xos/tosca/resources/onosservice.py
index 1275fab..b742ebb 100644
--- a/xos/tosca/resources/onosservice.py
+++ b/xos/tosca/resources/onosservice.py
@@ -5,6 +5,7 @@
sys.path.append("/opt/tosca")
from translator.toscalib.tosca_template import ToscaTemplate
+from core.models import ServiceAttribute
from services.onos.models import ONOSService
from service import XOSService
@@ -14,3 +15,27 @@
xos_model = ONOSService
copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber"]
+ def set_service_attr(self, obj, prop_name, value):
+ value = self.try_intrinsic_function(value)
+ if value:
+ attrs = ServiceAttribute.objects.filter(service=obj, name=prop_name)
+ if attrs:
+ attr = attrs[0]
+ if attr.value != value:
+ self.info("updating attribute %s" % prop_name)
+ attr.value = value
+ attr.save()
+ else:
+ self.info("adding attribute %s" % prop_name)
+ ta = ServiceAttribute(service=obj, name=prop_name, value=value)
+ ta.save()
+
+ def postprocess(self, obj):
+ props = self.nodetemplate.get_properties()
+ for (k,d) in props.items():
+ v = d.value
+ if k.startswith("config_"):
+ self.set_service_attr(obj, k, v)
+ elif k.startswith("rest_"):
+ self.set_service_attr(obj, k, v)
+