Feature ready. UX to be refactor

pull/454/head
Nicolargo 2014-11-24 21:47:18 +01:00
parent e3d84c79b2
commit bd768aa4da
3 changed files with 28 additions and 14 deletions

View File

@ -135,3 +135,9 @@ list_2_countmin=1
# Define the static server list
server_1_name=localhost
server_1_port=61234
server_2_name=localhost
server_2_port=61235
server_3_name=localhost
server_3_port=61236
server_4_name=pasbon
server_4_port=61237

View File

@ -67,7 +67,7 @@ class GlancesClientBrowser(object):
if self.args.browser:
ret = self.static_server.get_servers_list()
if self.autodiscover_server is not None:
ret = self.autodiscover_server.get_servers_list() + self.static_server.get_servers_list()
ret = self.static_server.get_servers_list() + self.autodiscover_server.get_servers_list()
return ret
@ -142,9 +142,15 @@ class GlancesClientBrowser(object):
clear_password = self.screen.display_popup(_("Password needed for %s: " % v['name']), is_input=True)
# Hash with SHA256
encoded_password = sha256(clear_password).hexdigest()
self.autodiscover_server.set_server(self.screen.get_active(),
'password',
encoded_password)
# Static list then dynamic one
if self.screen.get_active() >= len(self.static_server.get_servers_list()):
self.autodiscover_server.set_server(self.screen.get_active() - len(self.static_server.get_servers_list()),
'password',
encoded_password)
else:
self.static_server.set_server(self.screen.get_active(),
'password',
encoded_password)
# Display the Glance client on the selected server
logger.info("Connect Glances client to the %s server" %

View File

@ -19,6 +19,9 @@
"""Manage the Glances server static list """
# System lib
from socket import gethostbyname, gaierror
# Import Glances libs
from glances.core.glances_globals import logger
@ -45,25 +48,24 @@ class GlancesStaticServer(object):
elif not config.has_section(self._section):
logger.warning("No [%s] section in the configuration file. Can not load server list." % self._section)
else:
logger.info("Start reading the [%s] section in the configuration file" % self._section)
for i in range(1, 256):
new_server = {}
postfix = 'server_%s_' % str(i)
# Read the server name (mandatory)
new_server['name'] = config.get_raw_option(self._section, '%sname' % postfix)
for s in ['name', 'port']:
new_server[s] = config.get_raw_option(self._section, '%s%s' % (postfix, s))
if new_server['name'] is not None:
# Read other optionnal information
for s in ['alias', 'port', 'password']:
new_server[s] = config.get_raw_option(self._section, '%s%s' % (postfix, s))
# Manage optionnal information
if new_server['alias'] is None:
new_server['alias'] = new_server['name']
if new_server['port'] is None:
new_server['port'] = 61209
if new_server['password'] is None:
new_server['password'] = ''
new_server['username'] = 'glances'
new_server['ip'] = new_server['name']
new_server['password'] = ''
try:
new_server['ip'] = gethostbyname(new_server['name'])
except gaierror as e:
logger.error("Can not get IP address for server %s (%s)" % (new_server['name'], e))
continue
new_server['key'] = new_server['name'] + ':' + new_server['port']
new_server['status'] = 'UNKNOWN'