예제 #1
0
    def connectToClusterServer(self, useSSL, certificatePath, clusterServerIP,
                               clusterServerListenningPort,
                               statusDBUpdateInterval, commandTimeout,
                               commandTimeoutCheckInterval):
        """
        Establishes a connection with the cluster server
        Args:
            certificatePath: the directory where the server.crt and server.key files are
            clusterServerIP: the cluster server's IP address
            clusterServerListenningPort: the cluster server commands connection's port
            statusDBUpdateInterval: the database update interval (in seconds)
        Returns:
            Nothing
        """
        self.__networkManager = NetworkManager(certificatePath)
        self.__networkManager.startNetworkService()

        self.__clusterServerIP = clusterServerIP
        self.__clusterServerPort = clusterServerListenningPort
        self.__packetHandler = ClusterServerPacketHandler(
            self.__networkManager)
        self.__commandsProcessor = CommandsProcessor(
            self.__commandsHandler, self.__packetHandler,
            self.__networkManager, self.__clusterServerIP,
            self.__clusterServerPort, self.__commandsDBConnector,
            self.__endpointDBConnector)
        packetReactor = ClusterEndpointPacketReactor(
            self.__codeTranslator, self.__commandsHandler,
            self.__packetHandler, self.__commandsProcessor,
            self.__endpointDBConnector, self.__commandsDBConnector)
        try:
            self.__networkManager.connectTo(clusterServerIP,
                                            clusterServerListenningPort, 5,
                                            packetReactor, useSSL)
            while (not self.__networkManager.isConnectionReady(
                    clusterServerIP, clusterServerListenningPort)):
                sleep(0.1)
            self.__updateRequestThread = VMServerMonitoringThread(
                self.__packetHandler, self.__networkManager,
                self.__commandsProcessor, self.__clusterServerIP,
                self.__clusterServerPort, statusDBUpdateInterval)
            self.__updateRequestThread.start()
            self.__commandExecutionThread = CommandsMonitoringThread(
                self.__commandsDBConnector, commandTimeout,
                self.__commandsHandler, commandTimeoutCheckInterval)
            self.__commandExecutionThread.start()
        except NetworkManagerException as e:
            raise Exception(e.message)