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
self._watched_files = {}
self._watch_callback = []
if sys.platform.startswith("win"):
@ -116,6 +117,12 @@ class Config:
self.clear()
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
def profile(self):
"""
@ -143,6 +150,8 @@ class Config:
self.read_config()
for section in self._override_config:
self.set_section_config(section, self._override_config[section])
for callback in self._watch_callback:
callback()
def reload(self):
"""

View File

@ -48,7 +48,7 @@ class Controller:
self.symbols = Symbols()
# Store settings shared by the different GUI will be replace by dedicated API later
self._settings = None
self._local_server = None
self._config_file = os.path.join(Config.instance().config_dir, "gns3_controller.conf")
log.info("Load controller configuration file {}".format(self._config_file))
@ -57,6 +57,7 @@ class Controller:
log.info("Start controller")
server_config = Config.instance().get_section_config("Server")
Config.instance().listen_for_config_changes(self._update_config)
host = server_config.get("host", "localhost")
# 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()
try:
yield from self.add_compute(compute_id="local",
name=name,
protocol=server_config.get("protocol", "http"),
host=host,
console_host=console_host,
port=server_config.getint("port", 3080),
user=server_config.get("user", ""),
password=server_config.get("password", ""),
force=True)
self._local_server = yield from self.add_compute(compute_id="local",
name=name,
protocol=server_config.get("protocol", "http"),
host=host,
console_host=console_host,
port=server_config.getint("port", 3080),
user=server_config.get("user", ""),
password=server_config.get("password", ""),
force=True)
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")
sys.exit(1)
@ -92,6 +93,16 @@ class Controller:
yield from self.gns3vm.auto_start_vm()
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
def stop(self):
log.info("Stop controller")