CORD-1252 eliminate hardcoded dependencies in VTN
Change-Id: I2765829dd7e7939e98d8d01ad2f3372e18561e7f
diff --git a/xos/synchronizer/steps/sync_onos_netcfg.py b/xos/synchronizer/steps/sync_onos_netcfg.py
index b084a66..67dc878 100644
--- a/xos/synchronizer/steps/sync_onos_netcfg.py
+++ b/xos/synchronizer/steps/sync_onos_netcfg.py
@@ -48,18 +48,18 @@
name=tagname)
return tags[0].value
- def get_tenants_who_want_config(self):
- tenants = []
+ def get_service_instances_who_want_config(self):
+ service_instances = []
# attribute is comma-separated list
for ta in ServiceInstanceAttribute.objects.filter(name="autogenerate"):
if ta.value:
for config in ta.value.split(','):
if config == "vtn-network-cfg":
- tenants.append(ta.service_instance)
- return tenants
+ service_instances.append(ta.service_instance)
+ return service_instances
- def save_tenant_attribute(self, tenant, name, value):
- tas = ServiceInstanceAttribute.objects.filter(service_instance_id=tenant.id, name=name)
+ def save_service_instance_attribute(self, service_instance, name, value):
+ tas = ServiceInstanceAttribute.objects.filter(service_instance_id=service_instance.id, name=name)
if tas:
ta = tas[0]
if ta.value != value:
@@ -68,7 +68,7 @@
ta.save()
else:
logger.info("saving autogenerated config %s" % name)
- ta = model_accessor.create_obj(ServiceInstanceAttribute, service_instance=tenant, name=name, value=value)
+ ta = model_accessor.create_obj(ServiceInstanceAttribute, service_instance=service_instance, name=name, value=value)
ta.save()
# This function currently assumes a single Deployment and Site
@@ -167,23 +167,26 @@
data["apps"]["org.opencord.vtn"]["cordvtn"]["nodes"].append(node_dict)
# Generate apps->org.onosproject.cordvtn->cordvtn->publicGateways
- # Pull the gateway information from vRouter
- if model_accessor.has_model_class("VRouterService"):
- vrouters = VRouterService.objects.all()
- if vrouters:
- for gateway in vrouters[0].get_gateways():
- gatewayIp = gateway['gateway_ip'].split('/',1)[0]
- gatewayMac = gateway['gateway_mac']
- gateway_dict = {
- "gatewayIp": gatewayIp,
- "gatewayMac": gatewayMac
- }
- data["apps"]["org.opencord.vtn"]["cordvtn"]["publicGateways"].append(gateway_dict)
- else:
- logger.info("No VRouter service present, not adding publicGateways to config")
+ # Pull the gateway information from Address Pool objects
+ for ap in AddressPool.objects.all():
+ if (not ap.gateway_ip) or (not ap.gateway_mac):
+ logger.info("Gateway_ip or gateway_mac is blank for addresspool %s. Skipping." % ap)
+ continue
+
+ gateway_dict = {
+ "gatewayIp": ap.gateway_ip,
+ "gatewayMac": ap.gateway_mac
+ }
+ data["apps"]["org.opencord.vtn"]["cordvtn"]["publicGateways"].append(gateway_dict)
+
+ if not AddressPool.objects.all().exists():
+ logger.info("No Address Pools present, not adding publicGateways to config")
return json.dumps(data, indent=4, sort_keys=True)
+ # TODO: Does this step execute every 5 seconds regardless of whether objects have changed?
+ # If so, what purpose does using watchers serve?
+
def call(self, **args):
vtn_service = VTNService.objects.all()
if not vtn_service:
@@ -194,6 +197,6 @@
# Check for autogenerate attribute
netcfg = self.get_onos_netcfg(vtn_service)
- tenants = self.get_tenants_who_want_config()
- for tenant in tenants:
- self.save_tenant_attribute(tenant, "rest_onos/v1/network/configuration/", netcfg)
+ service_instances = self.get_service_instances_who_want_config()
+ for service_instance in service_instances:
+ self.save_service_instance_attribute(service_instance, "rest_onos/v1/network/configuration/", netcfg)