onos resources and sample
diff --git a/xos/tosca/resources/onosapp.py b/xos/tosca/resources/onosapp.py
new file mode 100644
index 0000000..50af543
--- /dev/null
+++ b/xos/tosca/resources/onosapp.py
@@ -0,0 +1,57 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from core.models import User, TenantAttribute
+from services.onos.models import ONOSApp, ONOSService
+
+from xosresource import XOSResource
+
+class XOSONOSApp(XOSResource):
+    provides = ["tosca.nodes.ONOSApp", "tosca.nodes.ONOSvBNGApp"]
+    xos_model = ONOSApp
+    copyin_props = ["service_specific_id"]
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSONOSApp, self).get_xos_args()
+
+        provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=throw_exception)
+        if provider_name:
+            args["provider_service"] = self.get_xos_object(ONOSService, throw_exception=throw_exception, name=provider_name)
+
+        return args
+
+    def get_existing_objs(self):
+        objs = ONOSApp.get_tenant_objects().all()
+        objs = [x for x in objs if x.name == self.nodetemplate.name]
+        return objs
+
+    def set_tenant_attr(self, obj, prop_name, value):
+        value = self.try_intrinsic_function(value)
+        if value:
+            attrs = TenantAttribute.objects.filter(tenant=obj, name=prop_name)
+            if attrs:
+                attr = attrs[0]
+                if attr.value != value:
+                    self.info("updating attribute %s" % k)
+                    attrs.value = value
+                    attrs.save()
+            else:
+                self.info("adding attribute %s" % prop_name)
+                ta = TenantAttribute(tenant=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_tenant_attr(obj, k, v)
+
+    def can_delete(self, obj):
+        return super(XOSONOSApp, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/onosservice.py b/xos/tosca/resources/onosservice.py
new file mode 100644
index 0000000..1275fab
--- /dev/null
+++ b/xos/tosca/resources/onosservice.py
@@ -0,0 +1,16 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from services.onos.models import ONOSService
+
+from service import XOSService
+
+class XOSONOSService(XOSService):
+    provides = "tosca.nodes.ONOSService"
+    xos_model = ONOSService
+    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber"]
+
diff --git a/xos/tosca/samples/onos.yaml b/xos/tosca/samples/onos.yaml
new file mode 100644
index 0000000..0c5c34d
--- /dev/null
+++ b/xos/tosca/samples/onos.yaml
@@ -0,0 +1,54 @@
+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:
+    service_onos:
+      type: tosca.nodes.ONOSService
+      requirements:
+      properties:
+          kind: onos
+          view_url: /admin/onos/onosservice/$id$/
+
+    vBNG:
+      type: tosca.nodes.ONOSvBNGApp
+      requirements:
+          - onos_tenant:
+              node: service_onos
+              relationship: tosca.relationships.TenantOfService
+      properties:
+          config_addresses_json: >
+            {
+                "addresses" : [

+                            {

+                                "dpid" : "00:00:00:00:00:00:00:a1",

+                                "port" : "2",

+                                "ips" : ["192.0.0.1/24"],

+                                "mac" : "00:00:00:00:00:99"

+

+                            },

+                            {

+                                "dpid" : "00:00:00:00:00:00:00:a5",

+                                "port" : "4",

+                                "ips" : ["200.0.0.5/24"],

+                                "mac" : "00:00:00:00:00:98"

+                            }

+                ]

+            }
+          config_virtualbng_json: >
+            {
+                "localPublicIpPrefixes" : [

+                    "200.0.0.0/32",

+                    "201.0.0.0/30",

+                    "202.0.0.0/30"

+                ],

+                "nextHopIpAddress" : "200.0.0.5",

+                "publicFacingMac" : "00:00:00:00:00:66",

+                "xosIpAddress" : "10.11.10.1",

+                "xosRestPort" : "9999"

+            }
+