Replaced references to adapter_agent

Change-Id: Ic1cf6326f8799e8ce5f4c9293efb3b1701ffe7ce
diff --git a/pyvoltha/adapters/extensions/alarms/adapter_alarms.py b/pyvoltha/adapters/extensions/alarms/adapter_alarms.py
index 0e8f94a..0ee5dab 100644
--- a/pyvoltha/adapters/extensions/alarms/adapter_alarms.py
+++ b/pyvoltha/adapters/extensions/alarms/adapter_alarms.py
@@ -15,6 +15,7 @@
 
 import structlog
 import arrow
+from twisted.internet.defer import inlineCallbacks, returnValue
 from voltha_protos.events_pb2 import AlarmEventType, AlarmEventSeverity,\
     AlarmEventState, AlarmEventCategory
 log = structlog.get_logger()
@@ -37,21 +38,21 @@
     """
     Class for managing Alarms within a given Device Handler instance
     """
-    def __init__(self, adapter_agent, device_id, logical_device_id, serial_number):
+    def __init__(self, core_proxy, device_id, logical_device_id, serial_number):
         """
         Adapter alarm manager initializer
 
-        :param adapter_agent: (AdapterAgent) Adapter agent reference
+        :param core_proxy: (CoreProxy) Core proxy reference
         :param device_id: (str) Device handler's unique device id
         :param logical_device_id: (str) Logical Device that the device is a member of
         :param serial_number: (str) Serial number of the device(OLT) that created this instance
         """
         self.log = structlog.get_logger(device_id=device_id)
-        self.adapter_agent = adapter_agent
+        self.core_proxy = core_proxy
         self.device_id = device_id
         self.logical_device_id = logical_device_id
         self.serial_number = serial_number
-        self.adapter_name = adapter_agent.listening_topic
+        self.adapter_name = core_proxy.listening_topic
         self.lc = None
 
     def format_id(self, alarm):
@@ -80,7 +81,7 @@
         return '{} Alarm - {} - {}'.format(_object.upper(),
                                            alarm.upper(),
                                            'Raised' if status else 'Cleared')
-
+    @inlineCallbacks
     def send_alarm(self, context_data, alarm_data):
         """
         Send the alarm to the event bus
@@ -98,7 +99,7 @@
 
             self.log.debug('send_alarm', alarm_data=alarm_data)
             
-            alarm_event = self.adapter_agent.create_alarm(
+            alarm_event = self.core_proxy.create_alarm(
                 id=alarm_data.get('id', 'voltha.{}.{}.olt'.format(self.adapter_name,
                                                                   self.device_id)),
                 resource_id=str(alarm_data.get('resource_id', self.device_id)),
@@ -113,7 +114,7 @@
                 logical_device_id=self.logical_device_id,
                 alarm_type_name=alarm_data.get('alarm_type_name')
             )
-            self.adapter_agent.submit_alarm(self.device_id, alarm_event)
+            yield self.core_proxy.submit_alarm(self.device_id, alarm_event)
 
         except Exception as e:
             self.log.exception('failed-to-send-alarm', e=e)
diff --git a/pyvoltha/adapters/extensions/kpi/README.md b/pyvoltha/adapters/extensions/kpi/README.md
index a55c7d2..43d72bb 100644
--- a/pyvoltha/adapters/extensions/kpi/README.md
+++ b/pyvoltha/adapters/extensions/kpi/README.md
@@ -29,7 +29,7 @@
 2. Create the ProtoBuf message for your metrics by calling the newly created _manager's_
    **_make_proto_**() method. 
    
-3. Register the ProtoBuf message configuration with the adapter agent via the 
+3. Register the ProtoBuf message configuration with the core_proxy via the 
    _update_device_pm_config_() method with the optional init parameter set to **True**.
    
 4. Request the manager to schedule the first PM collection interval by calling the
@@ -51,7 +51,7 @@
         'nni-ports': self.northbound_ports.values(),
         'pon-ports': self.southbound_ports.values()
     }
-    self.pm_metrics = OltPmMetrics(self.adapter_agent, self.device_id, self.logical_device_id,
+    self.pm_metrics = OltPmMetrics(self.core_proxy, self.device_id, self.logical_device_id,
                                    grouped=True, freq_override=False,
                                    **kwargs)
 
@@ -59,8 +59,8 @@
     pm_config = self.pm_metrics.make_proto()
     self.log.debug("initial-pm-config", pm_config=pm_config)
     
-    # Create the PM information in the adapter agent
-    self.adapter_agent.update_device_pm_config(pm_config, init=True)
+    # Create the PM information in the core_proxy
+    self.core_proxy.update_device_pm_config(pm_config, init=True)
         
     # Start collecting stats from the device after a brief pause
     reactor.callLater(10, self.pm_metrics.start_collector)
@@ -80,7 +80,7 @@
         'heartbeat': self.heartbeat,
         'omci-cc': self.openomci.omci_cc
     }
-    self.pm_metrics = OnuPmMetrics(self.adapter_agent, self.device_id, self.logical_device_id,
+    self.pm_metrics = OnuPmMetrics(self.core_proxy, self.device_id, self.logical_device_id,
                                    grouped=True, freq_override=False,
                                    **kwargs)
                                    
@@ -90,8 +90,8 @@
     # Register the OMCI history intervals with OpenOMCI
     self.openomci.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm)
     
-    # Create the PM information in the adapter agent
-    self.adapter_agent.update_device_pm_config(pm_config, init=True)
+    # Create the PM information in the core_proxy
+    self.core_proxy.update_device_pm_config(pm_config, init=True)
     
     # Start collecting stats from the device after a brief pause
     reactor.callLater(30, self.pm_metrics.start_collector)
diff --git a/pyvoltha/adapters/extensions/kpi/onu/onu_omci_pm.py b/pyvoltha/adapters/extensions/kpi/onu/onu_omci_pm.py
index 98c1129..5ef706c 100644
--- a/pyvoltha/adapters/extensions/kpi/onu/onu_omci_pm.py
+++ b/pyvoltha/adapters/extensions/kpi/onu/onu_omci_pm.py
@@ -41,12 +41,12 @@
     DEFAULT_UNI_STATUS_ENABLED = True
     DEFAULT_UNI_STATUS_FREQUENCY = (15 * 60 * 10)
 
-    def __init__(self, adapter_agent, device_id, logical_device_id,
+    def __init__(self, core_proxy, device_id, logical_device_id,
                  grouped=False, freq_override=False, **kwargs):
         """
         Initializer for shared ONU Device Adapter OMCI CC PM metrics
 
-        :param adapter_agent: (AdapterAgent) Adapter agent for the device
+        :param core_proxy: (CoreProxy) Core proxy for the device
         :param device_id: (str) Device ID
         :param logical_device_id: (str) VOLTHA Logical Device ID
         :param grouped: (bool) Flag indicating if statistics are managed as a group
@@ -60,7 +60,7 @@
                                          retrieval of OpenOMCI Communications channel statistics
                                          and retrieval of polled statistics.
         """
-        super(OnuOmciPmMetrics, self).__init__(adapter_agent, device_id, logical_device_id,
+        super(OnuOmciPmMetrics, self).__init__(core_proxy, device_id, logical_device_id,
                                                grouped=grouped, freq_override=freq_override,
                                                **kwargs)
 
@@ -108,7 +108,7 @@
         self.omci_uni_metrics_config = {m: PmConfig(name=m, type=t, enabled=True)
                                         for (m, t) in self.omci_uni_pm_names}
 
-        self.openomci_interval_pm = OnuPmIntervalMetrics(adapter_agent, device_id, logical_device_id)
+        self.openomci_interval_pm = OnuPmIntervalMetrics(core_proxy, device_id, logical_device_id)
 
     def update(self, pm_config):
         # TODO: Test frequency override capability for a particular group
diff --git a/pyvoltha/adapters/extensions/kpi/onu/onu_pm_interval_metrics.py b/pyvoltha/adapters/extensions/kpi/onu/onu_pm_interval_metrics.py
index 8b7bf79..5353f1b 100644
--- a/pyvoltha/adapters/extensions/kpi/onu/onu_pm_interval_metrics.py
+++ b/pyvoltha/adapters/extensions/kpi/onu/onu_pm_interval_metrics.py
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import arrow
+from twisted.internet.defer import inlineCallbacks, returnValue 
 from voltha_protos.device_pb2 import PmConfig, PmGroupConfig
 from voltha_protos.events_pb2 import KpiEvent2, MetricInformation, MetricMetaData, KpiEventType
 from pyvoltha.adapters.extensions.kpi.adapter_pm_metrics import AdapterPmMetrics
@@ -55,8 +56,8 @@
     XGPON_DOWNSTREAM_HISTORY = False
     XGPON_UPSTREAM_HISTORY = False
 
-    def __init__(self, adapter_agent, device_id, logical_device_id, **kwargs):
-        super(OnuPmIntervalMetrics, self).__init__(adapter_agent, device_id, logical_device_id,
+    def __init__(self, core_proxy, device_id, logical_device_id, **kwargs):
+        super(OnuPmIntervalMetrics, self).__init__(core_proxy, device_id, logical_device_id,
                                                    grouped=True, freq_override=False,
                                                    **kwargs)
         ethernet_bridge_history = {
@@ -324,6 +325,7 @@
 
         return pm_config
 
+    @inlineCallbacks
     def publish_metrics(self, interval_data):
         """
         Collect the metrics for this ONU PM Interval
@@ -377,7 +379,7 @@
                     kpi_event = KpiEvent2(type=KpiEventType.slice,
                                           ts=now.float_timestamp,
                                           slice_data=slice_data)
-                    self.adapter_agent.submit_kpis(kpi_event)
+                    yield self.core_proxy.submit_kpis(kpi_event)
 
         except Exception as e:
             self.log.exception('failed-to-submit-kpis', e=e)
diff --git a/pyvoltha/adapters/extensions/kpi/onu/onu_pm_metrics.py b/pyvoltha/adapters/extensions/kpi/onu/onu_pm_metrics.py
index 9402ae9..eaf0232 100644
--- a/pyvoltha/adapters/extensions/kpi/onu/onu_pm_metrics.py
+++ b/pyvoltha/adapters/extensions/kpi/onu/onu_pm_metrics.py
@@ -35,12 +35,12 @@
     # the KPI shared library supports individual collection.
     DEFAULT_ONU_COLLECTION_FREQUENCY = 60 * 10      # 1 minute
 
-    def __init__(self, adapter_agent, device_id, logical_device_id,
+    def __init__(self, core_proxy, device_id, logical_device_id,
                  grouped=False, freq_override=False, **kwargs):
         """
         Initializer for shared ONU Device Adapter PM metrics
 
-        :param adapter_agent: (AdapterAgent) Adapter agent for the device
+        :param core_proxy: (CoreProxy) Core proxy for the device
         :param device_id: (str) Device ID
         :param logical_device_id: (str) VOLTHA Logical Device ID
         :param grouped: (bool) Flag indicating if statistics are managed as a group
@@ -53,7 +53,7 @@
                               'heartbeat': Reference to the a class that provides an ONU heartbeat
                                            statistics.   TODO: This should be standardized across adapters
         """
-        super(OnuPmMetrics, self).__init__(adapter_agent, device_id, logical_device_id,
+        super(OnuPmMetrics, self).__init__(core_proxy, device_id, logical_device_id,
                                            grouped=grouped, freq_override=freq_override,
                                            **kwargs)
 
@@ -77,7 +77,7 @@
         self.health_metrics_config = {m: PmConfig(name=m, type=t, enabled=True)
                                       for (m, t) in self.health_pm_names}
 
-        self.omci_pm = OnuOmciPmMetrics(adapter_agent, device_id, logical_device_id,
+        self.omci_pm = OnuOmciPmMetrics(core_proxy, device_id, logical_device_id,
                                         grouped=grouped, freq_override=freq_override,
                                         **kwargs)
 
diff --git a/pyvoltha/adapters/extensions/omci/state_machines/image_agent.py b/pyvoltha/adapters/extensions/omci/state_machines/image_agent.py
index 85a11e3..08e2a04 100755
--- a/pyvoltha/adapters/extensions/omci/state_machines/image_agent.py
+++ b/pyvoltha/adapters/extensions/omci/state_machines/image_agent.py
@@ -872,7 +872,7 @@
         # onu_dev = self._omci_agent.get_device(self._device_id)
         # assert device
         
-        # self._local_dir = DEFAULT_LOCAL_ROOT + onu_dev.adapter_agent.name
+        # self._local_dir = DEFAULT_LOCAL_ROOT + onu_dev.core_proxy.name
         # self.log.debug("ImageAgent", local_dir=self._local_dir)
         
         
@@ -907,9 +907,9 @@
         #     onu_dev = self._omci_agent.get_device(self._device_id)
         #     assert onu_dev
         #     if image_download.local_dir is None:
-        #         self._local_dir = ImageAgent.DEFAULT_LOCAL_ROOT + onu_dev.adapter_agent.name
+        #         self._local_dir = ImageAgent.DEFAULT_LOCAL_ROOT + onu_dev.core_proxy.name
         #     else:
-        #         self._local_dir = image_download.local_dir + '/' + onu_dev.adapter_agent.name
+        #         self._local_dir = image_download.local_dir + '/' + onu_dev.core_proxy.name
             
             # self.log.debug("ImageAgent", local_dir=self._local_dir)
         #     image_download.local_dir = self._local_dir