29 lines
840 B
Python
29 lines
840 B
Python
import syncthing_monitor.config_xml as xml
|
|
from .etcd_client import EtcdClient
|
|
from .syncthing_client import SyncthingClient
|
|
|
|
DEFAULT_ST_CONFIG_XML_PATH = '/config/config.xml'
|
|
DEFAULT_ST_GUI_PORT = 8384
|
|
|
|
|
|
def loop(gui_port="8384", host="sync"):
|
|
api_key = xml.parse_api_key(DEFAULT_ST_CONFIG_XML_PATH)
|
|
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)
|
|
|
|
syncthing = SyncthingClient(api_key, host, gui_port)
|
|
my_device_id = syncthing.get_my_device_id()
|
|
print("Found Device ID: {0}".format(my_device_id))
|
|
|
|
etcd = EtcdClient('etcd')
|
|
etcd.append_device_id(my_device_id)
|
|
device_ids = etcd.get_device_list()
|
|
|
|
syncthing.add_devices(device_ids)
|
|
syncthing.print_config()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
loop()
|