SEBA-405 Update progran service to use synchronizer library

Change-Id: Ia538fec19a1efeee12ec81e5733bdc30990b478a
diff --git a/Dockerfile.synchronizer b/Dockerfile.synchronizer
index b0322d5..c41dd79 100644
--- a/Dockerfile.synchronizer
+++ b/Dockerfile.synchronizer
@@ -14,7 +14,7 @@
 
 # xosproject/progran-synchronizer
 
-FROM xosproject/xos-synchronizer-base:2.1.32
+FROM xosproject/xos-synchronizer-base:2.1.38
 
 COPY xos/synchronizer /opt/xos/synchronizers/progran
 COPY VERSION /opt/xos/synchronizers/progran/
diff --git a/VERSION b/VERSION
index e010258..157e54f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0.5
+2.0.6
diff --git a/xos/synchronizer/progran-synchronizer.py b/xos/synchronizer/progran-synchronizer.py
index 37fbd6b..b8bd3d7 100644
--- a/xos/synchronizer/progran-synchronizer.py
+++ b/xos/synchronizer/progran-synchronizer.py
@@ -18,9 +18,8 @@
 
 # Runs the standard XOS synchronizer
 
-import importlib
 import os
-import sys
+from xossynchronizer import Synchronizer
 from xosconfig import Config
 
 base_config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/config.yaml')
@@ -31,8 +30,4 @@
 else:
     Config.init(base_config_file, 'synchronizer-config-schema.yaml')
 
-synchronizer_path = os.path.join(os.path.dirname(
-    os.path.realpath(__file__)), "../../synchronizers/new_base")
-sys.path.append(synchronizer_path)
-mod = importlib.import_module("xos-synchronizer")
-mod.main()
+Synchronizer().run()
diff --git a/xos/synchronizer/steps/helpers.py b/xos/synchronizer/steps/helpers.py
index 333566a..077d559 100644
--- a/xos/synchronizer/steps/helpers.py
+++ b/xos/synchronizer/steps/helpers.py
@@ -14,7 +14,6 @@
 
 from xosconfig import Config
 from multistructlog import create_logger
-from synchronizers.new_base.modelaccessor import ProgranService
 import time
 import datetime
 
@@ -28,9 +27,9 @@
         return ProgranHelpers.get_onos_info_from_service(progran_service)
 
     @staticmethod
-    def get_progran_onos_info():
+    def get_progran_onos_info(model_accessor):
         try:
-            progran_service = ProgranService.objects.all()[0]
+            progran_service = model_accessor.ProgranService.objects.all()[0]
         except IndexError:
             raise Exception("Cannot find Progran Service, does it exists?")
         return ProgranHelpers.get_onos_info_from_service(progran_service)
diff --git a/xos/synchronizer/steps/sync_enodeb.py b/xos/synchronizer/steps/sync_enodeb.py
index b0e4172..589142e 100644
--- a/xos/synchronizer/steps/sync_enodeb.py
+++ b/xos/synchronizer/steps/sync_enodeb.py
@@ -16,8 +16,8 @@
 
 import os
 import sys
-from synchronizers.new_base.SyncInstanceUsingAnsible import SyncStep
-from synchronizers.new_base.modelaccessor import ENodeB
+from xossynchronizer.steps.SyncInstanceUsingAnsible import SyncStep
+from xossynchronizer.modelaccessor import ENodeB
 
 from xosconfig import Config
 from multistructlog import create_logger
@@ -51,7 +51,7 @@
     def sync_record(self, o):
         log.info("sync'ing enodeb", object=str(o), **o.tologdict())
 
-        onos = ProgranHelpers.get_progran_onos_info()
+        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
 
         enodeb_url = "http://%s:%s/onos/progran/enodeb/" % (onos['url'], onos['port'])
         data = self.get_progran_enodeb_field(o)
@@ -76,7 +76,7 @@
 
     def delete_record(self, o):
         log.info("deleting enodeb", object=str(o), **o.tologdict())
-        onos = ProgranHelpers.get_progran_onos_info()
+        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
         enode_url = "http://%s:%s/onos/progran/enodeb/%s" % (onos['url'], onos['port'], o.enbId)
         r = requests.delete(enode_url, auth=HTTPBasicAuth(onos['username'], onos['password']))
         ProgranHelpers.get_progran_rest_errors(r)
diff --git a/xos/synchronizer/steps/sync_imsi.py b/xos/synchronizer/steps/sync_imsi.py
index 12918f1..aabec76 100644
--- a/xos/synchronizer/steps/sync_imsi.py
+++ b/xos/synchronizer/steps/sync_imsi.py
@@ -16,8 +16,8 @@
 
 import os
 import sys
-from synchronizers.new_base.SyncInstanceUsingAnsible import SyncStep
-from synchronizers.new_base.modelaccessor import MCordSubscriberInstance
+from xossynchronizer.steps.SyncInstanceUsingAnsible import SyncStep
+from xossynchronizer.modelaccessor import MCordSubscriberInstance
 
 from xosconfig import Config
 from multistructlog import create_logger
@@ -47,7 +47,7 @@
 
     def sync_record(self, o):
         log.info("sync'ing imsi", object=str(o), **o.tologdict())
-        onos = ProgranHelpers.get_progran_onos_info()
+        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
         imsi_url = "http://%s:%s/onos/progran/imsi/" % (onos['url'], onos['port'])
         data = self.get_progran_imsi_field(o)
         r = requests.post(imsi_url, data=json.dumps(data), auth=HTTPBasicAuth(onos['username'], onos['password']))
@@ -57,7 +57,7 @@
 
     def delete_record(self, o):
         log.info("deleting imsi", object=str(o), **o.tologdict())
-        onos = ProgranHelpers.get_progran_onos_info()
+        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
         profile_url = "http://%s:%s/onos/progran/imsi/%s" % (onos['url'], onos['port'], o.imsi_number)
         r = requests.delete(profile_url, auth=HTTPBasicAuth(onos['username'], onos['password']))
         log.info("IMSI synchronized", response=r.json())
\ No newline at end of file
diff --git a/xos/synchronizer/steps/sync_imsi_back.py b/xos/synchronizer/steps/sync_imsi_back.py
index b5a9a3e..7be4921 100644
--- a/xos/synchronizer/steps/sync_imsi_back.py
+++ b/xos/synchronizer/steps/sync_imsi_back.py
@@ -20,8 +20,8 @@
 import datetime
 import time
 
-from synchronizers.new_base.SyncInstanceUsingAnsible import SyncStep
-from synchronizers.new_base.modelaccessor import MCordSubscriberInstance
+from xossynchronizer.steps.SyncInstanceUsingAnsible import SyncStep
+from xossynchronizer.modelaccessor import MCordSubscriberInstance
 
 from xosconfig import Config
 from multistructlog import create_logger
@@ -54,7 +54,7 @@
             return
 
         log.debug("Reading IMSI from progran")
-        onos = ProgranHelpers.get_progran_onos_info()
+        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
         imsi_url = "http://%s:%s/onos/progran/imsi/" % (onos['url'], onos['port'])
         r = requests.get(imsi_url, auth=HTTPBasicAuth(onos['username'], onos['password']))
         res = r.json()['ImsiArray']
diff --git a/xos/synchronizer/steps/sync_imsi_link.py b/xos/synchronizer/steps/sync_imsi_link.py
index 863af21..a91d2a2 100644
--- a/xos/synchronizer/steps/sync_imsi_link.py
+++ b/xos/synchronizer/steps/sync_imsi_link.py
@@ -16,8 +16,8 @@
 
 import os
 import sys
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import MCordSubscriberInstance, ServiceInstanceLink, ProgranServiceInstance
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import MCordSubscriberInstance, ServiceInstanceLink, ProgranServiceInstance
 
 from xosconfig import Config
 from multistructlog import create_logger
@@ -57,7 +57,7 @@
         if o.provider_service_instance.leaf_model_name == "ProgranServiceInstance" and o.subscriber_service_instance.leaf_model_name ==  "MCordSubscriberInstance":
             log.info("sync'ing link", object=str(o), **o.tologdict())
 
-            onos = ProgranHelpers.get_progran_onos_info()
+            onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
 
             profile_name = o.provider_service_instance.name
             imsi_number =  o.subscriber_service_instance.leaf_model.imsi_number
@@ -78,7 +78,7 @@
         if o.provider_service_instance.leaf_model_name == "ProgranServiceInstance" and o.subscriber_service_instance.leaf_model_name ==  "MCordSubscriberInstance":
             log.info("deleting link", object=str(o), **o.tologdict())
 
-            onos = ProgranHelpers.get_progran_onos_info()
+            onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
 
             profile_name = o.provider_service_instance.name
             imsi_number =  o.subscriber_service_instance.leaf_model.imsi_number
diff --git a/xos/synchronizer/steps/sync_progranserviceinstance.py b/xos/synchronizer/steps/sync_progranserviceinstance.py
index d4e3d70..a026bf9 100644
--- a/xos/synchronizer/steps/sync_progranserviceinstance.py
+++ b/xos/synchronizer/steps/sync_progranserviceinstance.py
@@ -16,8 +16,8 @@
 
 import os
 import sys
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import ProgranServiceInstance, ENodeB, Handover
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import ProgranServiceInstance, ENodeB, Handover
 
 from xosconfig import Config
 from multistructlog import create_logger
@@ -41,7 +41,7 @@
     observes = ProgranServiceInstance
 
     def sync_record(self, o):
-        onos = ProgranHelpers.get_progran_onos_info()
+        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
 
         log.info("sync'ing profile", object=str(o), **o.tologdict())
 
diff --git a/xos/synchronizer/steps/sync_progranserviceinstance_back.py b/xos/synchronizer/steps/sync_progranserviceinstance_back.py
index acb8f6e..c50773b 100644
--- a/xos/synchronizer/steps/sync_progranserviceinstance_back.py
+++ b/xos/synchronizer/steps/sync_progranserviceinstance_back.py
@@ -20,8 +20,8 @@
 import datetime
 import time
 
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import ProgranServiceInstance, ENodeB, Handover, ServiceInstanceLink, MCordSubscriberInstance
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import ProgranServiceInstance, ENodeB, Handover, ServiceInstanceLink, MCordSubscriberInstance
 
 from xosconfig import Config
 from multistructlog import create_logger
@@ -53,7 +53,7 @@
             return
 
         log.debug("Reading profiles from progran")
-        onos = ProgranHelpers.get_progran_onos_info()
+        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
         profile_url = "http://%s:%s/onos/progran/profile/" % (onos['url'], onos['port'])
         r = requests.get(profile_url, auth=HTTPBasicAuth(onos['username'], onos['password']))
         res = r.json()['ProfileArray']