syncthing-monitor/syncthing_monitor/__main__.py

29 lines
880 B
Python
Raw Normal View History

import syncthing_monitor.config_xml as xml
from syncthing_monitor.etcd_cluster_info import EtcdClient
from syncthing_monitor.syncthing_client import SyncthingClient
DEFAULT_ST_CONFIG_XML_PATH = '/config/config.xml'
DEFAULT_ST_GUI_PORT = 8384
2021-01-28 10:56:11 +00:00
2021-01-28 13:31:25 +00:00
def loop(gui_port="8384", host="sync"):
api_key = xml.parse_api_key(DEFAULT_ST_CONFIG_XML_PATH)
2021-01-28 10:56:11 +00:00
print("Found API Key: {0}".format(api_key))
xml.set_listen_ip_to_any(DEFAULT_ST_CONFIG_XML_PATH, DEFAULT_ST_CONFIG_XML_PATH, DEFAULT_ST_GUI_PORT)
2021-01-28 13:31:25 +00:00
syncthing = SyncthingClient(api_key, host, gui_port)
my_device_id = syncthing.get_my_device_id()
print("Found Device ID: {0}".format(my_device_id))
2021-01-28 13:31:25 +00:00
etcd = EtcdClient('etcd')
etcd.append_device_id(my_device_id)
device_ids = etcd.get_device_list()
syncthing.add_devices(device_ids)
syncthing.print_config()
2021-01-29 08:28:35 +00:00
2021-01-28 10:56:11 +00:00
if __name__ == "__main__":
loop()