Link backend dependencies to references. Resolves #20.
diff --git a/planetstack/backend-model-deps b/planetstack/backend-model-deps
new file mode 100644
index 0000000..da9565f
--- /dev/null
+++ b/planetstack/backend-model-deps
@@ -0,0 +1,11 @@
+{
+    "Sliver": [
+	["SlicePrivilege","slice.sliceprivileges"],
+	["SitePrivilege","slice.site.siteprivileges"],
+	["ControllerImages","image.controllerimages"]
+    ] 
+    ,
+    "Network": [
+        ["Slice","network.slices"]
+    ]
+}
diff --git a/planetstack/openstack_observer/event_loop.py b/planetstack/openstack_observer/event_loop.py
index ce0ab5e..0d1486d 100644
--- a/planetstack/openstack_observer/event_loop.py
+++ b/planetstack/openstack_observer/event_loop.py
@@ -122,12 +122,17 @@
 		try:
 			# This contains dependencies between records, not sync steps
 			self.model_dependency_graph = json.loads(open(dep_path).read())
-			for lst in self.model_dependency_graph.values():
+			for left,lst in self.model_dependency_graph.items():
+                                new_lst = [] 
 				for k in lst:
 					try:
+                                                tup = (k,k.lower())
+                                                new_lst.append(tup)
 						deps = self.model_dependency_graph[k]
 					except:
 						self.model_dependency_graph[k] = []
+
+                                self.model_dependency_graph[left] = new_lst
 		except Exception,e:
 			raise e
 
@@ -157,13 +162,13 @@
 					provides_dict[m.__name__]=[s.__name__]
 
 		step_graph = {}
-		for k,v in self.model_dependency_graph.iteritems():
+		for k,v in self.model_dependency_graph.items():
 			try:
 				for source in provides_dict[k]:
 					if (not v):
 						step_graph[source] = []
 		
-					for m in v:
+					for m,_ in v:
 						try:
 							for dest in provides_dict[m]:
 								# no deps, pass
@@ -187,7 +192,7 @@
 		pp.pprint(step_graph)
 		self.ordered_steps = toposort(self.dependency_graph, map(lambda s:s.__name__,self.sync_steps))
 		#self.ordered_steps = ['SyncRoles', 'SyncControllerSites', 'SyncControllerSitePrivileges','SyncImages', 'SyncControllerImages','SyncControllerUsers','SyncControllerUserSitePrivileges','SyncControllerSlices', 'SyncControllerSlicePrivileges', 'SyncControllerUserSlicePrivileges', 'SyncControllerNetworks','SyncSlivers']
-		#self.ordered_steps = ['SyncControllerSites']
+		#self.ordered_steps = ['SyncControllerSites','SyncControllerUsers','SyncControllerSlices','SyncControllerNetworks']
 
 		print "Order of steps=",self.ordered_steps
 
@@ -247,7 +252,9 @@
 	def check_class_dependency(self, step, failed_steps):
 		step.dependenices = []
 		for obj in step.provides:
-			step.dependenices.extend(self.model_dependency_graph.get(obj.__name__, []))
+		        lst = self.model_dependency_graph.get(obj.__name__, [])
+			nlst = map(lambda(a,b):b,lst)
+			step.dependenices.extend(nlst)
 		for failed_step in failed_steps:
 			if (failed_step in step.dependencies):
 				raise StepNotReady
@@ -302,13 +309,15 @@
 			my_status = STEP_STATUS_KO
 		else:
 			sync_step = step(driver=self.driver,error_map=self.error_mapper)
-			sync_step.__name__ = step.__name__
+			sync_step. __name__= step.__name__
 			sync_step.dependencies = []
 			try:
 				mlist = sync_step.provides
 
 				for m in mlist:
-					sync_step.dependencies.extend(self.model_dependency_graph[m.__name__])
+				        lst =  self.model_dependency_graph[m.__name__]
+			                nlst = map(lambda(a,b):b,lst)
+					sync_step.dependencies.extend(nlst)
 			except KeyError:
 				pass
 			sync_step.debug_mode = debug_mode
diff --git a/planetstack/openstack_observer/syncstep.py b/planetstack/openstack_observer/syncstep.py
index 7b96e40..062b1d1 100644
--- a/planetstack/openstack_observer/syncstep.py
+++ b/planetstack/openstack_observer/syncstep.py
@@ -5,12 +5,16 @@
 from util.logger import Logger, logging
 from observer.steps import *
 from django.db.models import F, Q
+from core.models import * 
 import json
 import time
 import pdb
 
 logger = Logger(level=logging.INFO)
 
+def deepgetattr(obj, attr):
+    return reduce(getattr, attr.split('.'), obj)
+
 class FailedDependency(Exception):
     pass
 
@@ -63,14 +67,19 @@
     def check_dependencies(self, obj, failed):
         for dep in self.dependencies:
             peer_name = dep[0].lower() + dep[1:]    # django names are camelCased with the first letter lower
+ 
             try:
-                peer_object = getattr(obj, peer_name)
+                peer_object = deepgetattr(obj, peer_name)
+                try: 
+                    peer_objects = peer_object.all() 
+                except AttributeError:
+                    peer_objects = [peer_object] 
             except:
-                peer_object = None
+                peer_objects = []
 
-            if (peer_object and peer_object.pk==failed.pk and type(peer_object)==type(failed)):
-                if (obj.backend_status!=peer_object.backend_status):
-                    obj.backend_status = peer_object.backend_status
+            if (failed in peer_objects):
+                if (obj.backend_status!=failed.backend_status):
+                    obj.backend_status = failed.backend_status
                     obj.save(update_fields=['backend_status'])
                 raise FailedDependency("Failed dependency for %s:%s peer %s:%s failed  %s:%s" % (obj.__class__.__name__, str(obj.pk), peer_object.__class__.__name__, str(peer_object.pk), failed.__class__.__name__, str(failed.pk)))