[CORD-3100] Moving vtn-service to use the new onos-service APIs
Change-Id: Id6f05a18499a7d4dfcf53390f01c1d4f13bc61c0
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..485dee6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.idea
diff --git a/Dockerfile.synchronizer b/Dockerfile.synchronizer
index b4fe6d7..be1eb0c 100644
--- a/Dockerfile.synchronizer
+++ b/Dockerfile.synchronizer
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# docker build -t xosproject/vtn-synchronizer:candidate -f Dockerfile.synchronizer .
+
# xosproject/vtn-synchronizer
FROM xosproject/xos-synchronizer-base:candidate
diff --git a/xos/synchronizer/steps/sync_onos_netcfg.py b/xos/synchronizer/steps/sync_onos_netcfg.py
index ba254be..e56892a 100644
--- a/xos/synchronizer/steps/sync_onos_netcfg.py
+++ b/xos/synchronizer/steps/sync_onos_netcfg.py
@@ -23,9 +23,10 @@
from synchronizers.new_base.syncstep import DeferredException
from synchronizers.new_base.syncstep import SyncStep
from synchronizers.new_base.modelaccessor import *
-from xos.logger import Logger, logging
+from xosconfig import Config
+from multistructlog import create_logger
-logger = Logger(level=logging.INFO)
+log = create_logger(Config().get('logging'))
class SyncONOSNetcfg(SyncStep):
provides=[VTNService]
@@ -37,7 +38,7 @@
SyncStep.__init__(self, **args)
def handle_watched_object(self, o):
- logger.info("handle_watched_object is invoked for object %s" % (str(o)),extra=o.tologdict())
+ log.info("handle_watched_object is invoked for object %s" % (str(o)),extra=o.tologdict())
if (type(o) is Node): # For Node add/delete/modify
self.call()
if (type(o) is AddressPool): # For public gateways
@@ -54,19 +55,22 @@
return service_instances
def save_service_instance_attribute(self, service_instance, name, value):
+
+ vtn_onos_app = [si for si in service_instance.eastbound_service_instances if "ONOSApp" in si.leaf_model.class_names][0]
+
# returns True if something changed
something_changed=False
- tas = ServiceInstanceAttribute.objects.filter(service_instance_id=service_instance.id, name=name)
+ tas = ServiceInstanceAttribute.objects.filter(service_instance_id=vtn_onos_app.id, name=name)
if tas:
ta = tas[0]
if ta.value != value:
- logger.info("updating %s with attribute" % name)
+ log.info("updating %s with attribute" % name)
ta.value = value
ta.save(update_fields=["value", "updated"], always_update_timestamp=True)
something_changed = True
else:
- logger.info("saving autogenerated config %s" % name)
- ta = model_accessor.create_obj(ServiceInstanceAttribute, service_instance=service_instance, name=name, value=value)
+ log.info("saving autogenerated config %s" % name)
+ ta = model_accessor.create_obj(ServiceInstanceAttribute, service_instance=vtn_onos_app, name=name, value=value)
ta.save()
something_changed = True
return something_changed
@@ -139,7 +143,7 @@
try:
nodeip = socket.gethostbyname(node.name)
except socket.gaierror:
- logger.warn("unable to resolve hostname %s: node will not be added to config"
+ log.warn("unable to resolve hostname %s: node will not be added to config"
% node.name)
continue
@@ -148,7 +152,7 @@
dataPlaneIntf = node.dataPlaneIntf
dataPlaneIp = node.dataPlaneIp
except:
- logger.error("not adding node %s to the VTN configuration" % node.name)
+ log.error("not adding node %s to the VTN configuration" % node.name)
continue
node_dict = {
@@ -174,7 +178,7 @@
# 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)
+ log.info("Gateway_ip or gateway_mac is blank for addresspool %s. Skipping." % ap)
continue
gateway_dict = {
@@ -184,7 +188,7 @@
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")
+ log.info("No Address Pools present, not adding publicGateways to config")
return json.dumps(data, indent=4, sort_keys=True)
@@ -203,7 +207,7 @@
service_instances = self.get_service_instances_who_want_config()
for service_instance in service_instances:
- something_changed = self.save_service_instance_attribute(service_instance, "rest_onos/v1/network/configuration/", netcfg)
+ something_changed = self.save_service_instance_attribute(service_instance, "onos/v1/network/configuration/", netcfg)
if (something_changed):
# make sure we cause the ServiceInstance to be updated as well as the attribute
# TODO: revisit this after synchronizer multi-object-watching is complete