resources for deployment, site, and controller
diff --git a/xos/tosca/resources/controller.py b/xos/tosca/resources/controller.py
new file mode 100644
index 0000000..d5dc4b7
--- /dev/null
+++ b/xos/tosca/resources/controller.py
@@ -0,0 +1,47 @@
+# note: this module named xossite.py instead of site.py due to conflict with
+#    /usr/lib/python2.7/site.py
+
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from core.models import User,Controller,Deployment
+
+from xosresource import XOSResource
+
+class XOSController(XOSResource):
+    provides = "tosca.nodes.Controller"
+    xos_model = Controller
+
+    def get_xos_args(self):
+        args = {"name": self.nodetemplate.name}
+
+        deployment_name = self.get_requirement("tosca.relationships.ControllerDeployment")
+        if deployment_name:
+            args["deployment"] = self.get_xos_object(Deployment, name=deployment_name)
+
+        return args
+
+    def create(self):
+        xos_args = self.get_xos_args()
+
+        if not xos_args.get("deployment",None):
+            raise Exception("Controller must have a deployment")
+
+        controller = Controller(**xos_args)
+        controller.caller = self.user
+        controller.save()
+
+        self.info("Created Controller '%s'" % (str(controller), ))
+
+    def delete(self, obj):
+        if obj.controllersite.exists():
+            self.info("Controller %s has active sites; skipping delete" % obj.name)
+            return
+        super(XOSController, self).delete(obj)
+
+
+
diff --git a/xos/tosca/resources/deployment.py b/xos/tosca/resources/deployment.py
new file mode 100644
index 0000000..3524ca0
--- /dev/null
+++ b/xos/tosca/resources/deployment.py
@@ -0,0 +1,43 @@
+# note: this module named xossite.py instead of site.py due to conflict with
+#    /usr/lib/python2.7/site.py
+
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from core.models import User,Deployment
+
+from xosresource import XOSResource
+
+class XOSDeployment(XOSResource):
+    provides = "tosca.nodes.Deployment"
+    xos_model = Deployment
+
+    def get_xos_args(self):
+        args = {"name": self.nodetemplate.name}
+
+        return args
+
+    def create(self):
+        xos_args = self.get_xos_args()
+
+        slice = Deployment(**xos_args)
+        slice.caller = self.user
+        slice.save()
+
+        self.info("Created Deployment '%s'" % (str(slice), ))
+
+    def delete(self, obj):
+        if obj.sites.exists():
+            self.info("Deployment %s has active sites; skipping delete" % obj.name)
+            return
+        #if obj.nodes.exists():
+        #    self.info("Deployment %s has active nodes; skipping delete" % obj.name)
+        #    return
+        super(XOSDeployment, self).delete(obj)
+
+
+
diff --git a/xos/tosca/resources/xossite.py b/xos/tosca/resources/xossite.py
new file mode 100644
index 0000000..7ad5cee
--- /dev/null
+++ b/xos/tosca/resources/xossite.py
@@ -0,0 +1,76 @@
+# note: this module named xossite.py instead of site.py due to conflict with
+#    /usr/lib/python2.7/site.py
+
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from core.models import User,Site,Deployment,Controller,SiteDeployment
+
+from xosresource import XOSResource
+
+class XOSSite(XOSResource):
+    provides = "tosca.nodes.Site"
+    xos_model = Site
+
+    def get_xos_args(self):
+        args = {"login_base": self.nodetemplate.name,
+                "name": self.nodetemplate.name}
+
+        #deployment_name = self.get_requirement("tosca.relationships.SiteDeployment")
+        #if deployment_name:
+        #    args["deployment"] = self.get_xos_object(Deployment, name=deployment_name)
+
+        return args
+
+    def postprocess(self, obj):
+        results = []
+        for reqs in self.nodetemplate.requirements:
+            for (k,v) in reqs.items():
+                if (v["relationship"] == "tosca.relationships.SiteDeployment"):
+                    deployment_name = v["node"]
+                    deployment = self.get_xos_object(Deployment, name=deployment_name)
+
+                    controller_name = None
+                    for sd_req in v["requirements"]:
+                        for (sd_req_k, sd_req_v) in sd_req.items():
+                            if sd_req_v["relationship"] == "tosca.relationship.UsesController":
+                                controller_name = sd_req_v["node"]
+                    if not controller_name:
+                        raise Exception("Controller must be specified in SiteDeployment relationship")
+
+                    controller = self.get_xos_object(Controller, name=controller_name)
+
+                    existing_sitedeps = SiteDeployment.objects.filter(deployment=deployment, site=obj)
+                    if existing_sitedeps:
+                        self.info("SiteDeployment from %s to %s already exists" % (str(obj), str(deployment)))
+                    else:
+                        sitedep = SiteDeployment(deployment=deployment, site=obj, controller=controller)
+                        sitedep.save()
+                        self.info("Created SiteDeployment from %s to %s" % (str(obj), str(deployment)))
+
+    def create(self):
+        nodetemplate = self.nodetemplate
+        siteName = nodetemplate.name
+
+        xos_args = self.get_xos_args()
+
+        site = Site(**xos_args)
+        site.caller = self.user
+        site.save()
+
+        self.postprocess(site)
+
+        self.info("Created Site '%s'" % (str(site), ))
+
+    def delete(self, obj):
+        if obj.slices.exists():
+            self.info("Site %s has active slices; skipping delete" % obj.name)
+            return
+        super(XOSSite, self).delete(obj)
+
+
+