Fix bugs. Reefactor.
Tony Mack [Sun, 4 Jan 2015 00:37:39 +0000 (19:37 -0500)]
planetstack/openstack_observer/steps/__init__.py
planetstack/openstack_observer/steps/sync_controller_site_deployments.py
planetstack/openstack_observer/steps/sync_controller_users.py
planetstack/openstack_observer/steps/sync_nodes.py
planetstack/openstack_observer/steps/sync_site_privileges.py
planetstack/openstack_observer/steps/sync_sites.py
planetstack/openstack_observer/syncstep.py

index 3f074a5..3f8dca4 100644 (file)
@@ -1,16 +1,14 @@
-##from .sync_external_routes import SyncExternalRoutes
-#from .sync_network_slivers import SyncNetworkSlivers
-#from .sync_networks import SyncNetworks
-#from .sync_controller_networks import SyncControllerNetworks
-#from .sync_site_privileges import SyncSitePrivileges
-#from .sync_sites import SyncSites
-#from .sync_slice_memberships import SyncSliceMemberships
-#from .sync_slices import SyncSlices
-##from .sync_sliver_ips import SyncSliverIps
-#from .sync_slivers import SyncSlivers
-#from .sync_users import SyncUsers
-#from .sync_roles import SyncRoles
-#from .sync_nodes import SyncNodes
-#from .sync_images import SyncImages
-#from .sync_controller_images import SyncControllerImages
-#from .garbage_collector import GarbageCollector
+from .sync_controller_site_deployments import SyncControllerSiteDeployments
+from .sync_network_slivers import SyncNetworkSlivers
+from .sync_networks import SyncNetworks
+from .sync_controller_networks import SyncControllerNetworks
+from .sync_site_privileges import SyncSitePrivileges
+from .sync_sites import SyncSites
+from .sync_slice_memberships import SyncSliceMemberships
+from .sync_slices import SyncSlices
+from .sync_slivers import SyncSlivers
+from .sync_users import SyncUsers
+from .sync_roles import SyncRoles
+from .sync_nodes import SyncNodes
+from .sync_images import SyncImages
+from .sync_controller_images import SyncControllerImages
index a923608..907325a 100644 (file)
@@ -10,6 +10,10 @@ class SyncControllerSiteDeployments(OpenStackSyncStep):
     requested_interval=0
     provides=[SiteDeployments]
 
+    def fetch_pending(self, deleted=False):
+        pending = super(OpenStackSyncStep, self).fetch_pending(deleted)
+        return pending.filter(controller__isnull=False)
+
     def sync_record(self, site_deployment):
 
        template = os_template_env.get_template('sync_controller_site_deployments.yaml')
@@ -17,7 +21,7 @@ class SyncControllerSiteDeployments(OpenStackSyncStep):
                         'admin_user': site_deployment.controller.admin_user,
                         'admin_password': site_deployment.controller.admin_password,
                         'admin_tenant': site_deployment.controller.admin_tenant,
-                        'ansible_tag': '%s@%s'%(site_deployment.site.login_base,site_deployment.site_deployment.deployment.name), # name of ansible playbook
+                        'ansible_tag': '%s@%s'%(site_deployment.site.login_base,site_deployment.deployment.name), # name of ansible playbook
                         'tenant': site_deployment.site.login_base,
                         'tenant_description': site_deployment.site.name}
 
index 113869e..1b57b81 100644 (file)
@@ -4,7 +4,7 @@ from collections import defaultdict
 from django.db.models import F, Q
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
-from core.models.site import Controller, SiteDeployments, ControllerSiteDeployments
+from core.models.site import Controller, SiteDeployments, SiteDeployments
 from core.models.user import User
 from core.models.controllerusers import ControllerUsers
 from util.logger import Logger, logging
@@ -44,7 +44,7 @@ class SyncControllerUsers(OpenStackSyncStep):
             raise Exception('Siteless user %s'%controller_user.user.email)
         else:
             # look up tenant id for the user's site at the controller
-            #ctrl_site_deployments = ControllerSiteDeployments.objects.filter(
+            #ctrl_site_deployments = SiteDeployments.objects.filter(
             #  site_deployment__site=controller_user.user.site,
             #  controller=controller_user.controller)
 
index 8702a21..9d51073 100644 (file)
@@ -6,7 +6,7 @@ from django.db.models import F, Q
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
 from core.models.node import Node
-from core.models.site import SiteDeployments, Controller, ControllerSiteDeployments
+from core.models.site import SiteDeployments, Controller, SiteDeployments
 from util.logger import Logger, logging
 
 logger = Logger(level=logging.INFO)
@@ -30,7 +30,7 @@ class SyncNodes(OpenStackSyncStep):
         new_nodes = []
         for controller in controllers:
             try:
-               controller_site_deployments = ControllerSiteDeployments.objects.filter(controller=controller)[0]
+               controller_site_deployments = SiteDeployments.objects.filter(controller=controller)[0]
            except IndexError:
                 raise Exception("Controller %s not bound to any site deployments"%controller.name)
 
index 9dcd07e..6354d1f 100644 (file)
@@ -3,7 +3,7 @@ import base64
 from django.db.models import F, Q
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
-from core.models import User, ControllerUsers, SitePrivilege, ControllerSiteDeployments   
+from core.models import User, ControllerUsers, SitePrivilege, SiteDeployments   
 
 class SyncSitePrivileges(OpenStackSyncStep):
     requested_interval=0
@@ -18,7 +18,7 @@ class SyncSitePrivileges(OpenStackSyncStep):
 
     def sync_record(self, site_priv):
         # sync site privileges at all site controllers
-        ctrl_site_deployments = ControllerSiteDeployments.objects.filter(site_deployment__site=site_priv.site)
+        ctrl_site_deployments = SiteDeployments.objects.filter(site_deployment__site=site_priv.site)
         for ctrl_site_deployment in ctrl_site_deployments:
             controller_users = ControllerUsers.objects.filter(controller=ctrl_site_deployment.controller,
                                                               user=site_priv.user)
index e18e2f8..ea7df7e 100644 (file)
@@ -3,7 +3,7 @@ import base64
 from django.db.models import F, Q
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
-from core.models.site import Site, SiteDeployments, ControllerSiteDeployments 
+from core.models.site import Site, SiteDeployments, SiteDeployments 
 from observer.steps.sync_controller_site_deployments import *
 
 class SyncSites(OpenStackSyncStep):
@@ -15,15 +15,11 @@ class SyncSites(OpenStackSyncStep):
 
     def delete_record(self, site):
         # delete associated controllers site deployments
-        ctrl_site_deployments = ControllerSiteDeployments.objects.filter(site_deployment__site=site)
-        ctrl_site_deploy_deleter = SyncControllerSiteDeployments().delete_record
-        for ctrl_site_deployment in ctrl_site_deployments:
-            ctrl_site_deployment_deleter(ctrl_site_deployment)
-
-        # delete site deployments
         site_deployments = SiteDeployments.objects.filter(site=site)
+        site_deploy_deleter = SyncControllerSiteDeployments().delete_record
         for site_deployment in site_deployments:
-            site_deployment.delete()    
+            site_deployment_deleter(site_deployment)
+
          
 
        
index ad148b5..72a740c 100644 (file)
@@ -11,7 +11,7 @@ logger = Logger(level=logging.INFO)
 class FailedDependency(Exception):
     pass
 
-class SyncStep:
+class SyncStep(object):
     """ A PlanetStack Sync step. 
 
     Attributes: