2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 09:32:21 +00:00

Provide more specific details to client about reason for being unconnected

This commit is contained in:
jbjohnso 2014-04-23 14:04:26 -04:00
parent eacf28db69
commit ecbf2e95f9
4 changed files with 30 additions and 15 deletions

View File

@ -67,21 +67,16 @@ conserversequence = '\x05c' # ctrl-e, c
oldtcattr = termios.tcgetattr(sys.stdin.fileno())
netserver = None
statedata = {}
def updatestatus(stateinfo):
status = consolename
if 'clientcount' in stateinfo:
statedata['clientcount'] = stateinfo['clientcount']
if 'connectstate' in stateinfo:
statedata['connectstate'] = stateinfo['connectstate']
info = []
if ('connectstate' in statedata and
statedata['connectstate'] != 'connected'):
info.append(statedata['connectstate'])
if 'clientcount' in statedata and statedata['clientcount'] != 1:
info.append('clients: %d' % statedata['clientcount'])
if ('connectstate' in stateinfo and
stateinfo['connectstate'] != 'connected'):
info.append(stateinfo['connectstate'])
if 'error' in stateinfo:
info.append(stateinfo['error'])
if 'clientcount' in stateinfo and stateinfo['clientcount'] != 1:
info.append('clients: %d' % stateinfo['clientcount'])
if info:
status += ' [' + ','.join(info) + ']'
sys.stdout.write('\x1b]0;console: %s\x07' % status)

View File

@ -146,8 +146,9 @@ class _ConsoleHandler(object):
event=log.Events.stacktrace)
if not isinstance(self._console, conapi.Console):
self.connectstate = 'unconnected'
self._send_rcpts({'connectstate': self.connectstate})
self.error = 'misconfigured'
self._send_rcpts({'connectstate': self.connectstate,
'error': self.error})
return
self.send_break = self._console.send_break
if self._attribwatcher:
@ -161,10 +162,20 @@ class _ConsoleHandler(object):
(self.node,), attribstowatch, self._attribschanged)
try:
self._console.connect(self.get_console_output)
except exc.TargetEndpointBadCredentials:
self.error = 'badcredentials'
self.connectstate = 'unconnected'
self._send_rcpts({'connectstate': self.connectstate,
'error': self.error})
retrytime = 30 + (30 * random.random())
if not self.reconnect:
self.reconnect = eventlet.spawn_after(retrytime, self._connect)
return
except exc.TargetEndpointUnreachable:
self.error = 'unreachable'
self.connectstate = 'unconnected'
self._send_rcpts({'connectstate': self.connectstate})
self._send_rcpts({'connectstate': self.connectstate,
'error': self.error})
retrytime = 30 + (30 * random.random())
if not self.reconnect:
self.reconnect = eventlet.spawn_after(retrytime, self._connect)

View File

@ -36,6 +36,11 @@ class TargetEndpointUnreachable(ConfluentException):
# was unreachable. http code 504
pass
class TargetEndpointBadCredentials(ConfluentException):
# target was reachable, but authentication/authorization
# failed
pass
class ForbiddenRequest(ConfluentException):
# The client request is not allowed by authorization engine

View File

@ -138,7 +138,11 @@ class IpmiConsole(conapi.Console):
if self.broken:
break
if self.broken:
raise exc.TargetEndpointUnreachable(self.error)
if (self.error.startswith('Incorrect password') or
self.error.startswith('Unauthorized name')):
raise exc.TargetEndpointBadCredentials
else:
raise exc.TargetEndpointUnreachable(self.error)
self.connected = True
except socket.gaierror as err:
raise exc.TargetEndpointUnreachable(str(err))