config: cleanup HOSTNAME

parent d5c6ee3f
......@@ -110,7 +110,7 @@ All has default values.
```
LISTEN_INTERFACE
LISTEN_ADDR
HOSTNAME
BEIRAN_HOSTNAME
BEIRAN_SOCKET_FILE
```
......
......@@ -46,7 +46,7 @@ class BeiranContext:
"""Context object for Beiran Commands which keeps clients and other common objects"""
def __init__(self) -> None:
daemon_url = config.url if config.url != '' else \
daemon_url = config.url if config.url else \
"http+unix://" + config.socket_file
peer_address = PeerAddress(address=daemon_url)
......
......@@ -40,7 +40,6 @@ DEFAULTS = {
'CACHE_DIR': '/var/cache/beiran',
'RUN_DIR': '/var/run',
'DISCOVERY_METHOD': 'zeroconf',
'URL': '',
'KNOWN_NODES': [],
}
......@@ -273,7 +272,7 @@ class Config(metaclass=ConfigMeta):
@property
def url(self):
"""
Beiran daemon's URL. The default value is ``''``
Beiran daemon's URL. The default value is ``None``
config.toml: section ``beiran``, key ``url``
......@@ -282,6 +281,18 @@ class Config(metaclass=ConfigMeta):
"""
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 known_nodes(self):
"""
......
......@@ -10,7 +10,6 @@ run_dir = '/var/run'
listen_port = 8888
listen_address = '0.0.0.0'
socket_file = '/var/run/beirand.sock'
url = ''
discovery_method = 'zeroconf'
# docker plugin settings
......
......@@ -175,8 +175,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()
......
......@@ -16,7 +16,7 @@ services:
- BEIRAN_LISTEN_ADDR=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
......@@ -38,7 +38,7 @@ services:
- BEIRAN_LISTEN_ADDR=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
......
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