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

Implemented mcli role allowing multiple clients under the same account

parent 701ebd1a
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -30,8 +30,11 @@ from cloudcontrol.server.clients import Client, RegisteredCCHandler
from cloudcontrol.server.jobs import (ColdMigrationJob, HotMigrationJob,
                                      CloneJob, KillClientJob, AllocationJob,
                                      MigrationJob)
from cloudcontrol.server.db import SObject

from cloudcontrol.common.tql.db.tag import StaticTag


MIGRATION_TYPES = {'cold': ColdMigrationJob,
                   'hot': HotMigrationJob,}
RESCUE_SCRIPT = 'rescue'
@@ -1377,4 +1380,35 @@ class CliClient(Client):
        """
        self.conn.call('wall', sender, message)


class MultiCliClient(CliClient):

    """ A bootstrap client connected to the cc-server.
    """

    ROLE = 'mcli'
    KILL_ALREADY_CONNECTED = False

    def _get_tql_object(self):
        tql_object = SObject(self.login)
        tql_object.register(StaticTag('r', self.role))
        tql_object.register(StaticTag('a', self._login))
        self._server.db.register(tql_object)
        return tql_object

    @property
    def login(self):
        return '%s.%s' % (self._login, self.conn.get_fd())

    @property
    def role(self):
        return 'cli'

    def shutdown(self):
        super(MultiCliClient, self).shutdown()
        # Also, remote the object from the db:
        self._server.db.unregister(self.login)


Client.register_client_class(MultiCliClient)
Client.register_client_class(CliClient)