Commit f2666507 authored by Furkan Mustafa's avatar Furkan Mustafa

Merge branch '288-clean-up-config-values' into 'dev-0.0.9'

clean up config values and environment variables

See merge request !29
parents 87391a58 d4053b4d
LOG_LEVEL=DEBUG
LOG_FILE=$(pwd)/beirand.log
RUN_DIR_PATH=/var/run
BEIRAN_SOCK=${RUN_DIR_PATH}/beirand.sock
BEIRAN_DB_PATH=$(pwd)/beiran.db
CONFIG_DIR_PATH=$(pwd)
\ No newline at end of file
BEIRAN_LOG_LEVEL=DEBUG
BEIRAN_LOG_FILE=$(pwd)/beirand.log
BEIRAN_RUN_DIR=/var/run
BEIRAN_SOCKET_FILE=${BEIRAN_RUN_DIR}/beirand.sock
BEIRAN_DB_FILE=$(pwd)/beiran.db
BEIRAN_CONFIG_DIR=$(pwd)
\ No newline at end of file
......@@ -70,11 +70,11 @@ $ ./dev.sh
#### - Settings (Environment Variables)
```sh
export LOG_LEVEL=DEBUG
export LOG_FILE=$(pwd)/beirand.log
export BEIRAN_SOCK=$(pwd)/beirand.sock
export BEIRAN_DB_PATH=$(pwd)/beiran.db
export CONFIG_DIR_PATH=$(pwd)
export BEIRAN_LOG_LEVEL=DEBUG
export BEIRAN_LOG_FILE=$(pwd)/beirand.log
export BEIRAN_SOCKET_FILE=$(pwd)/beirand.sock
export BEIRAN_DB_FILE=$(pwd)/beiran.db
export BEIRAN_CONFIG_DIR=$(pwd)
```
#### - Start Daemon
......@@ -108,10 +108,10 @@ docker-compose build
All has default values.
```
LISTEN_INTERFACE
LISTEN_ADDR
HOSTNAME
BEIRAN_SOCK
BEIRAN_LISTEN_INTERFACE
BEIRAN_LISTEN_ADDRESS
BEIRAN_HOSTNAME
BEIRAN_SOCKET_FILE
```
## Using (PoC)
......
......@@ -21,7 +21,6 @@
#!/bin/env python
"""command line client for managing beiran daemon"""
import os
import sys
import logging
import importlib
......@@ -47,12 +46,8 @@ class BeiranContext:
"""Context object for Beiran Commands which keeps clients and other common objects"""
def __init__(self) -> None:
if 'BEIRAN_SOCK' in os.environ:
daemon_url = "http+unix://" + os.environ['BEIRAN_SOCK']
elif 'BEIRAN_URL' in os.environ:
daemon_url = os.environ['BEIRAN_URL']
else:
daemon_url = "http+unix://{}/beirand.sock".format(config.run_dir)
daemon_url = config.url if config.url else \
"http+unix://" + config.socket_file
peer_address = PeerAddress(address=daemon_url)
self.beiran_url = peer_address.location
......
......@@ -34,15 +34,19 @@ LOGGER = logging.getLogger()
DEFAULTS = {
'LISTEN_PORT': 8888,
'LISTEN_ADDRESS': '0.0.0.0',
'LOG_FILE': '/var/log/beirand.log',
'LOG_LEVEL': 'DEBUG',
'CONFIG_DIR': '/etc/beiran',
'DATA_DIR': '/var/lib/beiran',
'CACHE_DIR': '/var/cache/beiran',
'RUN_DIR': '/var/run',
'DISCOVERY_METHOD': 'zeroconf',
'KNOWN_NODES': [],
}
DEFAULT_FILE_PATHS = {
'LOG_FILE': '/var/log/beirand.log',
'DB_FILE': os.path.join(DEFAULTS['DATA_DIR'], 'beirand.log'), # type: ignore
'SOCKET_FILE': os.path.join(DEFAULTS['RUN_DIR'], 'beirand.sock'), # type: ignore
}
class ConfigMeta(type):
"""
......@@ -85,7 +89,8 @@ class Config(metaclass=ConfigMeta):
val = val[key]
return val
def get_config(self, ckey: str = '', ekey: str = '') -> Union[Any, object]:
def get_config(self, ckey: str = '', ekey: str = '',
isfile: bool = False) -> Union[Any, object]:
"""
Seek for config val through environment and config depending
on given keys.
......@@ -103,10 +108,21 @@ class Config(metaclass=ConfigMeta):
if not any([ckey, ekey]):
return None
defaults = DEFAULT_FILE_PATHS if isfile else DEFAULTS
env_value = os.getenv("BEIRAN_{}".format(ekey))
if env_value:
if ekey in defaults:
if isinstance(defaults[ekey], list):
return env_value.split(',')
if isinstance(defaults[ekey], int):
return int(env_value)
return \
os.getenv("BEIRAN_{}".format(ekey)) or \
env_value or \
self.get_config_from_file(ckey) or \
DEFAULTS.get(ekey, None)
defaults.get(ekey, None)
@staticmethod
def load_from_file(config_file: str):
......@@ -211,13 +227,13 @@ class Config(metaclass=ConfigMeta):
Environment variable: ``BEIRAN_LOG_FILE``
"""
return self.get_config('beiran.log_file', 'LOG_FILE')
return self.get_config('beiran.log_file', 'LOG_FILE', isfile=True)
@property
def discovery_method(self):
"""
Service discovery method for beiran daemons to find each
others. The default value is ``zeroconf``. It can be eighter
others. The default value is ``None``. It can be eighter
``zeroconf``, ``dns`` or any other discovery plugins name.
config.toml: section ``beiran``, key ``discovery_method``
......@@ -253,6 +269,81 @@ class Config(metaclass=ConfigMeta):
"""
return self.get_config('beiran.listen_port', 'LISTEN_PORT')
@property
def url(self):
"""
Beiran daemon's URL. The default value is ``None``
config.toml: section ``beiran``, key ``url``
Environment variable: ``BEIRAN_URL``
"""
return self.get_config('beiran.url', 'URL')
@property
def hostname(self):
"""
Beiran daemon's hostname. The default value is ``None``
config.toml: section ``beiran``, key ``hostname``
Environment variable: ``BEIRAN_HOSTNAME``
"""
return self.get_config('beiran.hostname', 'HOSTNAME')
@property
def listen_interface(self):
"""
Beiran daemon's interface. The default value is ``None``
config.toml: section ``beiran``, key ``listen_interface``
Environment variable: ``BEIRAN_LISTEN_INTERFACE``
"""
return self.get_config('beiran.listen_interface', 'LISTEN_INTERFACE')
@property
def known_nodes(self):
"""
List of URLs of known nodes. Beiran daemon tries to communicate with
them. The default value is ``[]``
config.toml: section ``beiran``, key ``known_nodes``
Environment variable: ``BEIRAN_KNOWN_NODES``
"""
return self.get_config('beiran.known_nodes', 'KNOWN_NODES')
@property
def db_file(self):
"""
A file path for database. The default value is
``/var/lib/beiran/beiran.db``.
config.toml: section ``beiran``, key ``db_file``
Environment variable: ``BEIRAN_DB_FILE``
"""
return self.get_config('beiran.db_file', 'DB_FILE', isfile=True)
@property
def socket_file(self):
"""
A file path for socket. The default value is
``/var/run/beirand.sock``.
config.toml: section ``beiran``, key ``socket_file``
Environment variable: ``BEIRAN_SOCKET_FILE``
"""
return self.get_config('beiran.socket_file', 'SOCKET_FILE', isfile=True)
@property
def plugin_types(self):
"""Return the list of supported plugin types"""
......@@ -273,10 +364,10 @@ class Config(metaclass=ConfigMeta):
"""Get the list of the enabled plugins"""
plugins = []
env_config = os.getenv('BEIRAN_PLUGINS')
if env_config:
env_plugins = os.getenv('BEIRAN_PLUGINS')
if env_plugins:
try:
for p_package in env_config.split(','):
for p_package in env_plugins.split(','):
(p_type, p_name) = p_package.split('.')
if p_type not in self.plugin_types:
raise Exception("Unknown plugin type: %s" % (p_type))
......@@ -307,7 +398,21 @@ class Config(metaclass=ConfigMeta):
return plugins
def get_plugin_config(self, p_type, name):
"""Get params of package plugin"""
"""Get params of package plugin. To set the plugin's
configuration with the environment variable,
set ``BEIRAN_<plugin type>_<plugin name>_CONFIG`` like this.
``BEIRAN_PACKAGE_DOCKER_CONFIG="chahce_dir=temp,foo=bar"``
"""
env_config = os.getenv("BEIRAN_{}_{}_CONFIG".format(p_type.upper(), name.upper()))
conf = dict()
if env_config:
for item in env_config.split(','):
key, value = item.split('=')
conf[key] = value
return conf
conf = self.get_config(ckey='%s.%s' % (p_type, name))
if not conf:
return dict()
......@@ -344,4 +449,6 @@ class Config(metaclass=ConfigMeta):
return self.__init__(config_file)
config = Config() # pylint: disable=invalid-name
config = Config( # pylint: disable=invalid-name
config_file=os.getenv("BEIRAN_CONF_FILE", None)
)
......@@ -9,8 +9,7 @@ data_dir = '/var/lib/beiran'
run_dir = '/var/run'
listen_port = 8888
listen_address = '0.0.0.0'
socket_path = '/var/run/beirand.sock'
daemon_url = ''
socket_file = '/var/run/beirand.sock'
discovery_method = 'zeroconf'
# docker plugin settings
......
......@@ -19,10 +19,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""HTTP and WS API implementation of beiran daemon"""
import os
from tornado import websocket, web
from tornado.options import options, define
from tornado.options import define
from tornado.web import HTTPError
from beiran.config import config
......@@ -30,7 +28,7 @@ from beiran.models import Node, PeerAddress
from beiran.cmd_req_handler import RPCEndpoint, rpc
from beiran.daemon.common import Services
from beiran.daemon.lib import get_listen_address, get_listen_port
from beiran.daemon.lib import get_listen_address
define('listen_address',
......@@ -39,18 +37,14 @@ define('listen_address',
help='Listen address')
define('listen_port',
group='webserver',
default=get_listen_port(),
default=config.listen_port,
help='Listen port')
define('unix_socket',
group='webserver',
default=config.run_dir + "/beirand.sock",
default=config.socket_file,
help='Path to unix socket to bind')
if 'BEIRAN_SOCK' in os.environ:
options.unix_socket = os.environ['BEIRAN_SOCK']
class EchoWebSocket(websocket.WebSocketHandler):
""" Websocket implementation for test
"""
......
......@@ -56,8 +56,7 @@ def local_node_uuid() -> UUID:
if LOCAL_NODE_UUID_CACHED:
return LOCAL_NODE_UUID_CACHED
config_folder = config.config_dir
uuid_conf_path = "/".join([config_folder, 'uuid.conf'])
uuid_conf_path = "/".join([config.config_dir, 'uuid.conf'])
try:
uuid_file = open(uuid_conf_path)
uuid_hex = uuid_file.read()
......@@ -115,24 +114,11 @@ def get_listen_address() -> str:
`{}` is not a valid one!""".format(env_addr))
def get_listen_port() -> int:
"""
Get listen port from env or default 8888
Returns:
int: listen port
"""
try:
return int(os.environ.get('LISTEN_PORT', config.listen_port))
except ValueError:
raise ValueError('LISTEN_PORT must be a valid port number!')
def get_listen_interface() -> str:
"""
Seek for listen interface in order described below and return it.
First try LISTEN_INTERFACE env var.
First try BEIRAN_LISTEN_INTERFACE env var.
Second try to find the interface of ip address specified by config.listen_address.
Third, if config.listen_address is not set return default gateway's interface
......@@ -141,8 +127,8 @@ def get_listen_interface() -> str:
"""
if 'LISTEN_INTERFACE' in os.environ:
return os.environ['LISTEN_INTERFACE']
if config.listen_interface:
return config.listen_interface
if config.listen_address:
for interface in netifaces.interfaces():
......@@ -159,7 +145,7 @@ def get_listen_interface() -> str:
def get_advertise_address() -> str:
"""
First try environment variable `ADVERTISE_ADDR`. If it is not set,
First try environment variable `BEIRAN_LISTEN_ADDRESS`. If it is not set,
return the listen address unless it is `0.0.0.0`.
Lastly return default gateway's ip address
......@@ -172,10 +158,6 @@ def get_advertise_address() -> str:
string: ip address of advertise address
"""
if 'ADVERTISE_ADDR' in os.environ:
return os.environ['ADVERTISE_ADDR']
listen_address = get_listen_address()
if listen_address != '0.0.0.0':
......@@ -188,8 +170,8 @@ def get_advertise_address() -> str:
def get_hostname() -> str:
""" Gets hostname for discovery
"""
if 'HOSTNAME' in os.environ:
return os.environ['HOSTNAME']
if config.hostname:
return config.hostname
return socket.gethostname()
......@@ -246,14 +228,14 @@ def collect_node_info() -> dict:
peer_address = PeerAddress(
uuid=local_node_uuid().hex,
host=get_advertise_address(),
port=get_listen_port(),
port=config.listen_port,
)
return {
"uuid": local_node_uuid().hex,
"address": peer_address.address,
"hostname": get_hostname(),
"ip_address": get_advertise_address(),
"port": get_listen_port(),
"port": config.listen_port,
"ip_address_6": None,
"os_type": platform.system(),
"os_version": platform.version(),
......
......@@ -48,7 +48,7 @@ from beiran.daemon.nodes import Nodes
from beiran.daemon.peer import Peer
from beiran.daemon.lib import collect_node_info
from beiran.daemon.lib import get_listen_port, get_advertise_address
from beiran.daemon.lib import get_advertise_address
from beiran.daemon.lib import update_sync_version_file
from beiran.daemon.http_ws import ROUTES
......@@ -102,7 +102,7 @@ class BeiranDaemon(EventEmitter):
service_port (int): service port of new node
"""
service_port = service_port or get_listen_port()
service_port = service_port or config.listen_port
try:
node = await self.nodes.get_node_by_ip_and_port(ip_address, service_port)
except Node.DoesNotExist:
......@@ -216,7 +216,7 @@ class BeiranDaemon(EventEmitter):
logger.setLevel(logging.INFO)
# check database file exists
beiran_db_path = os.getenv("BEIRAN_DB_PATH", '{}/beiran.db'.format(config.data_dir))
beiran_db_path = config.db_file
db_file_exists = os.path.exists(beiran_db_path)
if not db_file_exists:
......@@ -272,12 +272,12 @@ class BeiranDaemon(EventEmitter):
shared_config_for_plugins = {
"version": VERSION,
}
for plugin in config.get_enabled_plugins():
for plugin in config.enabled_plugins:
type_specific_config = dict()
if plugin['type'] == 'discovery':
type_specific_config = {
"address": get_advertise_address(),
"port": get_listen_port()
"port": config.listen_port
}
_plugin_obj = await self.get_plugin(plugin['type'], plugin['name'], {
**shared_config_for_plugins,
......@@ -286,7 +286,7 @@ class BeiranDaemon(EventEmitter):
})
# Only one discovery plugin at a time is supported (for now)
if plugin['type'] == 'discovery':
if plugin['type'] == 'discovery' and plugin['name'] == config.discovery_method:
Services.plugins['discovery'] = _plugin_obj
else:
Services.plugins['%s:%s' % (plugin['type'], plugin['name'])] = _plugin_obj
......@@ -312,8 +312,7 @@ class BeiranDaemon(EventEmitter):
)
# Probe Known Nodes
known_nodes = os.getenv("KNOWN_NODES")
known_urls = known_nodes.split(',') if known_nodes else []
known_urls = config.known_nodes
Services.get_logger().info("KNOWN_NODES are: %s", known_urls)
for known_url in known_urls:
......
......@@ -20,7 +20,6 @@
""" Logging package for daemon """
import os
import sys
import logging
......@@ -34,8 +33,7 @@ def build_logger(filename: str = config.log_file,
stdout_handler = logging.StreamHandler(sys.stdout)
handlers = [stdout_handler] # type: List[Union[logging.FileHandler, logging.StreamHandler]]
if filename:
file_handler = logging.FileHandler(filename=os.getenv(
'LOG_FILE', filename))
file_handler = logging.FileHandler(filename=filename)
handlers.append(file_handler)
logging.getLogger('asyncio').level = logging.WARNING
logging.basicConfig(
......
......@@ -27,6 +27,7 @@ from urllib.parse import urlparse
import re
from datetime import datetime
from peewee import IntegerField, CharField, UUIDField
from beiran.config import config
from beiran.models.base import BaseModel, JSONStringField
from beiran.log import build_logger
......@@ -189,7 +190,7 @@ class PeerAddress(BaseModel): # pylint: disable=too-many-instance-attributes
@classmethod
def add_or_update(cls, uuid: str, address: str,
discovery: str = None, config: dict = None) -> None:
discovery: str = None, paconfig: dict = None) -> None:
"""
Update with or create a new peer_address object from provided information.
......@@ -197,7 +198,7 @@ class PeerAddress(BaseModel): # pylint: disable=too-many-instance-attributes
uuid (str): uuid
address (str): address
discovery (str): discovery channel
config (dict): config dict
paconfig (dict): paconfig dict
Returns:
......@@ -209,10 +210,9 @@ class PeerAddress(BaseModel): # pylint: disable=too-many-instance-attributes
_self = cls(uuid=uuid, address=address)
_self.last_seen_at = int(datetime.now().timestamp())
if config:
_self.config = config
if discovery:
_self.discovery_method = discovery
if paconfig:
_self.config = paconfig
_self.discovery_method = discovery if discovery else config.discovery_method
_self.save()
@staticmethod
......
......@@ -76,6 +76,7 @@ class AbstractBasePlugin(metaclass=ABCMeta):
class BasePlugin(AbstractBasePlugin, EventEmitter): # pylint: disable=too-many-instance-attributes
"""BeiranPlugin with EventEmmiter
"""
DEFAULTS = {} # type: dict
def __init__(self, config: dict) -> None:
"""
......@@ -102,7 +103,8 @@ class BasePlugin(AbstractBasePlugin, EventEmitter): # pylint: disable=too-many-
if self.log.level == logging.NOTSET:
self.log.setLevel(logging.WARN)
self.daemon = config.pop('daemon')
self.config = config
self.config = self.init_config(config)
self.set_dynamic_defaults()
self.loop = get_event_loop()
self.status = 'init'
......@@ -139,6 +141,17 @@ class BasePlugin(AbstractBasePlugin, EventEmitter): # pylint: disable=too-many-
# """Get plugin status"""
# return self.__status
def init_config(self, config: dict):
"""Initialize plugin configuration. Values ​​not in ``config`` are
set with default values"""
for key, value in self.DEFAULTS.items():
config.setdefault(key, value)
return config
def set_dynamic_defaults(self):
"""Set dynamic configuration values like using ``run_dir``"""
pass
def emit(self, event: str, *args: Any, **kwargs: Any) -> None:
if event != 'new_listener':
# self.log.debug('[' + self.plugin_type
......
......@@ -63,15 +63,15 @@ chmod +x ${VIRTUAL_ENV_DIR}/bin/beiran*
export PATH="${VIRTUAL_ENV_DIR}/bin:$PATH"
export LOG_LEVEL=DEBUG
export LOG_FILE=${DIR}/beirand.log
export RUN_DIR_PATH=${DIR}
export BEIRAN_SOCK=${RUN_DIR_PATH}/beirand.sock
export BEIRAN_LOG_LEVEL=DEBUG
export BEIRAN_LOG_FILE=${DIR}/beirand.log
export BEIRAN_RUN_DIR=${DIR}
export BEIRAN_SOCKET_FILE=${BEIRAN_RUN_DIR}/beirand.sock
export BEIRAN_PORT=${BEIRAN_PORT:-8888}
export BEIRAN_URL=http://localhost:${BEIRAN_PORT}
export BEIRAN_DB_PATH=${DIR}/beiran.db
export LISTEN_ADDR=0.0.0.0
export CONFIG_DIR_PATH=${DIR}
export BEIRAN_DB_FILE=${DIR}/beiran.db
export BEIRAN_LISTEN_ADDRESS=0.0.0.0
export BEIRAN_CONFIG_DIR=${DIR}
function ps1_context {
# For any of these bits of context that exist, display them and append
......
......@@ -10,8 +10,8 @@ services:
- .:/src
environment:
- BEIRAN_DISCOVERY_METHOD=dns
- DISCOVERY_SERVICE_ADDRESS=beiran_dns
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_DISCOVERY_DNS_CONFIG='discovery_service_address=beiran_dns'
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
- BEIRAN_LOG_LEVEL=INFO
networks:
......
......@@ -24,7 +24,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
pod2:
......@@ -51,7 +51,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
pod3:
......@@ -78,7 +78,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
pod4:
image: gcr.io/google_containers/pause:0.8.0
......@@ -104,7 +104,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
networks:
test:
......@@ -23,7 +23,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
pod2:
......@@ -49,7 +49,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
pod3:
......@@ -75,7 +75,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
pod4:
image: gcr.io/google_containers/pause:0.8.0
......@@ -100,7 +100,7 @@ services:
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_PLUGINS=discovery.zeroconf,package.docker
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
networks:
test:
......@@ -9,7 +9,7 @@ services:
- .:/src
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
- BEIRAN_LISTEN_PORT=8889
- BEIRAN_LOG_LEVEL=INFO
......@@ -21,7 +21,7 @@ services:
- .:/src
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
- BEIRAN_LOG_LEVEL=INFO
- BEIRAN_LISTEN_PORT=8890
......@@ -33,6 +33,6 @@ services:
- .:/src
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
- BEIRAN_LOG_LEVEL=INFO
- BEIRAN_LISTEN_PORT=8891
......@@ -15,6 +15,6 @@ services:
network_mode: host
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_LISTEN_ADDR=0.0.0.0
- DISCOVERY_SERVICE_ADDRESS=beirand
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
- BEIRAN_DISCOVERY_DNS_CONFIG='discovery_service_address=beirand'
- BEIRAN_LOG_LEVEL=INFO
......@@ -13,10 +13,10 @@ services:
# network_mode: host
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
- BEIRAN_LISTEN_PORT=8892
- BEIRAN_LOG_LEVEL=INFO
# - HOSTNAME=b1
# - BEIRAN_HOSTNAME=b1
- DOCKER_HOST=http://172.17.0.1:2375
ports:
- 8892:8892
......@@ -35,10 +35,10 @@ services:
# network_mode: host
environment:
- BEIRAN_DISCOVERY_METHOD=zeroconf
- BEIRAN_LISTEN_ADDR=0.0.0.0
- BEIRAN_LISTEN_ADDRESS=0.0.0.0
- BEIRAN_LISTEN_PORT=8891
- BEIRAN_LOG_LEVEL=INFO
# - HOSTNAME=b2
# - BEIRAN_HOSTNAME=b2
- DOCKER_HOST=http://172.17.0.1:2375
ports:
- 8891:8891
......
......@@ -22,7 +22,6 @@
Zeroconf multicast discovery service implementation
"""
import os
import asyncio
import aiodns
......@@ -33,13 +32,14 @@ from beiran.plugin import BaseDiscoveryPlugin
PLUGIN_NAME = 'dns'
PLUGIN_TYPE = 'discovery'
# Constants
DEFAULT_DOMAIN = "_beiran._tcp.local."
class DNSDiscovery(BaseDiscoveryPlugin):
"""Beiran Implementation of DNS Service Discovery
"""
DEFAULTS = {
'discovery_service_address': 'beirand',
'domain': '_beiran._tcp.local.',
}
def __init__(self, config: dict) -> None: