CORD-1520 Update to new Service/Tenancy models
Change-Id: I54a60c9af962aa6fa9216b2d844b03e529a8b984
diff --git a/xos/synchronizer/model_policies/model_policy_vsgtenant.py b/xos/synchronizer/model_policies/model_policy_vsgtenant.py
index cf7be71..8674446 100644
--- a/xos/synchronizer/model_policies/model_policy_vsgtenant.py
+++ b/xos/synchronizer/model_policies/model_policy_vsgtenant.py
@@ -28,13 +28,17 @@
def cleanup_orphans(self, tenant):
# ensure vSG only has one vRouter
cur_vrouter = tenant.vrouter
- for vrouter in list(VRouterTenant.objects.filter(subscriber_tenant_id=tenant.id)): # TODO: Hardcoded dependency
- if (not cur_vrouter) or (vrouter.id != cur_vrouter.id):
- # print "XXX clean up orphaned vrouter", vrouter
- vrouter.delete()
+ for link in tenant.subscribed_links.all():
+ # TODO: hardcoded dependency
+ # cast from ServiceInstance to VRouterTenant
+ vrouters = VRouterTenant.objects.filter(id = link.provider_service_instance.id)
+ for vrouter in vrouters:
+ if (not cur_vrouter) or (vrouter.id != cur_vrouter.id):
+ # print "XXX clean up orphaned vrouter", vrouter
+ vrouter.delete()
def get_vsg_service(self, tenant):
- return VSGService.objects.get(id=tenant.provider_service.id)
+ return VSGService.objects.get(id=tenant.owner.id)
def find_instance_for_s_tag(self, s_tag):
tags = Tag.objects.filter(name="s_tag", value=s_tag)
@@ -57,7 +61,7 @@
if not flavors:
raise SynchronizerConfigurationError("No m1.small flavor")
- slice = tenant.provider_service.slices.first()
+ slice = tenant.owner.slices.first()
(node, parent) = LeastLoadedNodeScheduler(slice, label=self.get_vsg_service(tenant).node_label).pick()
@@ -107,7 +111,7 @@
return port
def get_lan_network(self, tenant, instance):
- slice = tenant.provider_service.slices.all()[0]
+ slice = tenant.owner.slices.all()[0]
# there should only be one network private network, and its template should not be the management template
lan_networks = [x for x in slice.networks.all() if
x.template.visibility == "private" and (not "management" in x.template.name)]
@@ -150,7 +154,7 @@
if tenant.volt and tenant.volt.s_tag:
tags = Tag.objects.filter(name="s_tag", value=tenant.volt.s_tag)
if not tags:
- tag = Tag(service=tenant.provider_service, content_type=instance.self_content_type_id, object_id=instance.id, name="s_tag", value=str(tenant.volt.s_tag))
+ tag = Tag(service=tenant.owner, content_type=instance.self_content_type_id, object_id=instance.id, name="s_tag", value=str(tenant.volt.s_tag))
tag.save()
# VTN-CORD needs a WAN address for the VM, so that the VM can
@@ -158,11 +162,11 @@
tags = Tag.objects.filter(content_type=instance.self_content_type_id, object_id=instance.id, name="vm_vrouter_tenant")
if not tags:
vrouter = self.allocate_public_service_instance(address_pool_name="addresses_vsg",
- subscriber_service=tenant.provider_service)
+ subscriber_service=tenant.owner)
vrouter.set_attribute("tenant_for_instance_id", instance.id)
vrouter.save()
# TODO: potential partial failure
- tag = Tag(service=tenant.provider_service, content_type=instance.self_content_type_id, object_id=instance.id, name="vm_vrouter_tenant", value="%d" % vrouter.id)
+ tag = Tag(service=tenant.owner, content_type=instance.self_content_type_id, object_id=instance.id, name="vm_vrouter_tenant", value="%d" % vrouter.id)
tag.save()
instance.no_sync = False # allow the synchronizer to run now