CORD-1250 Update to new Service/Tenancy models

Change-Id: I2e5fa0dd7d62a6451a6726eeaba2c3aaf1b83bc9
diff --git a/xos/synchronizer/model_policies/model_policy_volttenant.py b/xos/synchronizer/model_policies/model_policy_volttenant.py
index b474263..8d02091 100644
--- a/xos/synchronizer/model_policies/model_policy_volttenant.py
+++ b/xos/synchronizer/model_policies/model_policy_volttenant.py
@@ -39,36 +39,40 @@
 
             self.logger.info("MODEL_POLICY: volttenant %s creating vsg" % tenant)
 
-            vcpe = VSGTenant(provider_service=vsgServices[0],
-                             subscriber_tenant=tenant)
+            vcpe = VSGTenant(owner=vsgServices[0])
             vcpe.creator = tenant.creator
             vcpe.save()
+            link = ServiceInstanceLink(provider_service_instance = vcpe, subscriber_service_instance = tenant)
+            link.save()
 
     def manage_subscriber(self, tenant):
-        if (tenant.subscriber_root is None):
-            # The vOLT is not connected to a Subscriber, so either find an
-            # existing subscriber with the same SSID, or autogenerate a new
-            # subscriber.
-            #
-            # TODO: This probably goes away when we rethink the ONOS-to-XOS
-            # vOLT API.
+        # check for existing link to a root
+        links = tenant.provided_links.all()
+        for link in links:
+            roots = CordSubscriberRoot.objects.filter(id = link.subscriber_service_instance.id)
+            if roots:
+                return
 
-            subs = CordSubscriberRoot.objects.filter(service_specific_id = tenant.service_specific_id)
-            if subs:
-                self.logger.info("MODEL_POLICY: volttenant %s using existing subscriber root" % tenant)
-                sub = subs[0]
-            else:
-                self.logger.info("MODEL_POLICY: volttenant %s creating new subscriber root" % tenant)
-                sub = CordSubscriberRoot(service_specific_id = tenant.service_specific_id,
-                                         name = "autogenerated-for-vOLT-%s" % tenant.id)
-                sub.save()
-            tenant.subscriber_root = sub
-            tenant.save()
+        subs = CordSubscriberRoot.objects.filter(service_specific_id = tenant.service_specific_id)
+        if subs:
+            self.logger.info("MODEL_POLICY: volttenant %s using existing subscriber root" % tenant)
+            sub = subs[0]
+        else:
+            self.logger.info("MODEL_POLICY: volttenant %s creating new subscriber root" % tenant)
+            sub = CordSubscriberRoot(service_specific_id = tenant.service_specific_id,
+                                     name = "autogenerated-for-vOLT-%s" % tenant.id)
+            sub.save()
+
+        link = ServiceInstanceLink(provider_service_instance = tenant, subscriber_service_instance = sub)
+        link.save()
 
     def cleanup_orphans(self, tenant):
         # ensure vOLT only has one vCPE
         cur_vcpe = tenant.vcpe
-        subscribed_vcpes = VSGTenant.objects.filter(subscriber_tenant_id = tenant.id)
-        for vcpe in subscribed_vcpes:
-            if (not cur_vcpe) or (vcpe.id != cur_vcpe.id):
-                vcpe.delete()
+
+        links = tenant.subscribed_links.all()
+        for link in links:
+            vsgs = VSGTenant.objects.filter(id = link.provider_service_instance.id)
+            for vsg in vsgs:
+                if (not cur_vcpe) or (vsg.id != cur_vcpe.id):
+                    vsg.delete()