add colocate option, use flavor selector
diff --git a/xos/tosca/resources/compute.py b/xos/tosca/resources/compute.py
index 3040721..2e5bc94 100644
--- a/xos/tosca/resources/compute.py
+++ b/xos/tosca/resources/compute.py
@@ -8,6 +8,7 @@
 from core.models import Slice,Sliver,User,Flavor,Node,Image
 from nodeselect import XOSNodeSelector
 from imageselect import XOSImageSelector
+from flavorselect import XOSFlavorSelector
 
 from xosresource import XOSResource
 
@@ -15,15 +16,14 @@
     provides = "tosca.nodes.Compute"
     xos_model = Sliver
 
-    def select_compute_node(self, user, v):
+    def select_compute_node(self, user, v, hostname=None):
         mem_size = v.get_property_value("mem_size")
         num_cpus = v.get_property_value("num_cpus")
         disk_size = v.get_property_value("disk_size")
 
-        # TODO: pick flavor based on parameters
-        flavor = Flavor.objects.get(name="m1.small")
+        flavor = XOSFlavorSelector(user, mem_size=mem_size, num_cpus=num_cpus, disk_size=disk_size).get_flavor()
 
-        compute_node = XOSNodeSelector(user, mem_size=mem_size, num_cpus=num_cpus, disk_size=disk_size).get_nodes(1)[0]
+        compute_node = XOSNodeSelector(user, mem_size=mem_size, num_cpus=num_cpus, disk_size=disk_size, hostname=hostname).get_nodes(1)[0]
 
         return (compute_node, flavor)
 
@@ -35,7 +35,7 @@
 
         return XOSImageSelector(user, distribution=distribution, version=version, type=type, architecture=architecture).get_image()
 
-    def get_xos_args(self, name=None):
+    def get_xos_args(self, name=None, index=None):
         nodetemplate = self.nodetemplate
 
         if not name:
@@ -48,10 +48,20 @@
         sliceName = self.get_requirement("tosca.relationships.MemberOfSlice", throw_exception=True)
         slice = self.get_xos_object(Slice, name=sliceName)
 
+        # locate it one the same host as some other sliver
+        colocate_host = None
+        colocate_sliver_name = self.get_requirement("tosca.relationships.SameHost")
+        if index is not None:
+            colocate_sliver_name = "%s-%d" % (colocate_sliver_name, index)
+        colocate_slivers = Sliver.objects.filter(name=colocate_sliver_name)
+        if colocate_slivers:
+            colocate_host = colocate_slivers[0].node.name
+            self.info("colocating on %s" % colocate_host)
+
         capabilities = nodetemplate.get_capabilities()
         for (k,v) in capabilities.items():
             if (k=="host"):
-                (compute_node, flavor) = self.select_compute_node(self.user, v)
+                (compute_node, flavor) = self.select_compute_node(self.user, v, hostname=colocate_host)
             elif (k=="os"):
                 image = self.select_image(self.user, v)
 
@@ -84,7 +94,7 @@
             default_instances = scalable.get("default_instances",1)
             for i in range(0, default_instances):
                 name = "%s-%d" % (self.nodetemplate.name, i)
-                existing_slivers = Sliver.objects.filter(name=name)
+                existing_slivers = Sliver.objects.filter(name=name, index=i)
                 if existing_slivers:
                     self.info("%s %s already exists" % (self.xos_model.__name__, name))
                     self.update(existing_slivers[0])