Commit 0c07df4b authored by Antoine Millet's avatar Antoine Millet

Now handle properly disconnections of a client.

parent 34c3ef80
......@@ -47,7 +47,8 @@ class CCServer(object):
# Create the connection manager:
self.manager = SimpleSslRpcServer(sock, certfile=certfile,
keyfile=keyfile,
default_handler=WelcomeHandler(self))
default_handler=WelcomeHandler(self),
on_disconnect='on_disconnect')
def iterrole(self, role):
'''
......@@ -71,6 +72,17 @@ class CCServer(object):
self._connected[login] = CCClient(login, role, self, connection)
def unregister(self, connection):
'''
Unregister an already connected account.
:param connection: the connection of the client to unregister
'''
client = self.search_client_by_connection(connection)
if client.login in self._connected:
del self._connected[client.login]
def search_client_by_connection(self, connection):
'''
Search a connected client by it connection. If no client is found,
......
......@@ -42,14 +42,19 @@ class CCHandler(RpcHandler):
return cmd_list
class HypervisorHandler(CCHandler):
class OnlineCCHandler(CCHandler):
def on_disconnect(self, connection):
self._server.unregister(connection)
class HypervisorHandler(OnlineCCHandler):
'''
Handler binded to 'node' role.
'''
role_name = 'hypervisor'
class ClientHandler(CCHandler):
class ClientHandler(OnlineCCHandler):
'''
Handler binded to 'cli' role.
'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment