Adapted sync_nodes to controller objects
diff --git a/planetstack/openstack_observer/steps/sync_nodes.py b/planetstack/openstack_observer/steps/sync_nodes.py
index d5edb02..8702a21 100644
--- a/planetstack/openstack_observer/steps/sync_nodes.py
+++ b/planetstack/openstack_observer/steps/sync_nodes.py
@@ -6,7 +6,7 @@
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
 from core.models.node import Node
-from core.models.site import SiteDeployments, Controller
+from core.models.site import SiteDeployments, Controller, ControllerSiteDeployments
 from util.logger import Logger, logging
 
 logger = Logger(level=logging.INFO)
@@ -22,16 +22,24 @@
             return []
 
         # collect local nodes
-        site_deployments = SiteDeployments.objects.all()
+        controllers = Controller.objects.all()
         nodes = Node.objects.all()
         node_hostnames = [node.name for node in nodes]
 
         # fetch all nodes from each controller
-        controllers = Controller.objects.all()
         new_nodes = []
         for controller in controllers:
             try:
-                driver = self.driver.admin_driver(controller=controller)
+            	controller_site_deployments = ControllerSiteDeployments.objects.filter(controller=controller)[0]
+	    except IndexError:
+                raise Exception("Controller %s not bound to any site deployments"%controller.name)
+
+            site_deployment = controller_site_deployments.site_deployment
+            if (not site_deployment):
+                raise Exception('Controller without Site Deployment: %s'%controller.name)
+
+            try:
+                driver = self.driver.admin_driver(controller=controller,tenant='admin')
                 compute_nodes = driver.shell.nova.hypervisors.list()
             except:
                 logger.log_exc("Failed to get nodes from controller %s" % str(controller))
@@ -40,10 +48,9 @@
             for compute_node in compute_nodes:
                 if compute_node.hypervisor_hostname not in node_hostnames:
                     # XX TODO:figure out how to correctly identify a node's site.
-                    # XX pick a random site to add the node to for now
-                    site_index = random.randint(0, len(site_deployments))
+                    # XX pick the first one
                     node = Node(name=compute_node.hypervisor_hostname,
-                                site_deployment=site_deployments[site_index])
+                                site_deployment=site_deployment)
                     new_nodes.append(node)
 
         return new_nodes