First try to manage Glances server protected by password

This commit is contained in:
Nicolargo 2014-11-16 21:56:48 +01:00
parent 290d8a1d32
commit 2d72625344
2 changed files with 13 additions and 13 deletions

View File

@ -23,10 +23,10 @@
import json
import socket
try:
from xmlrpc.client import ServerProxy, Fault
from xmlrpc.client import ServerProxy, Fault, ProtocolError
except ImportError:
# Python 2
from xmlrpclib import ServerProxy, Fault
from xmlrpclib import ServerProxy, Fault, ProtocolError
# Import Glances libs
from glances.core.glances_globals import logger
@ -69,12 +69,9 @@ class GlancesClientBrowser(object):
for v in self.get_servers_list():
# !!! Perhaps, it will be better to store the ServerProxy instance in the get_servers_list
uri = 'http://%s:%s' % (v['ip'], v['port'])
# Configure the server timeout to 3 seconds
t = GlancesClientTransport()
t.set_timeout(3)
# !!! How to manage password protection ???
# => Disable autodiscover if password is set ?
# => Display a popup and ask for password ? <=====
# Get common stats
try:
s = ServerProxy(uri, t)
except Exception as e:
@ -95,6 +92,9 @@ class GlancesClientBrowser(object):
except (socket.error, Fault, KeyError) as e:
logger.warning(
"Can not grab stats form {0}: {1}".format(uri, e))
except ProtocolError as e:
logger.debug(
"Password protected server. Can not grab stats from {0}: {1}".format(uri, e))
# List can change size during iteration...
except RuntimeError:
logger.debug(

View File

@ -995,14 +995,14 @@ class GlancesCursesBrowser(_GlancesCurses):
line = 0
for v in servers_list:
# Get server stats
try:
server_stat = {}
for c in column_def:
server_stat = {}
for c in column_def:
try:
server_stat[c[0]] = v[c[0]]
except KeyError as e:
logger.debug(
"Can not grab stats %s from server (KeyError: %s)".format(c[0], e))
continue
except KeyError as e:
logger.debug(
"Can not grab stats {0} from server (KeyError: {1})".format(c[0], e))
server_stat[c[0]] = '?'
# Display line for server stats
cpt = 0