Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index e187f68..5f9efd2 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -633,7 +633,7 @@
 
     # nodes no longer direclty connected to deployments
     #suit_form_tabs =(('sites','Deployment Details'),('nodes','Nodes'),('deploymentprivileges','Privileges'),('tags','Tags'),('imagedeployments','Images'))
-    suit_form_tabs =(('sites','Deployment Details'),('deploymentprivileges','Privileges'),,('imagedeployments','Images'))
+    suit_form_tabs =(('sites','Deployment Details'),('deploymentprivileges','Privileges'))
 
     def get_form(self, request, obj=None, **kwargs):
         if request.user.isReadOnlyUser():
@@ -935,6 +935,7 @@
           ('sliceprivileges','Privileges'),
           ('slivers','Slivers'),
           ('reservations','Reservations'),
+          ('tags','Tags'),
           ]
 
         request=getattr(_thread_locals, "request", None)
diff --git a/planetstack/model_policies/model_policy_Controller.py b/planetstack/model_policies/model_policy_Controller.py
index 9415bb5..98eeaff 100644
--- a/planetstack/model_policies/model_policy_Controller.py
+++ b/planetstack/model_policies/model_policy_Controller.py
@@ -2,6 +2,10 @@
 def handle(controller):
     from core.models import Controller, Site, ControllerSite, Slice, ControllerSlice, User, ControllerUser
     from collections import defaultdict
+
+    #controller = Controller.get(controller_id)
+
+	
     # relations for all sites
     ctrls_by_site = defaultdict(list)
     ctrl_sites = ControllerSite.objects.all()
@@ -12,7 +16,7 @@
         if site not in ctrls_by_site or \
             controller not in ctrls_by_site[site]:
             controller_site = ControllerSite(controller=controller, site=site)
-            controller_site.save()	
+            controller_site.save()
     # relations for all slices
     ctrls_by_slice = defaultdict(list)
     ctrl_slices = ControllerSlice.objects.all()
@@ -23,7 +27,7 @@
         if slice not in ctrls_by_slice or \
             controller not in ctrls_by_slice:
             controller_slice = ControllerSlice(controller=controller, slice=slice)
-            controller_slice.save()    
+            controller_slice.save()
     # relations for all users
     ctrls_by_user = defaultdict(list)
     ctrl_users = ControllerUser.objects.all()
@@ -34,8 +38,4 @@
         if user not in ctrls_by_user or \
             controller not in ctrls_by_user[user]:
             controller_user = ControllerUser(controller=controller, user=user)
-            controller_user.save()         
-
-
-
-
+            controller_user.save()
diff --git a/planetstack/model_policies/model_policy_Network.py b/planetstack/model_policies/model_policy_Network.py
index f822bf2..8702d21 100644
--- a/planetstack/model_policies/model_policy_Network.py
+++ b/planetstack/model_policies/model_policy_Network.py
@@ -1,8 +1,10 @@
 from core.models import *
 
 def handle(network):
-	from core.models import ControllerSlice,ControllerNetwork
+	from core.models import ControllerSlice,ControllerNetwork, Network
 	from collections import defaultdict
+
+        # network = Network.get(network_id)
 	# network controllers are not visible to users. We must ensure
 	# networks are deployed at all deploymets available to their slices.
 	slice_controllers = ControllerSlice.objects.all()
diff --git a/planetstack/model_policies/model_policy_Site.py b/planetstack/model_policies/model_policy_Site.py
index 7d96264..23010a2 100644
--- a/planetstack/model_policies/model_policy_Site.py
+++ b/planetstack/model_policies/model_policy_Site.py
@@ -1,6 +1,8 @@
 
 def handle(site):
-    from core.models import Controller, ControllerSite 
+    from core.models import Controller, ControllerSite, Site 
+
+    # site = Site.get(site_id)
     # make sure site has a ControllerSite record for each controller
     ctrl_sites = ControllerSite.objects.filter(site=site)
     existing_controllers = [cs.controller for cs in ctrl_sites]
diff --git a/planetstack/model_policies/model_policy_SitePrivilege.py b/planetstack/model_policies/model_policy_SitePrivilege.py
index 90280a3..6e9a65c 100644
--- a/planetstack/model_policies/model_policy_SitePrivilege.py
+++ b/planetstack/model_policies/model_policy_SitePrivilege.py
@@ -1,6 +1,7 @@
 def handle(site_privilege):
     from core.models import Controller, SitePrivilege, ControllerSitePrivilege
     
+    # site_privilege = SitePrivilege.get(site_privilege_id)
     # apply site privilage at all controllers
     controller_site_privileges = ControllerSitePrivilege.objects.filter(
         site_privilege = site_privilege,
diff --git a/planetstack/model_policies/model_policy_Slice.py b/planetstack/model_policies/model_policy_Slice.py
index cc9f2b0..1f58570 100644
--- a/planetstack/model_policies/model_policy_Slice.py
+++ b/planetstack/model_policies/model_policy_Slice.py
@@ -1,7 +1,10 @@
 
 def handle(slice):
-    from core.models import Controller, ControllerSlice, SiteDeployment, Network, NetworkSlice,NetworkTemplate
+    from core.models import Controller, ControllerSlice, SiteDeployment, Network, NetworkSlice,NetworkTemplate, Slice
     from collections import defaultdict
+
+    # slice = Slice.get(slice_id)
+
     controller_slices = ControllerSlice.objects.filter(slice=slice)
     existing_controllers = [cs.controller for cs in controller_slices] 
     
diff --git a/planetstack/model_policies/model_policy_SlicePrivilege.py b/planetstack/model_policies/model_policy_SlicePrivilege.py
index 0f772cb..e58a973 100644
--- a/planetstack/model_policies/model_policy_SlicePrivilege.py
+++ b/planetstack/model_policies/model_policy_SlicePrivilege.py
@@ -1,6 +1,7 @@
 def handle(slice_privilege):
     from core.models import Controller, SlicePrivilege, ControllerSlicePrivilege
-    
+   
+    # slice_privilege = SlicePrivilege.get(slice_privilege_id) 
     # apply slice privilage at all controllers
     controller_slice_privileges = ControllerSlicePrivilege.objects.filter(
         slice_privilege = slice_privilege,
diff --git a/planetstack/model_policies/model_policy_User.py b/planetstack/model_policies/model_policy_User.py
index b7b16ad..8d14244 100644
--- a/planetstack/model_policies/model_policy_User.py
+++ b/planetstack/model_policies/model_policy_User.py
@@ -1,6 +1,8 @@
 def handle(user):
-    from core.models import Controller, ControllerSite, ControllerUser
+    from core.models import Controller, ControllerSite, ControllerUser, User
     from collections import defaultdict
+
+    # user = User.get(user_id)
     
     controller_users = ControllerUser.objects.filter(user=user)
     existing_controllers = [cu.controller for cu in controller_users]
diff --git a/planetstack/model_policy.py b/planetstack/model_policy.py
index e12b15c..7aef793 100644
--- a/planetstack/model_policy.py
+++ b/planetstack/model_policy.py
@@ -6,6 +6,7 @@
 import model_policies
 from util.logger import logger
 
+
 modelPolicyEnabled = True
 
 def EnableModelPolicy(x):
@@ -17,7 +18,6 @@
 		if (d.updated < o.updated):
 			d.save(update_fields=['updated'])
 	except AttributeError,e:
-		pdb.set_trace()
 		raise e
 	
 def delete_if_inactive(d, o):
@@ -25,6 +25,23 @@
 	d.delete()	
 	return
 
+def execute_model_policy(policy_name, instance, update_fields_empty, deleted):
+	if (update_fields_empty):
+		# Automatic dirtying
+		#walk_inv_deps(update_dep, instance)
+
+		try:
+			policy_handler = getattr(model_policies, policy_name, None)
+                        logger.error("POLICY HANDLER: %s %s" % (policy_name, policy_handler))                       
+			if policy_handler is not None:
+				policy_handler.handle(instance)
+		except:
+			logger.log_exc("Model Policy Error:") 
+			print "Policy Exceution Error"
+	elif deleted:
+		walk_inv_deps(delete_if_inactive, instance)
+
+
 @receiver(post_save)
 def post_save_handler(sender, instance, **kwargs):
         if not modelPolicyEnabled:
@@ -32,17 +49,13 @@
 
 	sender_name = sender.__name__
 	policy_name = 'model_policy_%s'%sender_name
-	
-	if (not kwargs['update_fields']):
-		# Automatic dirtying
-		walk_inv_deps(update_dep, instance)
+        if (not kwargs['update_fields']):
+		noargs = True
+		deleted = False
+	else:
+		noargs = False
+		deleted = True
 
-		try:
-			policy_handler = getattr(model_policies, policy_name, None)
-			if policy_handler is not None:
-				policy_handler.handle(instance)
-		except:
-			logger.log_exc("Model Policy Error:") 
-	elif 'deleted' in kwargs['update_fields']:
-		walk_inv_deps(delete_if_inactive, instance)
+	execute_model_policy(policy_name, instance, noargs, deleted)
+	
 	
diff --git a/planetstack/openstack_observer/event_loop.py b/planetstack/openstack_observer/event_loop.py
index cdd94a2..cc0611c 100644
--- a/planetstack/openstack_observer/event_loop.py
+++ b/planetstack/openstack_observer/event_loop.py
@@ -22,9 +22,21 @@
 from syncstep import SyncStep
 from toposort import toposort
 from observer.error_mapper import *
+from openstack_observer.openstacksyncstep import OpenStackSyncStep
+
 
 debug_mode = False
 
+class bcolors:
+    HEADER = '\033[95m'
+    OKBLUE = '\033[94m'
+    OKGREEN = '\033[92m'
+    WARNING = '\033[93m'
+    FAIL = '\033[91m'
+    ENDC = '\033[0m'
+    BOLD = '\033[1m'
+    UNDERLINE = '\033[4m'
+
 logger = Logger(level=logging.INFO)
 
 class StepNotReady(Exception):
@@ -96,7 +108,7 @@
 					# provides field (this eliminates the abstract base classes
 					# since they don't have a provides)
 
-					if inspect.isclass(c) and issubclass(c, SyncStep) and hasattr(c,"provides") and (c not in self.sync_steps):
+					if inspect.isclass(c) and (issubclass(c, SyncStep) or issubclass(c,OpenStackSyncStep)) and hasattr(c,"provides") and (c not in self.sync_steps):
 						self.sync_steps.append(c)
 		logger.info('loaded sync steps: %s' % ",".join([x.__name__ for x in self.sync_steps]))
 		# print 'loaded sync steps: %s' % ",".join([x.__name__ for x in self.sync_steps])
diff --git a/planetstack/openstack_observer/run_ansible b/planetstack/openstack_observer/run_ansible
index 5fab9df..224a6d7 100644
--- a/planetstack/openstack_observer/run_ansible
+++ b/planetstack/openstack_observer/run_ansible
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 source /opt/ansible/hacking/env-setup
 ansible-playbook -v $@
diff --git a/planetstack/openstack_observer/steps/sync_controller_images.py b/planetstack/openstack_observer/steps/sync_controller_images.py
index 008de71..2014a25 100644
--- a/planetstack/openstack_observer/steps/sync_controller_images.py
+++ b/planetstack/openstack_observer/steps/sync_controller_images.py
@@ -12,7 +12,7 @@
 logger = Logger(level=logging.INFO)
 
 class SyncControllerImages(OpenStackSyncStep):
-    provides=[ControllerImages]
+    provides=[ControllerImages, Image]
     requested_interval=0
 
     def fetch_pending(self, deleted):
@@ -24,19 +24,19 @@
 
     def sync_record(self, controller_image):
         logger.info("Working on image %s on controller %s" % (controller_image.image.name, controller_image.controller))
-	image_fields = {'endpoint':controller_image.controller.auth_url,
-			'admin_user':controller_image.controller.admin_user,
-			'admin_password':controller_image.controller.admin_password,
-			'name':controller_image.image.name,
-			'filepath':controller_image.image.path,
-	                'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
-			}
+        image_fields = {'endpoint':controller_image.controller.auth_url,
+                        'admin_user':controller_image.controller.admin_user,
+                        'admin_password':controller_image.controller.admin_password,
+                        'name':controller_image.image.name,
+                        'filepath':controller_image.image.path,
+                        'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
+                        }
 
-	res = run_template('sync_controller_images.yaml', image_fields, path='controller_images')
+        res = run_template('sync_controller_images.yaml', image_fields, path='controller_images')
 
-	if (len(res)!=1):
-	    raise Exception('Could not sync image %s'%controller_image.image.name)
-	else:
-	    image_id = res[0]['id'] 
+        if (len(res)!=1):
+            raise Exception('Could not sync image %s'%controller_image.image.name)
+        else:
+            image_id = res[0]['id']
             controller_image.glance_image_id = image_id
             controller_image.save()
diff --git a/planetstack/openstack_observer/steps/sync_controller_images.yaml b/planetstack/openstack_observer/steps/sync_controller_images.yaml
index aca7171..18228db 100644
--- a/planetstack/openstack_observer/steps/sync_controller_images.yaml
+++ b/planetstack/openstack_observer/steps/sync_controller_images.yaml
@@ -7,7 +7,7 @@
         login_username: {{ admin_user }}
         login_tenant_name: 'admin'
         login_password: {{ admin_password }}
-        name: {{ name }}
-        file: {{ filepath }}
+        name: "{{ name }}"
+        file: "{{ filepath }}"
         disk_format: 'raw'
         is_public: true
diff --git a/planetstack/openstack_observer/steps/sync_controller_networks.py b/planetstack/openstack_observer/steps/sync_controller_networks.py
index c90e4df..cb82680 100644
--- a/planetstack/openstack_observer/steps/sync_controller_networks.py
+++ b/planetstack/openstack_observer/steps/sync_controller_networks.py
@@ -15,7 +15,7 @@
 
 class SyncControllerNetworks(OpenStackSyncStep):
     requested_interval = 0
-    provides=[Network, ControllerNetwork, Sliver]
+    provides=[ControllerNetwork, Network]
 
     def alloc_subnet(self, uuid):
         a = 10
diff --git a/planetstack/openstack_observer/steps/sync_controller_site_privileges.py b/planetstack/openstack_observer/steps/sync_controller_site_privileges.py
index dd5bf3a..99a5987 100644
--- a/planetstack/openstack_observer/steps/sync_controller_site_privileges.py
+++ b/planetstack/openstack_observer/steps/sync_controller_site_privileges.py
@@ -14,7 +14,7 @@
 logger = Logger(level=logging.INFO)
 
 class SyncControllerSitePrivileges(OpenStackSyncStep):
-    provides=[ControllerSitePrivilege]
+    provides=[ControllerSitePrivilege, SitePrivilege]
     requested_interval=0
 
     def fetch_pending(self, deleted):
diff --git a/planetstack/openstack_observer/steps/sync_controller_sites.py b/planetstack/openstack_observer/steps/sync_controller_sites.py
index 865ae07..71837a3 100644
--- a/planetstack/openstack_observer/steps/sync_controller_sites.py
+++ b/planetstack/openstack_observer/steps/sync_controller_sites.py
@@ -8,7 +8,7 @@
 
 class SyncControllerSites(OpenStackSyncStep):
     requested_interval=0
-    provides=[ControllerSite]
+    provides=[ControllerSite, Site]
 
     def fetch_pending(self, deleted=False):
         pending = super(OpenStackSyncStep, self).fetch_pending(deleted)
diff --git a/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py b/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py
index f981f16..94d5d21 100644
--- a/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py
+++ b/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py
@@ -14,7 +14,7 @@
 logger = Logger(level=logging.INFO)
 
 class SyncControllerSlicePrivileges(OpenStackSyncStep):
-    provides=[ControllerSlicePrivilege]
+    provides=[ControllerSlicePrivilege, SlicePrivilege]
     requested_interval=0
 
     def fetch_pending(self, deleted):
diff --git a/planetstack/openstack_observer/steps/sync_controller_slices.py b/planetstack/openstack_observer/steps/sync_controller_slices.py
index 7331fac..0f8b6fc 100644
--- a/planetstack/openstack_observer/steps/sync_controller_slices.py
+++ b/planetstack/openstack_observer/steps/sync_controller_slices.py
@@ -14,7 +14,7 @@
 logger = Logger(level=logging.INFO)
 
 class SyncControllerSlices(OpenStackSyncStep):
-    provides=[ControllerSlice]
+    provides=[ControllerSlice, Slice]
     requested_interval=0
 
     def fetch_pending(self, deleted):
diff --git a/planetstack/openstack_observer/steps/sync_slivers.py b/planetstack/openstack_observer/steps/sync_slivers.py
index 75b0b1e..06a05f1 100644
--- a/planetstack/openstack_observer/steps/sync_slivers.py
+++ b/planetstack/openstack_observer/steps/sync_slivers.py
@@ -93,7 +93,7 @@
         if (legacy):
             host_filter = sliver.node.name.split('.',1)[0]
         else:
-            host_filter = sliver.node.name
+            host_filter = sliver.node.name.strip()
 
         availability_zone_filter = 'nova:%s'%host_filter
         sliver_name = '%s-%d'%(sliver.slice.name,sliver.id)
@@ -105,7 +105,7 @@
         controller = sliver.node.site_deployment.controller
         tenant_fields = {'endpoint':controller.auth_url,
                      'admin_user': sliver.creator.email,
-                     'admin_password': sliver.creator.reomote_password,
+                     'admin_password': sliver.creator.remote_password,
                      'admin_tenant': sliver.slice.name,
                      'tenant': sliver.slice.name,
                      'tenant_description': sliver.slice.description,