add Tag object to Tosca
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index 4879584..a4b1b05 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -849,6 +849,21 @@
required: false
description: URL to the dashboard
+ tosca.nodes.Tag:
+ derived_from: tosca.nodes.Root
+ description: >
+ An XOS Tag
+ properties:
+ xos_base_props
+ name:
+ type: string
+ required: true
+ descrption: name of tag
+ value:
+ type: string
+ required: false
+ descrption: value of tag
+
tosca.nodes.Compute.Container:
derived_from: tosca.nodes.Compute
description: >
@@ -985,6 +1000,9 @@
tosca.relationships.DependsOn:
derived_from: tosca.relationships.Root
+ tosca.relationships.TagsObject:
+ derived_from: tosca.relationships.Root
+
tosca.capabilities.xos.Service:
derived_from: tosca.capabilities.Root
description: An XOS Service
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index fda4182..8c15379 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -1348,6 +1348,32 @@
required: false
description: URL to the dashboard
+ tosca.nodes.Tag:
+ derived_from: tosca.nodes.Root
+ description: >
+ An XOS Tag
+ properties:
+ no-delete:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to delete this object
+ no-create:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to create this object
+ no-update:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to update this object
+ name:
+ type: string
+ required: true
+ descrption: name of tag
+ value:
+ type: string
+ required: false
+ descrption: value of tag
+
tosca.nodes.Compute.Container:
derived_from: tosca.nodes.Compute
description: >
@@ -1484,6 +1510,9 @@
tosca.relationships.DependsOn:
derived_from: tosca.relationships.Root
+ tosca.relationships.TagsObject:
+ derived_from: tosca.relationships.Root
+
tosca.capabilities.xos.Service:
derived_from: tosca.capabilities.Root
description: An XOS Service
diff --git a/xos/tosca/resources/tag.py b/xos/tosca/resources/tag.py
new file mode 100644
index 0000000..76d41cd
--- /dev/null
+++ b/xos/tosca/resources/tag.py
@@ -0,0 +1,53 @@
+import importlib
+import os
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+from django.contrib.contenttypes.models import ContentType
+
+from core.models import Tag
+
+from xosresource import XOSResource
+
+class XOSTag(XOSResource):
+ provides = "tosca.nodes.Tag"
+ xos_model = Tag
+ name_field = None
+ copyin_props = ("name", "value")
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSTag, self).get_xos_args()
+
+ # Find the Tosca object that this Tag is pointing to, and return its
+ # content_type and object_id, which will be used in the GenericForeignKey
+ # django relation.
+
+ target_name = self.get_requirement("tosca.relationships.TagsObject", throw_exception=throw_exception)
+ if target_name:
+ target_model = self.engine.name_to_xos_model(self.user, target_name)
+ args["content_type"] = ContentType.objects.get_for_model(target_model)
+ args["object_id"] = target_model.id
+
+ # To uniquely identify a Tag, we must know the object that it is attached
+ # to as well as the name of the Tag.
+
+ if ("content_type" not in args) or ("object_id" not in args) or ("name" not in args):
+ if throw_exception:
+ raise Exception("Tag must specify TagsObject requirement and Name property")
+
+ return args
+
+ def get_existing_objs(self):
+ args = self.get_xos_args(throw_exception=True)
+
+ return Tag.objects.filter(content_type=args["content_type"],
+ object_id=args["object_id"],
+ name=args["name"])
+
+ def postprocess(self, obj):
+ pass
+
+ def can_delete(self, obj):
+ return super(XOSTag, self).can_delete(obj)
+
diff --git a/xos/tosca/samples/slicetag.yaml b/xos/tosca/samples/slicetag.yaml
new file mode 100644
index 0000000..ec064e3
--- /dev/null
+++ b/xos/tosca/samples/slicetag.yaml
@@ -0,0 +1,35 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Setup CORD-related services -- vOLT, vCPE, vBNG.
+
+imports:
+ - custom_types/xos.yaml
+
+topology_template:
+ node_templates:
+ mysite_vsg:
+ type: tosca.nodes.Slice
+ properties:
+ no-create: True
+ no-delete: True
+ no-update: True
+
+ service_vsg:
+ type: tosca.nodes.Service
+ properties:
+ no-create: True
+ no-delete: True
+ no-update: True
+
+ mysite_vsg_foobar_tag:
+ type: tosca.nodes.Tag
+ properties:
+ name: foobar
+ value: xyz
+ requirements:
+ - target:
+ node: mysite_vsg
+ relationship: tosca.relationships.TagsObject
+ - service:
+ node: service_vsg
+ relationship: tosca.relationships.MemberOfService