Verified Commit e4142c31 authored by Štěpán Henek's avatar Štěpán Henek 🌩

mqtt: allow to se controller_id

parent bc19657b
......@@ -50,6 +50,10 @@ def get_arg_parser():
help="path to passwd file (first record will be used to authenticate)",
default=None,
)
group.add_argument(
"--mqtt-controller-id", type=lambda x: re.match(r"[0-9a-zA-Z]{16}", x).group().upper(),
help="sets which controller on the messages bus should be configured (8 bytes in hex)",
)
group.add_argument(
"--bus-socket", default="/var/run/ubus.sock", help="message bus socket path"
)
......@@ -89,7 +93,7 @@ def main():
current_state.set_backend(
Backend(
args.message_bus, host=args.mqtt_host, port=args.mqtt_port,
credentials=args.mqtt_passwd_file
credentials=args.mqtt_passwd_file, controller_id=args.mqtt_controller_id,
)
)
......
# Foris
# Copyright (C) 2017 CZ.NIC, z.s.p.o. <http://www.nic.cz>
# Copyright (C) 2019 CZ.NIC, z.s.p.o. <http://www.nic.cz>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -51,6 +51,7 @@ class Backend(object):
self.host = kwargs["host"]
self.port = kwargs["port"]
self.credentials = kwargs["credentials"]
self.controller_id = kwargs["controller_id"]
self._instance = MqttSender(
kwargs["host"], kwargs["port"], default_timeout=self.DEFAULT_TIMEOUT,
credentials=kwargs["credentials"],
......@@ -63,7 +64,9 @@ class Backend(object):
return "%s('%s:%d')" % (type(self._instance).__name__, self.host, self.port)
return "%s" % type(self._instance).__name__
def perform(self, module, action, data=None, raise_exception_on_failure=True):
def perform(
self, module, action, data=None, raise_exception_on_failure=True, controller_id=None
):
""" Perform backend action
:returns: None on error, response data otherwise
......@@ -73,7 +76,9 @@ class Backend(object):
response = None
start_time = time.time()
try:
response = self._instance.send(module, action, data)
response = self._instance.send(
module, action, data, controller_id=controller_id or self.controller_id
)
except ControllerError as e:
logger.error("Exception in backend occured.")
if raise_exception_on_failure:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment