add support for short-form Controller specification
diff --git a/xos/onboard/exampleservice/exampleservice-onboard-longform.yaml b/xos/onboard/exampleservice/exampleservice-onboard-longform.yaml
new file mode 100644
index 0000000..0eddd51
--- /dev/null
+++ b/xos/onboard/exampleservice/exampleservice-onboard-longform.yaml
@@ -0,0 +1,57 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Onboard the exampleservice
+
+imports:
+ - custom_types/xos.yaml
+
+topology_template:
+ node_templates:
+ exampleservice:
+ type: tosca.nodes.ServiceController
+ properties:
+ base_url: file:/opt/xos/onboard/exampleservice/
+
+ exampleservice_models:
+ type: tosca.nodes.ServiceControllerResource
+ properties:
+ kind: models
+ format: python
+ url: models.py
+ requirements:
+ - controller:
+ node: exampleservice
+ relationship: tosca.relationships.UsedByController
+
+ exampleservice_admin:
+ type: tosca.nodes.ServiceControllerResource
+ properties:
+ kind: admin
+ format: python
+ url: admin.py
+ requirements:
+ - controller:
+ node: exampleservice
+ relationship: tosca.relationships.UsedByController
+
+ exampleservice_synchronizer:
+ type: tosca.nodes.ServiceControllerResource
+ properties:
+ kind: synchronizer
+ format: manifest
+ url: synchronizer/manifest
+ requirements:
+ - controller:
+ node: exampleservice
+ relationship: tosca.relationships.UsedByController
+
+ exampleservice_tosca_types:
+ type: tosca.nodes.ServiceControllerResource
+ properties:
+ kind: tosca_custom_types
+ format: yaml
+ url: exampleservice.yaml
+ requirements:
+ - controller:
+ node: exampleservice
+ relationship: tosca.relationships.UsedByController
diff --git a/xos/onboard/exampleservice/exampleservice-onboard.yaml b/xos/onboard/exampleservice/exampleservice-onboard.yaml
index 25f2a31..67413d0 100644
--- a/xos/onboard/exampleservice/exampleservice-onboard.yaml
+++ b/xos/onboard/exampleservice/exampleservice-onboard.yaml
@@ -11,36 +11,9 @@
type: tosca.nodes.ServiceController
properties:
base_url: file:/opt/xos/onboard/exampleservice/
-
- exampleservice_models:
- type: tosca.nodes.ServiceControllerResource
- properties:
- kind: models
- format: python
- url: models.py
- requirements:
- - controller:
- node: exampleservice
- relationship: tosca.relationships.UsedByController
-
- exampleservice_admin:
- type: tosca.nodes.ServiceControllerResource
- properties:
- kind: admin
- format: python
- url: admin.py
- requirements:
- - controller:
- node: exampleservice
- relationship: tosca.relationships.UsedByController
-
- exampleservice_synchronizer:
- type: tosca.nodes.ServiceControllerResource
- properties:
- kind: synchronizer
- format: manifest
- url: synchronizer/manifest
- requirements:
- - controller:
- node: exampleservice
- relationship: tosca.relationships.UsedByController
+ # The following will concatenate with base_url automatically, if
+ # base_url is non-null.
+ models: models.py
+ admin: admin.py
+ synchronizer: manifest
+ tosca_custom_types: exampleservice.yaml
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index 93aeb33..c8c48bf 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -31,6 +31,22 @@
type: string
required: false
description: Base url, to allow resources to use relative URLs
+ models:
+ type: string
+ required: false
+ description: url of models.py
+ admin:
+ type: string
+ required: false
+ description: url of admin.py
+ synchronizer:
+ type: string
+ required: false
+ description: url of synchronizer manifest
+ tosca_custom_types:
+ type: string
+ required: false
+ description: url of tosca custom_types
tosca.nodes.ServiceControllerResource:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index 9e2042b..0d94afa 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -109,6 +109,22 @@
type: string
required: false
description: Base url, to allow resources to use relative URLs
+ models:
+ type: string
+ required: false
+ description: url of models.py
+ admin:
+ type: string
+ required: false
+ description: url of admin.py
+ synchronizer:
+ type: string
+ required: false
+ description: url of synchronizer manifest
+ tosca_custom_types:
+ type: string
+ required: false
+ description: url of tosca custom_types
tosca.nodes.ServiceControllerResource:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/resources/servicecontroller.py b/xos/tosca/resources/servicecontroller.py
index a32d1cc..bde588f 100644
--- a/xos/tosca/resources/servicecontroller.py
+++ b/xos/tosca/resources/servicecontroller.py
@@ -5,7 +5,7 @@
sys.path.append("/opt/tosca")
from translator.toscalib.tosca_template import ToscaTemplate
-from core.models import ServiceController
+from core.models import ServiceController, ServiceControllerResource
from xosresource import XOSResource
@@ -14,5 +14,25 @@
xos_model = ServiceController
copyin_props = ["base_url"]
+ def postprocess_resource_prop(self, obj, kind, format):
+ value = self.get_property(kind)
+ if value:
+ scr = ServiceControllerResource.objects.filter(service_controller=obj, kind=kind, format=format)
+ if scr:
+ scr=scr[0]
+ if scr.url != value:
+ self.info("updating resource %s" % kind)
+ scr.url = value
+ scr.save()
+ else:
+ self.info("adding resource %s" % kind)
+ scr = ServiceControllerResource(service_controller=obj, name=kind, kind=kind, format=format, url=value)
+ scr.save()
+ def postprocess(self, obj):
+ # allow these common resource to be specified directly by the ServiceController tosca object
+ self.postprocess_resource_prop(obj, "models", "python")
+ self.postprocess_resource_prop(obj, "admin", "python")
+ self.postprocess_resource_prop(obj, "tosca_custom_types", "yaml")
+ self.postprocess_resource_prop(obj, "synchronizer", "manifest")