Moved Docker stuff to "Docker" folder
Created k8s folder for k8s stuff Added early-stage service.yaml for K8s deployment
This commit is contained in:
22
Docker/src/python/tHome/broker/__init__.py
Normal file
22
Docker/src/python/tHome/broker/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#===========================================================================
|
||||
#
|
||||
# RainForest Eagle Electric meter reading package
|
||||
#
|
||||
#===========================================================================
|
||||
|
||||
__doc__ = """RainForest Eagle electric meter reader.
|
||||
|
||||
This package implements a web server which the RainForest Eagle can use as a cloud service. The Eagle will post data to the this module which parses the XML messages and sends them out as ZeroMQ messages (usually to a tHome.msgHub).
|
||||
|
||||
Logging object name: tHome.eagle
|
||||
"""
|
||||
|
||||
#===========================================================================
|
||||
|
||||
|
||||
#===========================================================================
|
||||
|
||||
from . import config
|
||||
from .connect import connect
|
||||
|
||||
#===========================================================================
|
||||
41
Docker/src/python/tHome/broker/config.py
Normal file
41
Docker/src/python/tHome/broker/config.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#===========================================================================
|
||||
#
|
||||
# Config file
|
||||
#
|
||||
#===========================================================================
|
||||
|
||||
__doc__ = """Config file parsing.
|
||||
"""
|
||||
|
||||
from .. import util
|
||||
from ..util import config as C
|
||||
|
||||
#===========================================================================
|
||||
|
||||
# Config file section name and defaults.
|
||||
configEntries = {
|
||||
# ( name, converter function, default value )
|
||||
C.Entry( "host", str ),
|
||||
C.Entry( "port", int, 1883 ),
|
||||
C.Entry( "keepAlive", int, 60 ),
|
||||
C.Entry( "user", str ),
|
||||
C.Entry( "password", str ),
|
||||
C.Entry( "ca_certs", list ),
|
||||
C.Entry( "certFile", util.path.expand ),
|
||||
C.Entry( "keyFile", util.path.expand ),
|
||||
}
|
||||
|
||||
#===========================================================================
|
||||
def parse( configDir, configFile='broker.py' ):
|
||||
cfg = C.readAndCheck( configDir, configFile, configEntries )
|
||||
|
||||
if cfg.ca_certs:
|
||||
for i in range( len( cfg.ca_certs ) ):
|
||||
cfg.ca_certs[i] = util.path.expand( cfg.ca_certs[i] )
|
||||
|
||||
return cfg
|
||||
|
||||
#===========================================================================
|
||||
|
||||
|
||||
|
||||
44
Docker/src/python/tHome/broker/connect.py
Normal file
44
Docker/src/python/tHome/broker/connect.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#===========================================================================
|
||||
#
|
||||
# Broker connection
|
||||
#
|
||||
#===========================================================================
|
||||
from . import config
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
#===========================================================================
|
||||
class Client( mqtt.Client ):
|
||||
"""Logging client
|
||||
"""
|
||||
def __init__( self, log=None ):
|
||||
mqtt.Client.__init__( self )
|
||||
self._logger = log
|
||||
# Restore callbacks overwritten by stupid mqtt library
|
||||
self.on_log = Client.on_log
|
||||
|
||||
def on_log( self, userData, level, buf ):
|
||||
if self._logger:
|
||||
self._logger.log( level, buf )
|
||||
|
||||
#===========================================================================
|
||||
def connect( configDir, log, client=None ):
|
||||
cfg = config.parse( configDir )
|
||||
|
||||
if client is None:
|
||||
client = Client( log )
|
||||
|
||||
if cfg.user:
|
||||
client.username_pw_set( cfg.user, cfg.password )
|
||||
|
||||
if cfg.ca_certs:
|
||||
client.tls_set( cfg.ca_certs, cfg.certFile, cfg.keyFile )
|
||||
|
||||
log.info( "Connecting to broker at %s:%d" % ( cfg.host, cfg.port ) )
|
||||
client.connect( cfg.host, cfg.port, cfg.keepAlive )
|
||||
|
||||
return client
|
||||
|
||||
#===========================================================================
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user