Merge "Change from Django 1.5 and earlier queryset() to Django 1.6 and later get_queryset()"
diff --git a/xos/synchronizer/steps/sync_host.yaml b/xos/synchronizer/steps/sync_host.yaml
index 58bccba..55dc70b 100644
--- a/xos/synchronizer/steps/sync_host.yaml
+++ b/xos/synchronizer/steps/sync_host.yaml
@@ -1,20 +1,8 @@
 ---
 - hosts: 127.0.0.1
   connection: local
-  vars:
-    rest_hostname: {{ rest_hostname }}
-    rest_port: {{ rest_port }}
-    rest_endpoint: {{ rest_endpoint }}
-    rest_json: '{{ rest_json }}'
 
   tasks:
-  - debug: var=rest_json
+  - name: Add host entry for fabric
+    command: curl -sS --user onos:rocks -X POST -HContent-Type:application/json -d '{{ rest_json }}' http://{{ rest_hostname }}:{{ rest_port }}/{{ rest_endpoint }}
 
-  - name: Call Fabric REST API
-    uri:
-      url: http://{{ '{{' }} rest_hostname {{ '}}' }}:{{ '{{' }} rest_port {{ '}}' }}/{{ '{{' }} rest_endpoint {{ '}}' }} #http://localhost:8181/onos/v1/network/configuration/
-      body: "{{ '{{' }} rest_json {{ '}}' }}"
-      body_format: raw
-      method: POST
-      user: karaf
-      password: karaf
diff --git a/xos/synchronizer/steps/sync_vroutertenant.py b/xos/synchronizer/steps/sync_vroutertenant.py
index fd77ca2..2f3701a 100644
--- a/xos/synchronizer/steps/sync_vroutertenant.py
+++ b/xos/synchronizer/steps/sync_vroutertenant.py
@@ -44,6 +44,23 @@
         else:
             objs = VRouterTenant.get_deleted_tenant_objects()
 
+        # Check that each is a valid vCPE tenant or instance
+        for vroutertenant in objs:
+            # Do we have a vCPE subscriber_tenant?
+            if vroutertenant.subscriber_tenant:
+                sub = vroutertenant.subscriber_tenant
+                if sub.kind != 'vCPE' or not sub.get_attribute("instance_id"):
+                    objs.remove(vroutertenant)
+            else:
+                # Maybe the VRouterTenant is for an instance
+                instance_id = vroutertenant.get_attribute("tenant_for_instance_id")
+                if not instance_id:
+                    objs.remove(vroutertenant)
+                else:
+                    instance = Instance.objects.filter(id=instance_id)[0]
+                    if not instance.instance_name:
+                        objs.remove(vroutertenant)
+
         return objs
 
     def map_sync_inputs(self, vroutertenant):
@@ -57,21 +74,15 @@
         # * Look up the instance corresponding to the address
         # * Look up the node running the instance
         # * Get the "location" tag, push to the fabric
-        #
-        # Do we have a vCPE subscriber_tenant?
-        if (vroutertenant.subscriber_tenant):
+        if vroutertenant.subscriber_tenant:
             sub = vroutertenant.subscriber_tenant
-            if (sub.kind == 'vCPE'):
-                instance_id = sub.get_attribute("instance_id")
-                if instance_id:
-                    instance = Instance.objects.filter(id=instance_id)[0]
-                    name = str(sub)
+            instance_id = sub.get_attribute("instance_id")
+            instance = Instance.objects.filter(id=instance_id)[0]
+            name = str(sub)
         else:
-            # Maybe the VRouterTenant is for an instance
             instance_id = vroutertenant.get_attribute("tenant_for_instance_id")
-            if instance_id: 
-                instance = Instance.objects.filter(id=instance_id)[0]
-                name = str(instance)
+            instance = Instance.objects.filter(id=instance_id)[0]
+            name = str(instance)
 
         node = instance.node
         location = self.get_node_tag(node, "location")
@@ -88,7 +99,7 @@
             }
         }
 
-        rest_json = json.dumps(data, indent=4)
+        rest_json = json.dumps(data)
 
         fields = {
             'rest_hostname': fos.rest_hostname,