config: implement 'set_dynamic_defaults' to enable to set all plugin's config values

parent b518fbd5
......@@ -104,6 +104,7 @@ class BasePlugin(AbstractBasePlugin, EventEmitter): # pylint: disable=too-many-
self.log.setLevel(logging.WARN)
self.daemon = config.pop('daemon')
self.config = self.init_config(config)
self.set_dynamic_defaults()
self.loop = get_event_loop()
self.status = 'init'
......@@ -147,6 +148,10 @@ class BasePlugin(AbstractBasePlugin, EventEmitter): # pylint: disable=too-many-
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
......
......@@ -32,15 +32,13 @@ 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'
'discovery_service_address': 'beirand',
'domain': '_beiran._tcp.local.',
}
def __init__(self, config: dict) -> None:
......
......@@ -37,22 +37,21 @@ from beiran.plugin import BaseDiscoveryPlugin
PLUGIN_NAME = 'zeroconf'
PLUGIN_TYPE = 'discovery'
# Constants
DEFAULT_DOMAIN = "_beiran._tcp.local."
class ZeroconfDiscovery(BaseDiscoveryPlugin):
"""Beiran Implementation of Zeroconf Multicast DNS Service Discovery
"""
DEFAULTS = {} # type: dict
DEFAULTS = {
'domain': '_beiran._tcp.local.',
}
def __init__(self, config: dict) -> None:
""" Creates an instance of Zeroconf Discovery Service
"""
super().__init__(config)
self.info = None
self.domain = config['domain'] if 'domain' in config else DEFAULT_DOMAIN
self.version = config['version']
self.domain = self.config['domain']
self.version = self.config['version']
self.zeroconf = Zeroconf(self.loop,
address_family=[netifaces.AF_INET],
iface=self.network_interface)
......
......@@ -43,10 +43,13 @@ class K8SInterface(BaseInterfacePlugin):
def __init__(self, plugin_config: dict) -> None:
super().__init__(plugin_config)
if 'unix_socket_path' in plugin_config:
self.unix_socket_path = plugin_config['unix_socket_path']
else:
self.unix_socket_path = "unix://" + config.run_dir + "/beiran-cri.sock"
self.unix_socket_path = self.config['unix_socket_path']
def set_dynamic_defaults(self):
"""Set dynamic configuration value like using ``run_dir``"""
self.config.setdefault(
'unix_socket_path', "unix://" + config.run_dir + "/beiran-cri.sock"
)
async def init(self):
ApiDependencies.logger = self.log
......
......@@ -49,17 +49,20 @@ PLUGIN_TYPE = 'package'
# pylint: disable=attribute-defined-outside-init
class DockerPackaging(BasePackagePlugin): # pylint: disable=too-many-instance-attributes
"""Docker support for Beiran"""
DEFAULTS = {} # type: dict
DEFAULTS = {
'storage': '/var/lib/docker'
}
def __init__(self, config_dict: dict) -> None:
super().__init__({
"storage": "/var/lib/docker",
**config_dict
})
# def __init__(self, plugin_config: dict) -> None:
# super().__init__(plugin_config)
def set_dynamic_defaults(self):
"""Set dynamic configuration value like using ``run_dir``"""
self.config.setdefault('cache_dir', config.cache_dir + '/docker')
async def init(self):
self.aiodocker = Docker()
self.util = DockerUtil(cache_dir=config.cache_dir + '/docker',
self.util = DockerUtil(cache_dir=self.config["cache_dir"],
storage=self.config["storage"], aiodocker=self.aiodocker,
logger=self.log, local_node=self.node)
self.docker = docker.from_env()
......
......@@ -109,7 +109,7 @@ class DockerUtil: # pylint: disable=too-many-instance-attributes
# event datas for downloading layers
EVENT_START_LAYER_DOWNLOAD = "start_layer_download"
def __init__(self, cache_dir: str, storage: str = "/var/lib/docker", # pylint: disable=too-many-arguments
def __init__(self, cache_dir: str, storage: str, # pylint: disable=too-many-arguments
aiodocker: Docker = None, logger: logging.Logger = None,
local_node: Node = None) -> None:
self.cache_dir = cache_dir
......
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