Provide command line arg access to any module
Change-Id: I48d5c13062d1be5fef6be9e258e1820274733779
diff --git a/voltha/adapters/tibit_olt/tibit_olt.py b/voltha/adapters/tibit_olt/tibit_olt.py
index 152f5ab..1cb25c8 100644
--- a/voltha/adapters/tibit_olt/tibit_olt.py
+++ b/voltha/adapters/tibit_olt/tibit_olt.py
@@ -21,6 +21,7 @@
import structlog
from zope.interface import implementer
+from voltha.registry import registry
from voltha.adapters.interface import IAdapterInterface
from voltha.protos.adapter_pb2 import Adapter, AdapterConfig
from voltha.protos.device_pb2 import DeviceType, DeviceTypes
@@ -52,10 +53,11 @@
version='0.1',
config=AdapterConfig(log_level=LogLevel.INFO)
)
+ self.interface = registry('main').get_args().interface
def start(self):
- log.debug('starting')
- log.info('started')
+ log.debug('starting', interface=self.interface)
+ log.info('started', interface=self.interface)
def stop(self):
log.debug('stopping')
diff --git a/voltha/main.py b/voltha/main.py
index ac62054..44cd416 100755
--- a/voltha/main.py
+++ b/voltha/main.py
@@ -23,6 +23,7 @@
import yaml
from twisted.internet.defer import inlineCallbacks
+from zope.interface import implementer
from common.structlog_setup import setup_logging
from common.utils.dockerhelpers import get_my_containers_name
@@ -35,7 +36,7 @@
from voltha.northbound.kafka.kafka_proxy import KafkaProxy, get_kafka_proxy
from voltha.northbound.rest.health_check import init_rest_service
from voltha.protos.common_pb2 import LogLevel
-from voltha.registry import registry
+from voltha.registry import registry, IComponent
VERSION = '0.9.0'
@@ -204,7 +205,9 @@
log.info('(to stop: press Ctrl-C)')
+@implementer(IComponent)
class Main(object):
+
def __init__(self):
self.args = args = parse_args()
@@ -231,11 +234,24 @@
def start(self):
self.start_reactor() # will not return except Keyboard interrupt
+ def stop(self):
+ pass
+
+ def get_args(self):
+ """Allow access to command line args"""
+ return self.args
+
+ def get_config(self):
+ """Allow access to content of config file"""
+ return self.config
+
@inlineCallbacks
def startup_components(self):
try:
self.log.info('starting-internal-components')
+ registry.register('main', self)
+
yield registry.register(
'coordinator',
Coordinator(