示例#1
0
    def __init__(self):
        self.SettingsManagerInst = SettingsManager()
        self.StorageManagerInst = StorageManager()
        self.RSSFeedManagerInst = RSSFeedManager()
        self.NetworkManagerInst = NetworkManager()
        self.FileManagerInst = FileManager()
        self.GuiManagerInst = GuiManager()
        self.ThreadManagerInst = ThreadManager()

        self.setmanagers()
示例#2
0
 def connectToMainServer(self, certificatePath, mainServerIP,
                         mainServerListenningPort):
     self.__manager = NetworkManager(certificatePath)
     self.__manager.startNetworkService()
     callback = _MainServerConnectorCallback(self)
     # Connect to the main server
     self.__mainServerPort = mainServerListenningPort
     self.__manager.connectTo(mainServerIP, mainServerListenningPort, 5,
                              callback, True)
     while (not self.__manager.isConnectionReady(mainServerListenningPort)):
         sleep(0.1)
     # Create the packet handler
     self.__pHandler = MainServerPacketHandler(self.__manager)
     # Create the update thread
     self.__updateRequestThread = StatusDatabaseUpdateThread(
         _MainServerConnectorUpdateHandler(self), 20)
     # Start it
     self.__updateRequestThread.start()
    def __init__(self):
        self.SettingsManagerInst = SettingsManager()
        self.StorageManagerInst = StorageManager()
        self.RSSFeedManagerInst = RSSFeedManager()
        self.NetworkManagerInst = NetworkManager()
        self.FileManagerInst = FileManager()
        self.GuiManagerInst = GuiManager()
        self.ThreadManagerInst =  ThreadManager()

        self.setmanagers()
 def connectToMainServer(self, certificatePath, mainServerIP, mainServerListenningPort):
     self.__manager = NetworkManager(certificatePath)
     self.__manager.startNetworkService()
     callback = _MainServerConnectorCallback(self)
     # Connect to the main server
     self.__mainServerPort = mainServerListenningPort
     self.__manager.connectTo(mainServerIP, mainServerListenningPort, 5, callback, True)
     while (not self.__manager.isConnectionReady(mainServerListenningPort)) :
         sleep(0.1)
     # Create the packet handler
     self.__pHandler = MainServerPacketHandler(self.__manager)
     # Create the update thread
     self.__updateRequestThread = StatusDatabaseUpdateThread(_MainServerConnectorUpdateHandler(self), 20)
     # Start it
     self.__updateRequestThread.start()
class MainServerConnector(object):    

    def __init__(self, callback):
        self.__stopped = False
        self.__callback = callback
    
    def connectToDatabase(self, rootsPassword, databaseName, websiteUser, websiteUserPassword, updateUser, updateUserPassword):
        # Create the status database
        self.__rootsPassword = rootsPassword
        self.__databaseName = databaseName
        configurator = DBConfigurator(rootsPassword)
        configurator.runSQLScript(databaseName, "../../database/SystemStatusDB.sql")
        # Register the website and the update users
        configurator.addUser(websiteUser, websiteUserPassword, databaseName, False)
        configurator.addUser(updateUser, updateUserPassword, databaseName, True)
        # Create the database connectors
        self.__reader = SystemStatusDatabaseReader(websiteUser, websiteUserPassword, databaseName)
        self.__writer = SystemStatusDatabaseWriter(updateUser, updateUserPassword, databaseName)
        # Connect to the database
        self.__reader.connect()
        self.__writer.connect()
        
    def connectToMainServer(self, certificatePath, mainServerIP, mainServerListenningPort):
        self.__manager = NetworkManager(certificatePath)
        self.__manager.startNetworkService()
        callback = _MainServerConnectorCallback(self)
        # Connect to the main server
        self.__mainServerPort = mainServerListenningPort
        self.__manager.connectTo(mainServerIP, mainServerListenningPort, 5, callback, True)
        while (not self.__manager.isConnectionReady(mainServerListenningPort)) :
            sleep(0.1)
        # Create the packet handler
        self.__pHandler = MainServerPacketHandler(self.__manager)
        # Create the update thread
        self.__updateRequestThread = StatusDatabaseUpdateThread(_MainServerConnectorUpdateHandler(self), 20)
        # Start it
        self.__updateRequestThread.start()
        
    def disconnectFromMainServer(self):
        # Discard all the incoming packets and the scheduled updates
        self.__stopped = True
        # Stop the update request thread
        self.__updateRequestThread.stop()
        # Close the database connections
        self.__reader.disconnect()
        self.__writer.disconnect()
        # Stop the network service
        self.__manager.stopNetworkService()
        # Delete the status database
        dbConfigurator = DBConfigurator(self.__rootsPassword)
        dbConfigurator.dropDatabase(self.__databaseName)
        
    def getImages(self):
        return self.__reader.getImages()
        
    def getVMServersData(self):
        return self.__reader.getVMServersData()
    
    def registerVMServer(self, vmServerIP, vmServerPort, vmServerName):
        p = self.__pHandler.createVMServerRegistrationPacket(vmServerIP, vmServerPort, vmServerName)
        self.__manager.sendPacket(self.__mainServerPort, p)
        
    def unregisterVMServer(self, vmServerNameOrIP, halt):
        p = self.__pHandler.createVMServerUnregistrationOrShutdownPacket(vmServerNameOrIP, halt, False)
        self.__manager.sendPacket(self.__mainServerPort, p)
        
    def bootUpVMServer(self, vmServerNameOrIP):
        p = self.__pHandler.createVMServerBootUpPacket(vmServerNameOrIP)
        self.__manager.sendPacket(self.__mainServerPort, p)
        
    def shutdownVMServer(self, vmServerNameOrIP, halt):
        p = self.__pHandler.createVMServerUnregistrationOrShutdownPacket(vmServerNameOrIP, halt, True)
        self.__manager.sendPacket(self.__mainServerPort, p)
        
    def bootUpVirtualMachine(self, imageName, userID):
        p = self.__pHandler.createVMBootRequestPacket(imageName, userID)
        self.__manager.sendPacket(self.__mainServerPort, p)
        
    def _processIncomingPacket(self, packet):
        if (self.__stopped) :
            return
        data = self.__pHandler.readPacket(packet)
        if (data["packet_type"] == PACKET_T.VM_SERVERS_STATUS_DATA) :
            self.__writer.processVMServerSegment(data["Segment"], data["SequenceSize"], data["Data"])
        elif (data["packet_type"] == PACKET_T.AVAILABLE_IMAGES_DATA) :
            self.__writer.processImageSegment(data["Segment"], data["SequenceSize"], data["Data"])
        elif (data["packet_type"] == PACKET_T.VM_SERVER_BOOTUP_ERROR) :
            self.__callback.handleVMServerBootUpError(data["ServerNameOrIPAddress"], data["ErrorMessage"])
        elif (data["packet_type"] == PACKET_T.VM_SERVER_REGISTRATION_ERROR) :
            self.__callback.handleVMServerRegistrationError(data["ServerNameOrIPAddress"], data["ErrorMessage"])  
        elif (data["packet_type"] == PACKET_T.VM_BOOT_FAILURE) :
            self.__callback.handleVMBootFailure(data["VMName"], data["UserID"], data["ErrorMessage"])  
        elif (data["packet_type"] == PACKET_T.VM_CONNECTION_DATA) :
            self.__callback.handleVMConnectionData(data["UserID"], data["VNCServerIPAddress"], data["VNCServerPort"],
                                                   data["VNCServerPassword"])
    
    def _sendUpdateRequestPackets(self):
        if (self.__stopped) :
            return
        # Send some update request packets to the main server
        p = self.__pHandler.createDataRequestPacket(PACKET_T.QUERY_VM_SERVERS_STATUS)
        self.__manager.sendPacket(self.__mainServerPort, p)
        p = self.__pHandler.createDataRequestPacket(PACKET_T.QUERY_AVAILABLE_IMAGES)
        self.__manager.sendPacket(self.__mainServerPort, p)
示例#6
0
class MainServerConnector(object):
    def __init__(self, callback):
        self.__stopped = False
        self.__callback = callback

    def connectToDatabase(self, rootsPassword, databaseName, websiteUser,
                          websiteUserPassword, updateUser, updateUserPassword):
        # Create the status database
        self.__rootsPassword = rootsPassword
        self.__databaseName = databaseName
        configurator = DBConfigurator(rootsPassword)
        configurator.runSQLScript(databaseName,
                                  "../../database/SystemStatusDB.sql")
        # Register the website and the update users
        configurator.addUser(websiteUser, websiteUserPassword, databaseName,
                             False)
        configurator.addUser(updateUser, updateUserPassword, databaseName,
                             True)
        # Create the database connectors
        self.__reader = SystemStatusDatabaseReader(websiteUser,
                                                   websiteUserPassword,
                                                   databaseName)
        self.__writer = SystemStatusDatabaseWriter(updateUser,
                                                   updateUserPassword,
                                                   databaseName)
        # Connect to the database
        self.__reader.connect()
        self.__writer.connect()

    def connectToMainServer(self, certificatePath, mainServerIP,
                            mainServerListenningPort):
        self.__manager = NetworkManager(certificatePath)
        self.__manager.startNetworkService()
        callback = _MainServerConnectorCallback(self)
        # Connect to the main server
        self.__mainServerPort = mainServerListenningPort
        self.__manager.connectTo(mainServerIP, mainServerListenningPort, 5,
                                 callback, True)
        while (not self.__manager.isConnectionReady(mainServerListenningPort)):
            sleep(0.1)
        # Create the packet handler
        self.__pHandler = MainServerPacketHandler(self.__manager)
        # Create the update thread
        self.__updateRequestThread = StatusDatabaseUpdateThread(
            _MainServerConnectorUpdateHandler(self), 20)
        # Start it
        self.__updateRequestThread.start()

    def disconnectFromMainServer(self):
        # Discard all the incoming packets and the scheduled updates
        self.__stopped = True
        # Stop the update request thread
        self.__updateRequestThread.stop()
        # Close the database connections
        self.__reader.disconnect()
        self.__writer.disconnect()
        # Stop the network service
        self.__manager.stopNetworkService()
        # Delete the status database
        dbConfigurator = DBConfigurator(self.__rootsPassword)
        dbConfigurator.dropDatabase(self.__databaseName)

    def getImages(self):
        return self.__reader.getImages()

    def getVMServersData(self):
        return self.__reader.getVMServersData()

    def registerVMServer(self, vmServerIP, vmServerPort, vmServerName):
        p = self.__pHandler.createVMServerRegistrationPacket(
            vmServerIP, vmServerPort, vmServerName)
        self.__manager.sendPacket(self.__mainServerPort, p)

    def unregisterVMServer(self, vmServerNameOrIP, halt):
        p = self.__pHandler.createVMServerUnregistrationOrShutdownPacket(
            vmServerNameOrIP, halt, False)
        self.__manager.sendPacket(self.__mainServerPort, p)

    def bootUpVMServer(self, vmServerNameOrIP):
        p = self.__pHandler.createVMServerBootUpPacket(vmServerNameOrIP)
        self.__manager.sendPacket(self.__mainServerPort, p)

    def shutdownVMServer(self, vmServerNameOrIP, halt):
        p = self.__pHandler.createVMServerUnregistrationOrShutdownPacket(
            vmServerNameOrIP, halt, True)
        self.__manager.sendPacket(self.__mainServerPort, p)

    def bootUpVirtualMachine(self, imageName, userID):
        p = self.__pHandler.createVMBootRequestPacket(imageName, userID)
        self.__manager.sendPacket(self.__mainServerPort, p)

    def _processIncomingPacket(self, packet):
        if (self.__stopped):
            return
        data = self.__pHandler.readPacket(packet)
        if (data["packet_type"] == PACKET_T.VM_SERVERS_STATUS_DATA):
            self.__writer.processVMServerSegment(data["Segment"],
                                                 data["SequenceSize"],
                                                 data["Data"])
        elif (data["packet_type"] == PACKET_T.AVAILABLE_IMAGES_DATA):
            self.__writer.processImageSegment(data["Segment"],
                                              data["SequenceSize"],
                                              data["Data"])
        elif (data["packet_type"] == PACKET_T.VM_SERVER_BOOTUP_ERROR):
            self.__callback.handleVMServerBootUpError(
                data["ServerNameOrIPAddress"], data["ErrorMessage"])
        elif (data["packet_type"] == PACKET_T.VM_SERVER_REGISTRATION_ERROR):
            self.__callback.handleVMServerRegistrationError(
                data["ServerNameOrIPAddress"], data["ErrorMessage"])
        elif (data["packet_type"] == PACKET_T.VM_BOOT_FAILURE):
            self.__callback.handleVMBootFailure(data["VMName"], data["UserID"],
                                                data["ErrorMessage"])
        elif (data["packet_type"] == PACKET_T.VM_CONNECTION_DATA):
            self.__callback.handleVMConnectionData(data["UserID"],
                                                   data["VNCServerIPAddress"],
                                                   data["VNCServerPort"],
                                                   data["VNCServerPassword"])

    def _sendUpdateRequestPackets(self):
        if (self.__stopped):
            return
        # Send some update request packets to the main server
        p = self.__pHandler.createDataRequestPacket(
            PACKET_T.QUERY_VM_SERVERS_STATUS)
        self.__manager.sendPacket(self.__mainServerPort, p)
        p = self.__pHandler.createDataRequestPacket(
            PACKET_T.QUERY_AVAILABLE_IMAGES)
        self.__manager.sendPacket(self.__mainServerPort, p)