示例#1
0
 def processPacket(self, packet):
     """
     Processes a packet sent from the image repository
     Args:
         packet: the incoming packet to process
     Returns:
         Nothing
     """
     data = self.__repositoryPacketHandler.readPacket(packet)
     if (data["packet_type"] == IR_PACKET_T.RETR_REQUEST_RECVD
             or data["packet_type"] == IR_PACKET_T.STOR_REQUEST_RECVD):
         return
     elif (data["packet_type"] == IR_PACKET_T.RETR_REQUEST_ERROR
           or data["packet_type"] == IR_PACKET_T.RETR_ERROR
           or data["packet_type"] == IR_PACKET_T.STOR_REQUEST_ERROR
           or data["packet_type"] == IR_PACKET_T.STOR_ERROR):
         self.__errorDescription = data["errorDescription"]
         self.__image_not_found = True
     elif (data["packet_type"] == IR_PACKET_T.RETR_START):
         try:
             ftpClient = FTPClient()
             ftpClient.connect(self.__ftpServerIP, data['FTPServerPort'],
                               self.__ftpTimeout, data['username'],
                               data['password'])
             ftpClient.retrieveFile(data['fileName'],
                                    self.__transferDirectory,
                                    data['serverDirectory'])
             ftpClient.disconnect()
         except Exception:
             self.__errorDescription = ERROR_DESC_T.VMSRVR_FTP_RETR_TRANSFER_ERROR
     elif (data["packet_type"] == IR_PACKET_T.STOR_START):
         try:
             ftpClient = FTPClient()
             ftpClient.connect(self.__ftpServerIP, data['FTPServerPort'],
                               self.__ftpTimeout, data['username'],
                               data['password'])
             ftpClient.storeFile(self.__sourceFilePath,
                                 self.__transferDirectory,
                                 data['serverDirectory'])
             ftpClient.disconnect()
         except Exception:
             self.__errorDescription = ERROR_DESC_T.VMSRVR_FTP_RETR_TRANSFER_ERROR
     elif (data["packet_type"] == IR_PACKET_T.ADDED_IMAGE_ID):
         self.__imageID = data["addedImageID"]
     self.__operation_completed = True