now supporting xos.yaml custom template and treating the slice as a requirement
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
new file mode 100644
index 0000000..95fe2dc
--- /dev/null
+++ b/xos/tosca/custom_types/xos.yaml
@@ -0,0 +1,14 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+node_types:
+    tosca.nodes.Slice:
+        derived_from: tosca.nodes.Root
+        properties:
+#            site:
+#                type: string
+#                required: true
+        
+    tosca.relationships.MemberOfSlice:
+        derived_from: tosca.relationships.Root
+
+    
\ No newline at end of file
diff --git a/xos/tosca/execute.py b/xos/tosca/execute.py
index 5511ae8..c9b5bfe 100644
--- a/xos/tosca/execute.py
+++ b/xos/tosca/execute.py
@@ -9,9 +9,15 @@
 from nodeselect import XOSNodeSelector
 
 class XOSTosca(object):
-    def __init__(self, tosca_yaml):
+    def __init__(self, tosca_yaml, parent_dir=None):
+        # TOSCA will look for imports using a relative path from where the
+        # template file is located, so we have to put the template file
+        # in a specific place.
+        if not parent_dir:
+            parent_dir = os.getcwd()
+
         try:
-            (tmp_handle, tmp_pathname) = tempfile.mkstemp()
+            (tmp_handle, tmp_pathname) = tempfile.mkstemp(dir=parent_dir)
             os.write(tmp_handle, tosca_yaml)
             os.close(tmp_handle)
 
@@ -51,21 +57,32 @@
         return Image.objects.get(name="Ubuntu-14.04-LTS")    # demo
 
     def execute_nodetemplate(self, user, nodetemplate):
+        if (nodetemplate.type == "tosca.nodes.Slice"):
+            return
+
         if (nodetemplate.type != "tosca.nodes.Compute"):
-             raise Exception("I Don't know how to deal with %s" % type)
+            raise Exception("I Don't know how to deal with %s" % nodetemplate.type)
 
         host=None
         flavor=None
         image=None
 
-        sliceName = None
-        artifacts = nodetemplate.entity_tpl.get("artifacts",[])
-        for artifact in artifacts:
-            if artifact.get("xos_slice", None):
-                 sliceName = artifact["xos_slice"]
-
+        sliceName  = None
+        for reqs in nodetemplate.requirements:
+            for (k,v) in reqs.items():
+                print v
+                if (v["relationship"] == "tosca.relationships.MemberOfSlice"):
+                    sliceName = v["node"]
         if not sliceName:
-             raise Exception("No xos_slice artifact for node %s" % nodetemplate.name)
+             raise Exception("No slice requirement for node %s" % nodetemplate.name)
+
+        #sliceName = None
+        #artifacts = nodetemplate.entity_tpl.get("artifacts",[])
+        #for artifact in artifacts:
+        #    if artifact.get("xos_slice", None):
+        #         sliceName = artifact["xos_slice"]
+        #if not sliceName:
+        #     raise Exception("No xos_slice artifact for node %s" % nodetemplate.name)
 
         slice = Slice.objects.filter(name=sliceName)
         if not slice:
diff --git a/xos/tosca/nodeselect.py b/xos/tosca/nodeselect.py
new file mode 100644
index 0000000..f139de7
--- /dev/null
+++ b/xos/tosca/nodeselect.py
@@ -0,0 +1,23 @@
+import os
+import sys
+
+sys.path.append("/opt/xos")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
+import django
+django.setup()
+from core.models import Slice,Sliver,User,Flavor,Node,Image
+
+class XOSNodeSelector(object):
+    def __init__(self, user):
+        self.user = user
+
+    def get_allowed_nodes(self):
+        # TODO: logic to get nodes that the user can use
+        nodes = Node.objects.all()
+        return nodes
+
+    def get_nodes(self, quantity):
+        nodes = self.get_allowed_nodes()
+        # TODO: sort the nodes by some useful metric to pick the best one
+        return nodes[:quantity]
+
diff --git a/xos/tosca/run.py b/xos/tosca/run.py
index a4a7407..492b12a 100644
--- a/xos/tosca/run.py
+++ b/xos/tosca/run.py
@@ -15,39 +15,16 @@
 from tosca.execute import XOSTosca
 
 def main():
-    django.setup()
+    if len(sys.argv)<3:
+        print "Syntax: run.py <username> <yaml-template-name>"
+        sys.exit(-1)
 
-    sample = """tosca_definitions_version: tosca_simple_yaml_1_0
+    username = sys.argv[1]
+    template_name = sys.argv[2]
 
-description: Template for deploying a single server with predefined properties.
+    u = User.objects.get(email=username)
 
-topology_template:
-  node_templates:
-    my_server:
-      type: tosca.nodes.Compute
-      capabilities:
-        # Host container properties
-        host:
-         properties:
-           num_cpus: 1
-           disk_size: 10 GB
-           mem_size: 4 MB
-        # Guest Operating System properties
-        os:
-          properties:
-            # host Operating System image properties
-            architecture: x86_64
-            type: linux
-            distribution: rhel
-            version: 6.5
-      artifacts:
-          - xos_slice: mysite_tosca
-            type: tosca.artifacts.Deployment
-
-"""
-    u = User.objects.get(email="scott@onlab.us")
-
-    xt = XOSTosca(sample)
+    xt = XOSTosca(file(template_name).read(), parent_dir=currentdir)
     xt.execute(u)
 
 if __name__=="__main__":
diff --git a/xos/tosca/samples/one_instance.yaml b/xos/tosca/samples/one_instance.yaml
new file mode 100644
index 0000000..968c999
--- /dev/null
+++ b/xos/tosca/samples/one_instance.yaml
@@ -0,0 +1,33 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Template for deploying a single server with predefined properties.
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    mysite_tosca:
+      type: tosca.nodes.Slice
+
+    my_server:
+      type: tosca.nodes.Compute
+      capabilities:
+        # Host container properties
+        host:
+         properties:
+           num_cpus: 1
+           disk_size: 10 GB
+           mem_size: 4 MB
+        # Guest Operating System properties
+        os:
+          properties:
+            # host Operating System image properties
+            architecture: x86_64
+            type: linux
+            distribution: rhel
+            version: 6.5
+      requirements:
+          - slice:
+                node: mysite_tosca
+                relationship: tosca.relationships.MemberOfSlice