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

Now handle properly disconnections of a client.

parent 34c3ef80
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -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,
+7 −2
Original line number Diff line number Diff line
@@ -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.
    '''