CORD-1010 refactor openstack synchronizer to use new_base

Change-Id: I4eb4e5131275faf69e1da05efc81a3d8d0d12296
diff --git a/xos/synchronizer/driver.py b/xos/synchronizer/driver.py
index e5ce2f8..1e795e4 100644
--- a/xos/synchronizer/driver.py
+++ b/xos/synchronizer/driver.py
@@ -1,7 +1,7 @@
 import commands
 import hashlib
 from xos.config import Config
-from core.models import Controller
+from synchronizers.new_base.modelaccessor import *
 
 try:
     from synchronizers.openstack.client import OpenStackClient
diff --git a/xos/synchronizer/manager.py b/xos/synchronizer/manager.py
deleted file mode 100644
index ae6cab9..0000000
--- a/xos/synchronizer/manager.py
+++ /dev/null
@@ -1,569 +0,0 @@
-import os
-#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
-import string
-import random
-import hashlib
-from datetime import datetime
-from django.utils import timezone
-
-from netaddr import IPAddress, IPNetwork
-from xos import settings
-from django.core import management
-from core.models import *
-from xos.config import Config
-try:
-    from synchronizers.openstack.client import OpenStackClient
-    from synchronizers.openstack.driver import OpenStackDriver
-    has_openstack = True
-except:
-    has_openstack = False
-
-manager_enabled = Config().api_nova_enabled
-
-
-def random_string(size=6):
-    return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(size))
-
-def require_enabled(callable):
-    def wrapper(*args, **kwds):
-        if manager_enabled and has_openstack:
-            return callable(*args, **kwds)
-        else:
-            return None
-    return wrapper
-
-
-class OpenStackManager:
-
-    def __init__(self, auth={}, caller=None):
-        self.client = None
-        self.driver = None
-        self.caller = None
-        self.has_openstack = has_openstack       
-        self.enabled = manager_enabled
-
-        if has_openstack and manager_enabled:
-            if auth:
-                try:
-                    self.init_user(auth, caller)
-                except:
-                    # if this fails then it meanse the caller doesn't have a
-                    # role at the slice's tenant. if the caller is an admin
-                    # just use the admin client/manager.
-                    if caller and caller.is_admin: 
-                        self.init_admin()
-                    else: raise
-            else:
-                self.init_admin()
-
-    @require_enabled 
-    def init_caller(self, caller, tenant):
-        auth = {'username': caller.email,
-                'password': hashlib.md5(caller.password).hexdigest()[:6],
-                'tenant': tenant}
-        self.client = OpenStackClient(**auth)
-        self.driver = OpenStackDriver(client=self.client)
-        self.caller = caller                 
-    
-    @require_enabled
-    def init_admin(self, tenant=None):
-        # use the admin credentials 
-        self.client = OpenStackClient(tenant=tenant)
-        self.driver = OpenStackDriver(client=self.client)
-        self.caller = self.driver.admin_user
-        self.caller.kuser_id = self.caller.id 
-
-    @require_enabled
-    def save_role(self, role):
-        if not role.role:
-            keystone_role = self.driver.create_role(role.role_type)
-            role.role = keystone_role.id
-
-    @require_enabled
-    def delete_role(self, role):
-        if role.role:
-            self.driver.delete_role({'id': role.role})
-
-    @require_enabled
-    def save_key(self, key, name):
-        key_fields = {'name': name,
-                      'public_key': key}
-        nova_key = self.driver.create_keypair(**key_fields)
-
-    @require_enabled
-    def delete_key(self, key):
-        if key.nkey_id:
-            self.driver.delete_keypair(key.nkey_id)
-
-    @require_enabled
-    def save_user(self, user):
-        name = user.email[:user.email.find('@')]
-        user_fields = {'name': name,
-                       'email': user.email,
-                       'password': hashlib.md5(user.password).hexdigest()[:6],
-                       'enabled': True}
-        if not user.kuser_id:
-            keystone_user = self.driver.create_user(**user_fields)
-            user.kuser_id = keystone_user.id
-        else:
-            self.driver.update_user(user.kuser_id, user_fields)     
-
-        if user.site:
-            self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'user')
-            if user.is_admin:
-                self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'admin')
-            else:
-                # may have admin role so attempt to remove it
-                self.driver.delete_user_role(user.kuser_id, user.site.tenant_id, 'admin')
-
-        if user.public_key:
-            self.init_caller(user, user.site.login_base)
-            self.save_key(user.public_key, user.keyname)
-            self.init_admin()
-
-        user.save()
-        user.enacted = timezone.now()
-        user.save(update_fields=['enacted'])
-  
-    @require_enabled
-    def delete_user(self, user):
-        if user.kuser_id:
-            self.driver.delete_user(user.kuser_id)        
-    
-    @require_enabled
-    def save_site(self, site, add_role=True):
-        if not site.tenant_id:
-            tenant = self.driver.create_tenant(tenant_name=site.login_base,
-                                               description=site.name,
-                                               enabled=site.enabled)
-            site.tenant_id = tenant.id
-            # give caller an admin role at the tenant they've created
-            self.driver.add_user_role(self.caller.kuser_id, tenant.id, 'admin')
-
-        # update the record
-        if site.id and site.tenant_id:
-            self.driver.update_tenant(site.tenant_id,
-                                      description=site.name,
-                                      enabled=site.enabled)
-
-        # commit the updated record
-        site.save()
-        site.enacted = timezone.now()
-        site.save(update_fields=['enacted']) # enusre enacted > updated  
-        
-
-    @require_enabled
-    def delete_site(self, site):
-        if site.tenant_id:
-            self.driver.delete_tenant(site.tenant_id)
-               
-    @require_enabled
-    def save_site_privilege(self, site_priv):
-        if site_priv.user.kuser_id and site_priv.site.tenant_id:
-            self.driver.add_user_role(site_priv.user.kuser_id,
-                                      site_priv.site.tenant_id,
-                                      site_priv.role.role_type)
-        site_priv.enacted = timezone.now()
-        site_priv.save(update_fields=['enacted'])
-
-    
-    @require_enabled
-    def delete_site_privilege(self, site_priv):
-        self.driver.delete_user_role(site_priv.user.kuser_id, 
-                                     site_priv.site.tenant_id, 
-                                     site_priv.role.role_type)
-
-    @require_enabled
-    def save_slice(self, slice):
-        if not slice.tenant_id:
-            nova_fields = {'tenant_name': slice.name,
-                   'description': slice.description,
-                   'enabled': slice.enabled}
-            tenant = self.driver.create_tenant(**nova_fields)
-            slice.tenant_id = tenant.id
-
-            # give caller an admin role at the tenant they've created
-            self.driver.add_user_role(self.caller.kuser_id, tenant.id, 'admin')
-
-            # refresh credentials using this tenant
-            self.driver.shell.connect(username=self.driver.shell.keystone.username,
-                                      password=self.driver.shell.keystone.password,
-                                      tenant=tenant.name)
-
-            # create network
-            network = self.driver.create_network(slice.name)
-            slice.network_id = network['id']
-
-            # create router
-            router = self.driver.create_router(slice.name)
-            slice.router_id = router['id']
-
-            # create subnet
-            next_subnet = self.get_next_subnet()
-            cidr = str(next_subnet.cidr)
-            ip_version = next_subnet.version
-            start = str(next_subnet[2])
-            end = str(next_subnet[-2]) 
-            subnet = self.driver.create_subnet(name=slice.name,
-                                               network_id = network['id'],
-                                               cidr_ip = cidr,
-                                               ip_version = ip_version,
-                                               start = start,
-                                               end = end)
-            slice.subnet_id = subnet['id']
-            # add subnet as interface to slice's router
-            self.driver.add_router_interface(router['id'], subnet['id'])
-            # add external route
-            self.driver.add_external_route(subnet)
-
-
-        if slice.id and slice.tenant_id:
-            self.driver.update_tenant(slice.tenant_id,
-                                      description=slice.description,
-                                      enabled=slice.enabled)   
-
-        slice.save()
-        slice.enacted = timezone.now()
-        slice.save(update_fields=['enacted']) 
-
-    @require_enabled
-    def delete_slice(self, slice):
-        if slice.tenant_id:
-            self._delete_slice(slice.tenant_id, slice.network_id, 
-                               slice.router_id, slice.subnet_id)
-    @require_enabled
-    def _delete_slice(self, tenant_id, network_id, router_id, subnet_id):
-        self.driver.delete_router_interface(slice.router_id, slice.subnet_id)
-        self.driver.delete_subnet(slice.subnet_id)
-        self.driver.delete_router(slice.router_id)
-        self.driver.delete_network(slice.network_id)
-        self.driver.delete_tenant(slice.tenant_id)
-        # delete external route
-        subnet = None
-        subnets = self.driver.shell.neutron.list_subnets()['subnets']
-        for snet in subnets:
-            if snet['id'] == slice.subnet_id:
-                subnet = snet
-        if subnet:
-            self.driver.delete_external_route(subnet) 
-
-    
-    @require_enabled
-    def save_slice_membership(self, slice_memb):
-        if slice_memb.user.kuser_id and slice_memb.slice.tenant_id:
-            self.driver.add_user_role(slice_memb.user.kuser_id,
-                                      slice_memb.slice.tenant_id,
-                                      slice_memb.role.role_type)
-        slice_memb.enacted = timezone.now()
-        slice_memb.save(update_fields=['enacted'])
-
-
-    @require_enabled
-    def delete_slice_membership(self, slice_memb):
-        self.driver.delete_user_role(slice_memb.user.kuser_id,
-                                     slice_memb.slice.tenant_id,
-                                     slice_memb.role.role_type)
-
-
-    @require_enabled
-    def get_next_subnet(self):
-        # limit ourself to 10.0.x.x for now
-        valid_subnet = lambda net: net.startswith('10.0')  
-        subnets = self.driver.shell.neutron.list_subnets()['subnets']
-        ints = [int(IPNetwork(subnet['cidr']).ip) for subnet in subnets \
-                if valid_subnet(subnet['cidr'])] 
-        ints.sort()
-        last_ip = IPAddress(ints[-1])
-        last_network = IPNetwork(str(last_ip) + "/24")
-        next_network = IPNetwork(str(IPAddress(last_network) + last_network.size) + "/24")
-        return next_network
-
-    @require_enabled
-    def save_subnet(self, subnet):    
-        if not subnet.subnet_id:
-            neutron_subnet = self.driver.create_subnet(name= subnet.slice.name,
-                                          network_id=subnet.slice.network_id,
-                                          cidr_ip = subnet.cidr,
-                                          ip_version=subnet.ip_version,
-                                          start = subnet.start,
-                                          end = subnet.end)
-            subnet.subnet_id = neutron_subnet['id']
-            # add subnet as interface to slice's router
-            self.driver.add_router_interface(subnet.slice.router_id, subnet.subnet_id)
-            #add_route = 'route add -net %s dev br-ex gw 10.100.0.5' % self.cidr
-            #commands.getstatusoutput(add_route)
-
-    
-    @require_enabled
-    def delete_subnet(self, subnet):
-        if subnet.subnet_id:
-            self.driver.delete_router_interface(subnet.slice.router_id, subnet.subnet_id)
-            self.driver.delete_subnet(subnet.subnet_id)
-            #del_route = 'route del -net %s' % self.cidr
-            #commands.getstatusoutput(del_route)
-
-    def get_requested_networks(self, slice):
-        network_ids = [x.network_id for x in slice.networks.all()]
-
-        if slice.network_id is not None:
-            network_ids.append(slice.network_id)
-
-        networks = []
-        for network_id in network_ids:
-            networks.append({"net-id": network_id})
-
-        return networks
-
-    @require_enabled
-    def save_instance(self, instance):
-        metadata_update = {}
-        if ("numberCores" in instance.changed_fields):
-            metadata_update["cpu_cores"] = str(instance.numberCores)
-
-        for tag in instance.slice.tags.all():
-            if tag.name.startswith("sysctl-"):
-                metadata_update[tag.name] = tag.value
-
-        if not instance.instance_id:
-            nics = self.get_requested_networks(instance.slice)
-            for nic in nics:
-                # If a network hasn't been instantiated yet, then we'll fail
-                # during slice creation. Defer saving the instance for now.
-                if not nic.get("net-id", None):
-                    instance.save()   # in case it hasn't been saved yet
-                    return
-            slice_memberships = SliceMembership.objects.filter(slice=instance.slice)
-            pubkeys = [sm.user.public_key for sm in slice_memberships if sm.user.public_key]
-            pubkeys.append(instance.creator.public_key)
-            instance = self.driver.spawn_instance(name=instance.name,
-                                   key_name = instance.creator.keyname,
-                                   image_id = instance.image.image_id,
-                                   hostname = instance.node.name,
-                                   pubkeys = pubkeys,
-                                   nics = nics,
-                                   metadata = metadata_update )
-            instance.instance_id = instance.id
-            instance.instance_name = getattr(instance, 'OS-EXT-SRV-ATTR:instance_name')
-        else:
-            if metadata_update:
-                self.driver.update_instance_metadata(instance.instance_id, metadata_update)
-
-        instance.save()
-        instance.enacted = timezone.now()
-        instance.save(update_fields=['enacted'])
-
-    @require_enabled
-    def delete_instance(self, instance):
-        if instance.instance_id:
-            self.driver.destroy_instance(instance.instance_id) 
-    
-
-    def refresh_nodes(self):
-        # collect local nodes
-        nodes = Node.objects.all()
-        nodes_dict = {}
-        for node in nodes:
-            if 'viccidev10' not in node.name:
-                nodes_dict[node.name] = node 
-        
-        deployment = Deployment.objects.filter(name='VICCI')[0]
-        login_bases = ['princeton', 'stanford', 'gt', 'uw', 'mpisws']
-        sites = Site.objects.filter(login_base__in=login_bases)
-        # collect nova nodes:
-        compute_nodes = self.client.nova.hypervisors.list()
-
-        compute_nodes_dict = {}
-        for compute_node in compute_nodes:
-            compute_nodes_dict[compute_node.hypervisor_hostname] = compute_node
-
-        # add new nodes:
-        new_node_names = set(compute_nodes_dict.keys()).difference(nodes_dict.keys())
-        i = 0
-        max = len(sites)
-        for name in new_node_names:
-            if i == max:
-                i = 0
-            site = sites[i]
-            node = Node(name=compute_nodes_dict[name].hypervisor_hostname,
-                        site=site,
-                        deployment=deployment)
-            node.save()
-            i+=1
-
-        # remove old nodes
-        old_node_names = set(nodes_dict.keys()).difference(compute_nodes_dict.keys())
-        Node.objects.filter(name__in=old_node_names).delete()
-
-    def refresh_images(self):
-        from core.models.image import Image
-        # collect local images
-        images = Image.objects.all()
-        images_dict = {}
-        for image in images:
-            images_dict[image.name] = image
-
-        # collect glance images
-        glance_images = self.client.glance.get_images()
-        glance_images_dict = {}
-        for glance_image in glance_images:
-            glance_images_dict[glance_image['name']] = glance_image
-
-        # add new images
-        new_image_names = set(glance_images_dict.keys()).difference(images_dict.keys())
-        for name in new_image_names:
-            image = Image(image_id=glance_images_dict[name]['id'],
-                          name=glance_images_dict[name]['name'],
-                          disk_format=glance_images_dict[name]['disk_format'],
-                          container_format=glance_images_dict[name]['container_format'])
-            image.save()
-
-        # remove old images
-        old_image_names = set(images_dict.keys()).difference(glance_images_dict.keys())
-        Image.objects.filter(name__in=old_image_names).delete()
-
-    @require_enabled
-    def save_network(self, network):
-        if not network.network_id:
-            if network.template.shared_network_name:
-                network.network_id = network.template.shared_network_id
-                (network.subnet_id, network.subnet) = self.driver.get_network_subnet(network.network_id)
-            else:
-                network_name = network.name
-
-                # create network
-                os_network = self.driver.create_network(network_name, shared=True)
-                network.network_id = os_network['id']
-
-                # create router
-                router = self.driver.create_router(network_name)
-                network.router_id = router['id']
-
-                # create subnet
-                next_subnet = self.get_next_subnet()
-                cidr = str(next_subnet.cidr)
-                ip_version = next_subnet.version
-                start = str(next_subnet[2])
-                end = str(next_subnet[-2])
-                subnet = self.driver.create_subnet(name=network_name,
-                                                   network_id = network.network_id,
-                                                   cidr_ip = cidr,
-                                                   ip_version = ip_version,
-                                                   start = start,
-                                                   end = end)
-                network.subnet = cidr
-                network.subnet_id = subnet['id']
-                # add subnet as interface to slice's router
-                self.driver.add_router_interface(router['id'], subnet['id'])
-                # add external route
-                self.driver.add_external_route(subnet)
-
-        network.save()
-        network.enacted = timezone.now()
-        network.save(update_fields=['enacted'])
-
-    def delete_network(self, network):
-        if (network.router_id) and (network.subnet_id):
-            self.driver.delete_router_interface(network.router_id, network.subnet_id)
-        if network.subnet_id:
-            self.driver.delete_subnet(network.subnet_id)
-        if network.router_id:
-            self.driver.delete_router(network.router_id)
-        if network.network_id:
-            self.driver.delete_network(network.network_id)
-
-    def save_network_template(self, template):
-        if (template.shared_network_name) and (not template.shared_network_id):
-            os_networks = self.driver.shell.neutron.list_networks(name=template.shared_network_name)['networks']
-            if os_networks:
-                template.shared_network_id = os_networks[0]["id"]
-
-        template.save()
-        template.enacted = timezone.now()
-        template.save(update_fields=['enacted'])
-
-    def find_or_make_template_for_network(self, name):
-        """ Given a network name, try to guess the right template for it """
-
-        # templates for networks we may encounter
-        if name=='nat-net':
-            template_dict = None # {"name": "private-nat", "visibility": "private", "translation": "nat"}
-        elif name=='sharednet1':
-            template_dict = {"name": "dedicated-public", "visibility": "public", "translation": "none"}
-        else:
-            template_dict = {"name": "private", "visibility": "private", "translation": "none"}
-
-        # if we have an existing template return it
-        templates = NetworkTemplate.objects.filter(name=template_dict["name"])
-        if templates:
-            return templates[0]
-
-        if template_dict == None:
-            return None
-
-        template = NetworkTemplate(**template_dict)
-        template.save()
-        return template
-
-    def refresh_network_templates(self):
-        for template in NetworkTemplate.objects.all():
-            if (template.shared_network_name) and (not template.shared_network_id):
-                 # this will cause us to try to fill in the shared_network_id
-                 self.save_network_template(template)
-
-    def refresh_networks(self):
-        # get a list of all networks in the model
-
-        networks = Network.objects.all()
-        networks_by_name = {}
-        networks_by_id = {}
-        for network in networks:
-            networks_by_name[network.name] = network
-            networks_by_id[network.network_id] = network
-
-        # Get a list of all shared networks in OS
-
-        os_networks = self.driver.shell.neutron.list_networks()['networks']
-        os_networks_by_name = {}
-        os_networks_by_id = {}
-        for os_network in os_networks:
-            os_networks_by_name[os_network['name']] = os_network
-            os_networks_by_id[os_network['id']] = os_network
-
-        for (uuid, os_network) in os_networks_by_id.items():
-            #print "checking OS network", os_network['name']
-            if (os_network['shared']) and (uuid not in networks_by_id):
-                # Only automatically create shared networks. This is for Andy's
-                # nat-net and sharednet1.
-
-                owner_slice = Slice.objects.get(tenant_id = os_network['tenant_id'])
-                template = self.find_or_make_template_for_network(os_network['name'])
-
-                if (template is None):
-                    # This is our way of saying we don't want to auto-instantiate
-                    # this network type.
-                    continue
-
-                (subnet_id, subnet) = self.driver.get_network_subnet(os_network['id'])
-
-                if owner_slice:
-                    #print "creating model object for OS network", os_network['name']
-                    new_network = Network(name = os_network['name'],
-                                          template = template,
-                                          owner = owner_slice,
-                                          network_id = uuid,
-                                          subnet_id = subnet_id)
-                    new_network.save()
-
-        for (network_id, network) in networks_by_id.items():
-            # If the network disappeared from OS, then reset its network_id to None
-            if (network.network_id is not None) and (network.network_id not in os_networks_by_id):
-                network.network_id = None
-
-            # If no OS object exists, then saving the network will create one
-            if (network.network_id is None):
-                #print "creating OS network for", network.name
-                self.save_network(network)
-            else:
-                pass #print "network", network.name, "has its OS object"
-
-
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
index 695349e..a3bc273 100644
--- a/xos/synchronizer/manifest
+++ b/xos/synchronizer/manifest
@@ -14,9 +14,7 @@
 steps/sync_controller_users.py
 steps/purge_disabled_users.py
 steps/__init__.py
-steps/sync_images.py
 steps/sync_controller_sites.py
-steps/sync_object.py
 steps/sync_controller_sites.yaml
 steps/sync_controller_users.yaml
 steps/sync_controller_images.py
@@ -29,10 +27,10 @@
 steps/sync_controller_site_privileges.py
 steps/delete_slivers.yaml
 steps/sync_container.py
+steps/sync_images.py
 steps/sync_roles.py
 steps/sync_controller_slices.yaml
 steps/teardown_container.yaml
-manager.py
 driver.py
 error_mapper.py
 xos-synchronizer.py
diff --git a/xos/synchronizer/model_policies/model_policy_Controller.py b/xos/synchronizer/model_policies/model_policy_Controller.py
index c62b612..2ff25d4 100644
--- a/xos/synchronizer/model_policies/model_policy_Controller.py
+++ b/xos/synchronizer/model_policies/model_policy_Controller.py
@@ -1,8 +1,7 @@
+from collections import defaultdict
+from synchronizers.new_base.modelaccessor import *
 
 def handle(controller):
-    from core.models import Controller, Site, ControllerSite, Slice, ControllerSlice, User, ControllerUser, ControllerImages, ControllerNetwork, Image, Network
-    from collections import defaultdict
-
     # relations for all sites
     ctrls_by_site = defaultdict(list)
     ctrl_sites = ControllerSite.objects.all()
diff --git a/xos/synchronizer/model_policies/model_policy_ControllerSite.py b/xos/synchronizer/model_policies/model_policy_ControllerSite.py
index 4b76080..3b7a037 100644
--- a/xos/synchronizer/model_policies/model_policy_ControllerSite.py
+++ b/xos/synchronizer/model_policies/model_policy_ControllerSite.py
@@ -1,6 +1,6 @@
+from synchronizers.new_base.modelaccessor import *
+
 def handle(controller_site):
-    from core.models import ControllerSite, Site
-   
     try:
         my_status_code = int(controller_site.backend_status[0])
         try:
diff --git a/xos/synchronizer/model_policies/model_policy_ControllerSlice.py b/xos/synchronizer/model_policies/model_policy_ControllerSlice.py
index bfe7995..3c6d54f 100644
--- a/xos/synchronizer/model_policies/model_policy_ControllerSlice.py
+++ b/xos/synchronizer/model_policies/model_policy_ControllerSlice.py
@@ -1,6 +1,6 @@
+from synchronizers.new_base.modelaccessor import *
+
 def handle(controller_slice):
-    from core.models import ControllerSlice, Slice
-   
     try:
         my_status_code = int(controller_slice.backend_status[0])
         try:
diff --git a/xos/synchronizer/model_policies/model_policy_ControllerUser.py b/xos/synchronizer/model_policies/model_policy_ControllerUser.py
index b69c9b8..895ebf8 100644
--- a/xos/synchronizer/model_policies/model_policy_ControllerUser.py
+++ b/xos/synchronizer/model_policies/model_policy_ControllerUser.py
@@ -1,6 +1,6 @@
+from synchronizers.new_base.modelaccessor import *
+
 def handle(controller_user):
-    from core.models import ControllerUser, User
-   
     try:
         my_status_code = int(controller_user.backend_status[0])
         try:
diff --git a/xos/synchronizer/model_policies/model_policy_Image.py b/xos/synchronizer/model_policies/model_policy_Image.py
index c77d5bb..6d6982e 100644
--- a/xos/synchronizer/model_policies/model_policy_Image.py
+++ b/xos/synchronizer/model_policies/model_policy_Image.py
@@ -1,7 +1,6 @@
-def handle(image):
-    from core.models import Controller, ControllerImages, Image
-    from collections import defaultdict
+from synchronizers.new_base.modelaccessor import *
 
+def handle(image):
     if (image.kind == "container"):
         # container images do not get instantiated
         return
diff --git a/xos/synchronizer/model_policies/model_policy_Instance.py b/xos/synchronizer/model_policies/model_policy_Instance.py
index dd1a8d5..c810a96 100644
--- a/xos/synchronizer/model_policies/model_policy_Instance.py
+++ b/xos/synchronizer/model_policies/model_policy_Instance.py
@@ -1,6 +1,6 @@
-def handle_container_on_metal(instance):
-        from core.models import Instance, Flavor, Port, Image
+from synchronizers.new_base.modelaccessor import *
 
+def handle_container_on_metal(instance):
         print "MODEL POLICY: instance", instance, "handle container_on_metal"
 
         if instance.deleted:
@@ -10,7 +10,7 @@
             # Our current docker-on-metal network strategy requires that there be some
             # VM on the server that connects to the networks, so that
             # the containers can piggyback off of that configuration.
-            if not Instance.objects.filter(slice=instance.slice, node=instance.node, isolation="vm").exists():
+            if not Instance.objects.filter(slice_id=instance.slice.id, node_id=instance.node.id, isolation="vm").exists():
                 flavors = Flavor.objects.filter(name="m1.small")
                 if not flavors:
                     raise XOSConfigurationError("No m1.small flavor")
@@ -35,17 +35,18 @@
             if (network.name.endswith("-nat")):
                 continue
 
-            if not Port.objects.filter(network=network, instance=instance).exists():
+            if not Port.objects.filter(network_id=network.id, instance_id=instance.id).exists():
                 port = Port(network = network, instance=instance)
                 port.save()
                 print "MODEL POLICY: instance", instance, "created port", port
 
 def handle(instance):
-    from core.models import Controller, ControllerSlice, ControllerNetwork, NetworkSlice
-
     networks = [ns.network for ns in NetworkSlice.objects.filter(slice=instance.slice)]
-    controller_networks = ControllerNetwork.objects.filter(network__in=networks,
-                                                                controller=instance.node.site_deployment.controller)
+    controller_networks = ControllerNetwork.objects.filter(controller=instance.node.site_deployment.controller)
+
+    # a little clumsy because the API ORM doesn't support __in queries
+    network_ids = [x.id for x in networks]
+    controller_networks = [x for x in controller_networks if x.network.id in network_ids]
 
     for cn in controller_networks:
         if (cn.lazy_blocked):
diff --git a/xos/synchronizer/model_policies/model_policy_Network.py b/xos/synchronizer/model_policies/model_policy_Network.py
index 06347c5..b3f45ce 100644
--- a/xos/synchronizer/model_policies/model_policy_Network.py
+++ b/xos/synchronizer/model_policies/model_policy_Network.py
@@ -1,9 +1,7 @@
-from core.models import *
+from synchronizers.new_base.modelaccessor import *
+from collections import defaultdict
 
 def handle(network):
-	from core.models import ControllerSlice,ControllerNetwork, Network
-	from collections import defaultdict
-
         print "MODEL POLICY: network", network
 
         # network = Network.get(network_id)
@@ -27,7 +25,11 @@
 
                         # check and see if some instance already exists
                         for networkslice in network.networkslices.all():
-                            if networkslice.slice.instances.filter(node__site_deployment__controller=expected_controller).exists():
+                            found = False
+                            for instance in networkslice.slice.instances.all():
+                               if instance.node.site_deployment.controller.id == expected_controller.id:
+                                   found = True
+                            if found:
                                print "MODEL_POLICY: network, setting lazy_blocked to false because instance on controller already exists"
                                lazy_blocked=False
 
diff --git a/xos/synchronizer/model_policies/model_policy_Site.py b/xos/synchronizer/model_policies/model_policy_Site.py
index 23010a2..f800092 100644
--- a/xos/synchronizer/model_policies/model_policy_Site.py
+++ b/xos/synchronizer/model_policies/model_policy_Site.py
@@ -1,10 +1,9 @@
+from synchronizers.new_base.modelaccessor import *
 
 def handle(site):
-    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)
+    ctrl_sites = ControllerSite.objects.filter(site_id=site.id)
     existing_controllers = [cs.controller for cs in ctrl_sites]
 
     all_controllers = Controller.objects.all()
diff --git a/xos/synchronizer/model_policies/model_policy_SitePrivilege.py b/xos/synchronizer/model_policies/model_policy_SitePrivilege.py
index d9c6a1e..2218994 100644
--- a/xos/synchronizer/model_policies/model_policy_SitePrivilege.py
+++ b/xos/synchronizer/model_policies/model_policy_SitePrivilege.py
@@ -1,10 +1,10 @@
+from synchronizers.new_base.modelaccessor import *
+
 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,
+        site_privilege_id = site_privilege.id,
         )
     existing_controllers = [sp.controller for sp in controller_site_privileges]
     all_controllers = Controller.objects.all()
diff --git a/xos/synchronizer/model_policies/model_policy_Slice.py b/xos/synchronizer/model_policies/model_policy_Slice.py
index 088d583..953d2c9 100644
--- a/xos/synchronizer/model_policies/model_policy_Slice.py
+++ b/xos/synchronizer/model_policies/model_policy_Slice.py
@@ -1,22 +1,17 @@
 from xos.config import Config
+from synchronizers.new_base.modelaccessor import *
 
 def handle_delete(slice):
-    from core.models import Controller, ControllerSlice, SiteDeployment, Network, NetworkSlice,NetworkTemplate, Slice
-    from collections import defaultdict
-
     public_nets = []
     private_net = None
-    networks = Network.objects.filter(owner=slice)
+    networks = Network.objects.filter(owner_id=slice.id)
 
     for n in networks:
-        n.delete()	
-    
+        n.delete()
+
     # Note that sliceprivileges and slicecontrollers are autodeleted, through the dependency graph
 
 def handle(slice):
-    from core.models import Controller, ControllerSlice, SiteDeployment, Network, NetworkSlice,NetworkTemplate, Slice
-    from collections import defaultdict
-
     # only create nat_net if not using VTN
     support_nat_net = not getattr(Config(), "networking_use_vtn", False)
 
@@ -24,7 +19,7 @@
 
     # slice = Slice.get(slice_id)
 
-    controller_slices = ControllerSlice.objects.filter(slice=slice)
+    controller_slices = ControllerSlice.objects.filter(slice_id=slice.id)
     existing_controllers = [cs.controller for cs in controller_slices] 
         
     print "MODEL POLICY: slice existing_controllers=", existing_controllers
@@ -47,7 +42,7 @@
         # make sure slice has at least 1 public and 1 private networkd
         public_nets = []
         private_nets = []
-        networks = Network.objects.filter(owner=slice)
+        networks = Network.objects.filter(owner_id=slice.id)
         for network in networks:
             if not network.autoconnect:
                 continue
@@ -82,7 +77,12 @@
         # create slice networks
         public_net_slice = None
         private_net_slice = None
-        net_slices = NetworkSlice.objects.filter(slice=slice, network__in=private_nets+public_nets)
+
+        public_net_ids = [x.id for x in public_nets]
+        private_net_ids = [x.id for x in private_nets]
+        net_slices = NetworkSlice.objects.filter(slice_id=slice.id)
+        net_slices = [x for x in net_slices if x.network_id in public_net_ids+private_net_ids]
+
         for net_slice in net_slices:
             if net_slice.network in public_nets:
                 public_net_slice = net_slice
diff --git a/xos/synchronizer/model_policies/model_policy_SlicePrivilege.py b/xos/synchronizer/model_policies/model_policy_SlicePrivilege.py
index bca7f22..f4fab58 100644
--- a/xos/synchronizer/model_policies/model_policy_SlicePrivilege.py
+++ b/xos/synchronizer/model_policies/model_policy_SlicePrivilege.py
@@ -1,7 +1,7 @@
+from synchronizers.new_base.modelaccessor import *
+
 def handle(slice_privilege):
-    from core.models import Controller, SlicePrivilege, ControllerSlicePrivilege
-   
-    # slice_privilege = SlicePrivilege.get(slice_privilege_id) 
+    # 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/xos/synchronizer/model_policies/model_policy_Sliver.py b/xos/synchronizer/model_policies/model_policy_Sliver.py
index a13428d..2f1f203 100644
--- a/xos/synchronizer/model_policies/model_policy_Sliver.py
+++ b/xos/synchronizer/model_policies/model_policy_Sliver.py
@@ -1,10 +1,10 @@
+from synchronizers.new_base.modelaccessor import *
 
 def handle(instance):
-    from core.models import Controller, ControllerSlice, ControllerNetwork, NetworkSlice
-
-    networks = [ns.network for ns in NetworkSlice.objects.filter(slice=instance.slice)]
-    controller_networks = ControllerNetwork.objects.filter(network__in=networks,
-                                                                controller=instance.node.site_deployment.controller)
+    networks = [ns.network for ns in NetworkSlice.objects.filter(slice_id=instance.slice.id)]
+    network_ids = [x.id for x in networks]
+    controller_networks = ControllerNetwork.objects.filter(controller_id=instance.node.site_deployment.controller.id)
+    controller_networks = [x for x in controller_networks if x.network_id in network_ids]
 
     for cn in controller_networks:
         if (cn.lazy_blocked):	
diff --git a/xos/synchronizer/model_policies/model_policy_User.py b/xos/synchronizer/model_policies/model_policy_User.py
index 8d14244..cc37db1 100644
--- a/xos/synchronizer/model_policies/model_policy_User.py
+++ b/xos/synchronizer/model_policies/model_policy_User.py
@@ -1,7 +1,6 @@
-def handle(user):
-    from core.models import Controller, ControllerSite, ControllerUser, User
-    from collections import defaultdict
+from synchronizers.new_base.modelaccessor import *
 
+def handle(user):
     # user = User.get(user_id)
     
     controller_users = ControllerUser.objects.filter(user=user)
diff --git a/xos/synchronizer/openstacksyncstep.py b/xos/synchronizer/openstacksyncstep.py
index 46056cf..49b4623 100644
--- a/xos/synchronizer/openstacksyncstep.py
+++ b/xos/synchronizer/openstacksyncstep.py
@@ -1,6 +1,6 @@
 import os
 import base64
-from synchronizers.base.syncstep import SyncStep
+from synchronizers.new_base.syncstep import SyncStep
 
 class OpenStackSyncStep(SyncStep):
     """ XOS Sync step for copying data to OpenStack 
diff --git a/xos/synchronizer/steps/purge_disabled_users.py b/xos/synchronizer/steps/purge_disabled_users.py
index 5cb7b06..425d4e4 100644
--- a/xos/synchronizer/steps/purge_disabled_users.py
+++ b/xos/synchronizer/steps/purge_disabled_users.py
@@ -1,11 +1,10 @@
 import os
 import base64
 import datetime
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from core.models.user import User
 from xos.logger import observer_logger as logger
+from synchronizers.new_base.modelaccessor import *
 
 #class SyncRoles(OpenStackSyncStep):
 #    provides=[User]
diff --git a/xos/synchronizer/steps/sync_container.py b/xos/synchronizer/steps/sync_container.py
index 9449af1..7b69fa5 100644
--- a/xos/synchronizer/steps/sync_container.py
+++ b/xos/synchronizer/steps/sync_container.py
@@ -4,13 +4,12 @@
 import sys
 import base64
 import time
-from django.db.models import F, Q
 from xos.config import Config
-from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
-from synchronizers.base.syncstep import SyncStep, DeferredException
-from synchronizers.base.ansible_helper import run_template_ssh
-from core.models import Service, Slice, Instance
+from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+from synchronizers.new_base.syncstep import DeferredException
+from synchronizers.new_base.ansible_helper import run_template_ssh
 from xos.logger import Logger, logging
+from synchronizers.new_base.modelaccessor import *
 
 # hpclibrary will be in steps/..
 parentdir = os.path.join(os.path.dirname(__file__),"..")
@@ -34,7 +33,7 @@
 
     def get_instance_port(self, container_port):
         for p in container_port.network.links.all():
-            if (p.instance) and (p.instance.isolation=="vm") and (p.instance.node == container_port.instance.node) and (p.mac):
+            if (p.instance) and (p.instance.isolation=="vm") and (p.instance.node.id == container_port.instance.node.id) and (p.mac):
                 return p
         return None
 
diff --git a/xos/synchronizer/steps/sync_controller_images.py b/xos/synchronizer/steps/sync_controller_images.py
index b944dca..2241fec 100644
--- a/xos/synchronizer/steps/sync_controller_images.py
+++ b/xos/synchronizer/steps/sync_controller_images.py
@@ -1,15 +1,11 @@
 import os
 import base64
-from collections import defaultdict
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from synchronizers.base.syncstep import *
-from core.models import Controller
-from core.models import Image, ControllerImages
-from xos.logger import observer_logger as logger 
-from synchronizers.base.ansible_helper import *
-import json
+from synchronizers.new_base.syncstep import *
+from xos.logger import observer_logger as logger
+from synchronizers.new_base.ansible_helper import *
+from synchronizers.new_base.modelaccessor import *
 
 class SyncControllerImages(OpenStackSyncStep):
     provides=[ControllerImages]
@@ -21,8 +17,7 @@
         if (deleted):
             return []
 
-        # now we return all images that need to be enacted
-        return ControllerImages.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
+        return super(SyncControllerImages, self).fetch_pending(deleted)
 
     def map_sync_inputs(self, controller_image):
         image_fields = {'endpoint':controller_image.controller.auth_url,
diff --git a/xos/synchronizer/steps/sync_controller_networks.py b/xos/synchronizer/steps/sync_controller_networks.py
index 357b084..8187e84 100644
--- a/xos/synchronizer/steps/sync_controller_networks.py
+++ b/xos/synchronizer/steps/sync_controller_networks.py
@@ -2,21 +2,14 @@
 import base64
 import struct
 import socket
-from collections import defaultdict
 from netaddr import IPAddress, IPNetwork
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from synchronizers.base.syncstep import *
-from core.models.network import *
-from core.models.slice import *
-from core.models.instance import Instance
+from synchronizers.new_base.syncstep import *
 from xos.logger import observer_logger as logger
-from synchronizers.base.ansible_helper import *
+from synchronizers.new_base.ansible_helper import *
 from xos.config import Config
-import json
-
-import pdb
+from synchronizers.new_base.modelaccessor import *
 
 class SyncControllerNetworks(OpenStackSyncStep):
     requested_interval = 0
diff --git a/xos/synchronizer/steps/sync_controller_site_privileges.py b/xos/synchronizer/steps/sync_controller_site_privileges.py
index 805f446..2768090 100644
--- a/xos/synchronizer/steps/sync_controller_site_privileges.py
+++ b/xos/synchronizer/steps/sync_controller_site_privileges.py
@@ -1,16 +1,12 @@
 import os
 import base64
-from collections import defaultdict
-from django.db.models import F, Q
+import json
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from synchronizers.base.syncstep import *
-from core.models.site import Controller, SitePrivilege 
-from core.models.user import User
-from core.models.controlleruser import ControllerUser, ControllerSitePrivilege
+from synchronizers.new_base.syncstep import *
 from xos.logger import observer_logger as logger
-from synchronizers.base.ansible_helper import *
-import json
+from synchronizers.new_base.ansible_helper import *
+from synchronizers.new_base.modelaccessor import *
 
 class SyncControllerSitePrivileges(OpenStackSyncStep):
     provides=[SitePrivilege]
diff --git a/xos/synchronizer/steps/sync_controller_sites.py b/xos/synchronizer/steps/sync_controller_sites.py
index 1a1ce41..ba489aa 100644
--- a/xos/synchronizer/steps/sync_controller_sites.py
+++ b/xos/synchronizer/steps/sync_controller_sites.py
@@ -1,13 +1,12 @@
 import os
 import base64
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from core.models.site import *
-from synchronizers.base.syncstep import *
-from synchronizers.base.ansible_helper import *
+from synchronizers.new_base.syncstep import *
+from synchronizers.new_base.ansible_helper import *
 from xos.logger import observer_logger as logger
 import json
+from synchronizers.new_base.modelaccessor import *
 
 class SyncControllerSites(OpenStackSyncStep):
     requested_interval=0
@@ -16,7 +15,12 @@
     playbook = 'sync_controller_sites.yaml'
 
     def fetch_pending(self, deleted=False):
-        lobjs = ControllerSite.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False),Q(controller__isnull=False))
+        lobjs = super(SyncControllerSites, self).fetch_pending(deleted)
+
+        if not deleted:
+            # filter out objects with null controllers
+            lobjs = [x for x in lobjs if x.controller]
+
         return lobjs
 
     def map_sync_inputs(self, controller_site):
diff --git a/xos/synchronizer/steps/sync_controller_slice_privileges.py b/xos/synchronizer/steps/sync_controller_slice_privileges.py
index b7c0487..3a2d167 100644
--- a/xos/synchronizer/steps/sync_controller_slice_privileges.py
+++ b/xos/synchronizer/steps/sync_controller_slice_privileges.py
@@ -1,16 +1,12 @@
 import os
 import base64
-from collections import defaultdict
-from django.db.models import F, Q
+import json
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from synchronizers.base.syncstep import *
-from core.models.slice import Controller, SlicePrivilege 
-from core.models.user import User
-from core.models.controlleruser import ControllerUser, ControllerSlicePrivilege
-from synchronizers.base.ansible_helper import *
+from synchronizers.new_base.syncstep import *
+from synchronizers.new_base.ansible_helper import *
 from xos.logger import observer_logger as logger
-import json
+from synchronizers.new_base.modelaccessor import *
 
 class SyncControllerSlicePrivileges(OpenStackSyncStep):
     provides=[SlicePrivilege]
@@ -29,15 +25,6 @@
         if not controller_slice_privilege.slice_privilege.user.site:
             raise Exception('Sliceless user %s'%controller_slice_privilege.slice_privilege.user.email)
         else:
-            # look up tenant id for the user's slice at the controller
-            #ctrl_slice_deployments = SliceDeployment.objects.filter(
-            #  slice_deployment__slice=controller_slice_privilege.user.slice,
-            #  controller=controller_slice_privilege.controller)
-
-            #if ctrl_slice_deployments:
-            #    # need the correct tenant id for slice at the controller
-            #    tenant_id = ctrl_slice_deployments[0].tenant_id  
-            #    tenant_name = ctrl_slice_deployments[0].slice_deployment.slice.login_base
             user_fields = {
                'endpoint':controller_slice_privilege.controller.auth_url,
                'endpoint_v3': controller_slice_privilege.controller.auth_url_v3,
@@ -64,14 +51,16 @@
 
         if controller_slice_privilege.role_id:
             driver = self.driver.admin_driver(controller=controller_slice_privilege.controller)
-            user = ControllerUser.objects.get(
-                controller=controller_slice_privilege.controller, 
-                user=controller_slice_privilege.slice_privilege.user
+            user = ControllerUser.objects.filter(
+                controller_id=controller_slice_privilege.controller.id,
+                user_id=controller_slice_privilege.slice_privilege.user.id
             )
-            slice = ControllerSlice.objects.get(
-                controller=controller_slice_privilege.controller, 
-                user=controller_slice_privilege.slice_privilege.user
+            user = user[0]
+            slice = ControllerSlice.objects.filter(
+                controller_id=controller_slice_privilege.controller.id,
+                user_id=controller_slice_privilege.slice_privilege.user.id
             )
+            slice = slice[0]
             driver.delete_user_role(
                 user.kuser_id, 
                 slice.tenant_id, 
diff --git a/xos/synchronizer/steps/sync_controller_slices.py b/xos/synchronizer/steps/sync_controller_slices.py
index 2bc0555..a01c2b2 100644
--- a/xos/synchronizer/steps/sync_controller_slices.py
+++ b/xos/synchronizer/steps/sync_controller_slices.py
@@ -1,15 +1,11 @@
 import os
 import base64
-from collections import defaultdict
-from netaddr import IPAddress, IPNetwork
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from synchronizers.base.syncstep import *
-from core.models import *
-from synchronizers.base.ansible_helper import *
+from synchronizers.new_base.syncstep import *
+from synchronizers.new_base.ansible_helper import *
 from xos.logger import observer_logger as logger
-import json
+from synchronizers.new_base.modelaccessor import *
 
 class SyncControllerSlices(OpenStackSyncStep):
     provides=[Slice]
@@ -24,8 +20,8 @@
             logger.info("controller %r has no admin_user, skipping" % controller_slice.controller)
             return
 
-        controller_users = ControllerUser.objects.filter(user=controller_slice.slice.creator,
-                                                             controller=controller_slice.controller)
+        controller_users = ControllerUser.objects.filter(user_id=controller_slice.slice.creator.id,
+                                                             controller_id=controller_slice.controller.id)
         if not controller_users:
             raise Exception("slice createor %s has not accout at controller %s" % (controller_slice.slice.creator, controller_slice.controller.name))
         else:
@@ -65,8 +61,8 @@
 
 
     def map_delete_inputs(self, controller_slice):
-        controller_users = ControllerUser.objects.filter(user=controller_slice.slice.creator,
-                                                              controller=controller_slice.controller)
+        controller_users = ControllerUser.objects.filter(user_id=controller_slice.slice.creator.id,
+                                                              controller_id=controller_slice.controller.id)
         if not controller_users:
             raise Exception("slice createor %s has not accout at controller %s" % (controller_slice.slice.creator, controller_slice.controller.name))
         else:
diff --git a/xos/synchronizer/steps/sync_controller_users.py b/xos/synchronizer/steps/sync_controller_users.py
index 189703a..449dc11 100644
--- a/xos/synchronizer/steps/sync_controller_users.py
+++ b/xos/synchronizer/steps/sync_controller_users.py
@@ -1,16 +1,11 @@
 import os
 import base64
-from collections import defaultdict
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from synchronizers.base.syncstep import *
-from core.models.site import Controller, SiteDeployment, SiteDeployment
-from core.models.user import User
-from core.models.controlleruser import ControllerUser
-from synchronizers.base.ansible_helper import *
+from synchronizers.new_base.syncstep import *
+from synchronizers.new_base.ansible_helper import *
 from xos.logger import observer_logger as logger
-import json
+from synchronizers.new_base.modelaccessor import *
 
 class SyncControllerUsers(OpenStackSyncStep):
     provides=[User]
@@ -35,15 +30,6 @@
         if not controller_user.user.site:
             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 = SiteDeployment.objects.filter(
-            #  site_deployment__site=controller_user.user.site,
-            #  controller=controller_user.controller)
-
-            #if ctrl_site_deployments:
-            #    # need the correct tenant id for site at the controller
-            #    tenant_id = ctrl_site_deployments[0].tenant_id
-            #    tenant_name = ctrl_site_deployments[0].site_deployment.site.login_base
             user_fields = {
                 'endpoint':controller_user.controller.auth_url,
                 'endpoint_v3': controller_user.controller.auth_url_v3,
diff --git a/xos/synchronizer/steps/sync_images.py b/xos/synchronizer/steps/sync_images.py
index d4ef430..61e8f18 100644
--- a/xos/synchronizer/steps/sync_images.py
+++ b/xos/synchronizer/steps/sync_images.py
@@ -1,52 +1,15 @@
 import os
 import base64
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from core.models.image import Image
 from xos.logger import observer_logger as logger
+from synchronizers.new_base.modelaccessor import *
 
 class SyncImages(OpenStackSyncStep):
     provides=[Image]
     requested_interval=0
-    observes=Image
+    observes=[Image]
 
-    def fetch_pending(self, deleted):
-        # Images come from the back end
-        # You can't delete them
-        if (deleted):
-            logger.info("SyncImages: returning because deleted=True")
-            return []
-
-        # get list of images on disk
-        images_path = Config().observer_images_directory
-
-        logger.info("SyncImages: deleted=False, images_path=%s" % images_path)
-
-        available_images = {}
-        if os.path.exists(images_path):
-            for f in os.listdir(images_path):
-                filename = os.path.join(images_path, f)
-                if os.path.isfile(filename) and filename.endswith(".img"):
-                    available_images[f] = filename
-
-        logger.info("SyncImages: available_images = %s" % str(available_images))
-
-        images = Image.objects.all()
-        image_names = [image.name for image in images]
-
-        for image_name in available_images:
-            #remove file extension
-            clean_name = ".".join(image_name.split('.')[:-1])
-            if clean_name not in image_names:
-                logger.info("SyncImages: adding %s" % clean_name)
-                image = Image(name=clean_name,
-                              disk_format='raw',
-                              container_format='bare', 
-                              path = available_images[image_name])
-                image.save()
-
-        return Image.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) 
-
-    def sync_record(self, image):
-        image.save()
+    def sync_record(self, role):
+        # do nothing
+        pass
diff --git a/xos/synchronizer/steps/sync_instances.py b/xos/synchronizer/steps/sync_instances.py
index 395b9b1..3682fd3 100644
--- a/xos/synchronizer/steps/sync_instances.py
+++ b/xos/synchronizer/steps/sync_instances.py
@@ -1,16 +1,13 @@
 import os
 import base64
 import socket
-from django.db.models import F, Q
 from xos.config import Config
 from xos.settings import RESTAPI_HOSTNAME, RESTAPI_PORT
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from core.models.instance import Instance
-from core.models.slice import Slice, SlicePrivilege, ControllerSlice
-from core.models.network import Network, NetworkSlice, ControllerNetwork
-from synchronizers.base.ansible_helper import *
-from synchronizers.base.syncstep import *
+from synchronizers.new_base.ansible_helper import *
+from synchronizers.new_base.syncstep import *
 from xos.logger import observer_logger as logger
+from synchronizers.new_base.modelaccessor import *
 
 def escape(s):
     s = s.replace('\n',r'\n').replace('"',r'\"')
@@ -105,7 +102,7 @@
             if tag.name.startswith("sysctl-"):
                 metadata_update[tag.name] = tag.value
 
-	slice_memberships = SlicePrivilege.objects.filter(slice=instance.slice)
+	slice_memberships = SlicePrivilege.objects.filter(slice_id=instance.slice.id)
         pubkeys = set([sm.user.public_key for sm in slice_memberships if sm.user.public_key])
         if instance.creator.public_key:
             pubkeys.add(instance.creator.public_key)
@@ -120,23 +117,25 @@
 
         # handle ports the were created by the user
         port_ids=[]
-        for port in Port.objects.filter(instance=instance):
+        for port in Port.objects.filter(instance_id=instance.id):
             if not port.port_id:
                 raise DeferredException("Instance %s waiting on port %s" % (instance, port))
             nics.append({"kind": "port", "value": port.port_id, "network": port.network})
 
         # we want to exclude from 'nics' any network that already has a Port
-        existing_port_networks = [port.network for port in Port.objects.filter(instance=instance)]
+        existing_port_networks = [port.network for port in Port.objects.filter(instance_id=instance.id)]
+        existing_port_network_ids = [x.id for x in existing_port_networks]
 
-        networks = [ns.network for ns in NetworkSlice.objects.filter(slice=instance.slice) if ns.network not in existing_port_networks]
-        controller_networks = ControllerNetwork.objects.filter(network__in=networks,
-                                                                controller=instance.node.site_deployment.controller)
+        networks = [ns.network for ns in NetworkSlice.objects.filter(slice_id=instance.slice.id) if ns.network.id not in existing_port_network_ids]
+        networks_ids = [x.id for x in networks]
+        controller_networks = ControllerNetwork.objects.filter(controller_id=instance.node.site_deployment.controller.id)
+        controller_networks = [x for x in controller_networks if x.id in networks_ids]
+
 
         for network in networks:
-           if not ControllerNetwork.objects.filter(network=network, controller=instance.node.site_deployment.controller).exists():
+           if not ControllerNetwork.objects.filter(network_id=network.id, controller_id=instance.node.site_deployment.controller.id).exists():
               raise DeferredException("Instance %s Private Network %s lacks ControllerNetwork object" % (instance, network.name))
 
-        #controller_networks = self.sort_controller_networks(controller_networks)
         for controller_network in controller_networks:
             # Lenient exception - causes slow backoff
             if controller_network.network.template.translation == 'none':
@@ -148,7 +147,6 @@
         network_templates = [network.template.shared_network_name for network in networks \
                              if network.template.shared_network_name]
 
-        #driver = self.driver.client_driver(caller=instance.creator, tenant=instance.slice.name, controller=instance.controllerNetwork)
         driver = self.driver.admin_driver(tenant='admin', controller=instance.node.site_deployment.controller)
         nets = driver.shell.neutron.list_networks()['networks']
         for net in nets:
@@ -163,7 +161,8 @@
         nics = self.sort_nics(nics)
 
         image_name = None
-        controller_images = instance.image.controllerimages.filter(controller=instance.node.site_deployment.controller)
+        controller_images = instance.image.controllerimages.all()
+        controller_images = [x for x in controller_images if x.controller_id==instance.node.site_deployment.controller.id]
         if controller_images:
             image_name = controller_images[0].image.name
             logger.info("using image from ControllerImage object: " + str(image_name))
diff --git a/xos/synchronizer/steps/sync_object.py b/xos/synchronizer/steps/sync_object.py
deleted file mode 100644
index e03bf92..0000000
--- a/xos/synchronizer/steps/sync_object.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import os
-import base64
-from collections import defaultdict
-from django.db.models import F, Q
-from xos.config import Config
-from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from synchronizers.base.syncstep import *
-from core.models import *
-from synchronizers.base.ansible_helper import *
-from xos.logger import observer_logger as logger
-import json
-
-class SyncObject(OpenStackSyncStep):
-    provides=[] # Caller fills this in
-    requested_interval=0
-    observes=[] # Caller fills this in
-
-    def sync_record(self, r):
-        raise DeferredException('Waiting for Service dependency: %r'%r)
diff --git a/xos/synchronizer/steps/sync_ports.py b/xos/synchronizer/steps/sync_ports.py
index b0f1113..d6f1303 100644
--- a/xos/synchronizer/steps/sync_ports.py
+++ b/xos/synchronizer/steps/sync_ports.py
@@ -1,11 +1,9 @@
 import os
 import base64
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from core.models import Controller
-from core.models.network import *
 from xos.logger import observer_logger as logger
+from synchronizers.new_base.modelaccessor import *
 
 class SyncPorts(OpenStackSyncStep):
     requested_interval = 0 # 3600
@@ -170,14 +168,17 @@
                 continue
 
         # For ports that were created by the user, find that ones
-        # that don't have neutron ports, and create them.
-        for port in Port.objects.filter(Q(port_id__isnull=True), Q(instance__isnull=False) ):
+        # that don't have neutron ports, and create them. These are ports
+        # with a null port_id and a non-null instance_id.
+        ports = Port.objects.all()
+        ports = [x for x in ports if ((not x.port_id) and (x.instance_id))]
+        for port in ports:
             logger.info("XXX working on port %s" % port)
             controller = port.instance.node.site_deployment.controller
             slice = port.instance.slice
 
             if controller:
-                cn=port.network.controllernetworks.filter(controller=controller)
+                cn=[x for x in port.network.controllernetworks.all() if x.controller_id==controller.id]
                 if not cn:
                     logger.log_exc("no controllernetwork for %s" % port)
                     continue
diff --git a/xos/synchronizer/steps/sync_roles.py b/xos/synchronizer/steps/sync_roles.py
index 418b4ea..c202f74 100644
--- a/xos/synchronizer/steps/sync_roles.py
+++ b/xos/synchronizer/steps/sync_roles.py
@@ -1,12 +1,9 @@
 import os
 import base64
-from django.db.models import F, Q
 from xos.config import Config
 from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
-from core.models.role import Role
-from core.models.site import SiteRole, Controller, ControllerRole
-from core.models.slice import SliceRole
 from xos.logger import observer_logger as logger
+from synchronizers.new_base.modelaccessor import *
 
 class SyncRoles(OpenStackSyncStep):
     provides=[Role]
diff --git a/xos/synchronizer/xos-synchronizer.py b/xos/synchronizer/xos-synchronizer.py
index c2d9e43..6cd8e7a 100644
--- a/xos/synchronizer/xos-synchronizer.py
+++ b/xos/synchronizer/xos-synchronizer.py
@@ -6,21 +6,20 @@
 sys.path.append('/opt/xos')
 
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
-from synchronizers.base.backend import Backend
-from synchronizers.base.event_loop import set_driver
 from xos.config import Config, DEFAULT_CONFIG_FN
-from core.models import Instance,NetworkTemplate
 from xos.logger import Logger, logging, logger
-from django.db import ProgrammingError
 import time
 
-try:
-    from django import setup as django_setup # django 1.7
-except:
-    django_setup = False
+from synchronizers.new_base.modelaccessor import *
+from synchronizers.new_base.backend import Backend
+from synchronizers.new_base.event_loop import set_driver
 
 config = Config()
 
+logger = Logger(level=logging.INFO)
+
+# TODO: These two lines are the only difference between this file and
+#       new_base/xos-synchronizer.py. Reconcile these.
 # set the driver.
 from synchronizers.openstack.driver import OpenStackDriver
 set_driver(OpenStackDriver())
@@ -64,9 +63,6 @@
 
     if args.daemon: daemon()
 
-    if django_setup: # 1.7
-        django_setup()
-
     models_active = False
     wait = False
     while not models_active: