Handle password configuration change on remote servers

Fix https://github.com/GNS3/gns3-gui/issues/1942
This commit is contained in:
Julien Duponchelle 2017-03-22 18:29:08 +01:00
parent cb78eb4ee3
commit 9fd5e4cbc9
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 30 additions and 10 deletions

View File

@ -50,6 +50,7 @@ class Config:
# Monitor configuration files for changes # Monitor configuration files for changes
self._watched_files = {} self._watched_files = {}
self._watch_callback = []
if sys.platform.startswith("win"): if sys.platform.startswith("win"):
@ -116,6 +117,12 @@ class Config:
self.clear() self.clear()
self._watch_config_file() self._watch_config_file()
def listen_for_config_changes(self, callback):
"""
Call the callback when the configuration file change
"""
self._watch_callback.append(callback)
@property @property
def profile(self): def profile(self):
""" """
@ -143,6 +150,8 @@ class Config:
self.read_config() self.read_config()
for section in self._override_config: for section in self._override_config:
self.set_section_config(section, self._override_config[section]) self.set_section_config(section, self._override_config[section])
for callback in self._watch_callback:
callback()
def reload(self): def reload(self):
""" """

View File

@ -48,7 +48,7 @@ class Controller:
self.symbols = Symbols() self.symbols = Symbols()
# Store settings shared by the different GUI will be replace by dedicated API later # Store settings shared by the different GUI will be replace by dedicated API later
self._settings = None self._settings = None
self._local_server = None
self._config_file = os.path.join(Config.instance().config_dir, "gns3_controller.conf") self._config_file = os.path.join(Config.instance().config_dir, "gns3_controller.conf")
log.info("Load controller configuration file {}".format(self._config_file)) log.info("Load controller configuration file {}".format(self._config_file))
@ -57,6 +57,7 @@ class Controller:
log.info("Start controller") log.info("Start controller")
server_config = Config.instance().get_section_config("Server") server_config = Config.instance().get_section_config("Server")
Config.instance().listen_for_config_changes(self._update_config)
host = server_config.get("host", "localhost") host = server_config.get("host", "localhost")
# If console_host is 0.0.0.0 client will use the ip they use # If console_host is 0.0.0.0 client will use the ip they use
@ -71,15 +72,15 @@ class Controller:
computes = yield from self._load_controller_settings() computes = yield from self._load_controller_settings()
try: try:
yield from self.add_compute(compute_id="local", self._local_server = yield from self.add_compute(compute_id="local",
name=name, name=name,
protocol=server_config.get("protocol", "http"), protocol=server_config.get("protocol", "http"),
host=host, host=host,
console_host=console_host, console_host=console_host,
port=server_config.getint("port", 3080), port=server_config.getint("port", 3080),
user=server_config.get("user", ""), user=server_config.get("user", ""),
password=server_config.get("password", ""), password=server_config.get("password", ""),
force=True) force=True)
except aiohttp.web_exceptions.HTTPConflict as e: except aiohttp.web_exceptions.HTTPConflict as e:
log.fatal("Can't acces to the local server, make sure anything else is not running on the same port") log.fatal("Can't acces to the local server, make sure anything else is not running on the same port")
sys.exit(1) sys.exit(1)
@ -92,6 +93,16 @@ class Controller:
yield from self.gns3vm.auto_start_vm() yield from self.gns3vm.auto_start_vm()
yield from self._project_auto_open() yield from self._project_auto_open()
def _update_config(self):
"""
Call this when the server configuration file
change
"""
if self._local_server:
server_config = Config.instance().get_section_config("Server")
self._local_server.user = server_config.get("user")
self._local_server.password = server_config.get("password")
@asyncio.coroutine @asyncio.coroutine
def stop(self): def stop(self):
log.info("Stop controller") log.info("Stop controller")