text: # -*- coding: utf8 -*-
  '''
      ========================================================================
                                      CygnusCloud
      ========================================================================
      
      File: spanishCodesTranslator.py    
      Version: 3.0
      Description: spanish codes translator definitions
      
      Copyright 2012-13 Luis Barrios Hernández, Adrián Fernández Hernández,
          Samuel Guayerbas Martín
          
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
  '''
  from codesTranslator import CodesTranslator
  
  from clusterServer.database.clusterServerDB import SERVER_STATE_T, IMAGE_STATE_T
  from errors.codes import ERROR_DESC_T
  from clusterEndpoint.commands.commandsHandler import COMMAND_TYPE
  
  class SpanishCodesTranslator(CodesTranslator):
      """
      These objects translates the codes generated by the infrastructure into Spanish.
      """
      def processVMServerSegment(self, data):
          result = []
          for tup in data :
              tmp = list(tup)
              tmp[1] = self.__translateServerStatusCode(tmp[1])
              result.append(tuple(tmp))
          return result
      
      def processImageCopiesDistributionSegment(self, data):
          result = []
          for tup in data :
              tmp = list(tup)
              if (tmp[2] == IMAGE_STATE_T.READY) :
                  tmp[2] = "Sincronizada"
              elif (tmp[2] == IMAGE_STATE_T.EDITED) :
                  tmp[2] = "No sincronizada"
              elif (tmp[2] == IMAGE_STATE_T.DEPLOY) :
                  tmp[2] = "En despliegue"
              else:
                  tmp[2] = "Pendiente de borrado"
              result.append(tuple(tmp))
          return result           
      
      def __translateServerStatusCode(self, code):
          if (code == SERVER_STATE_T.BOOTING) :
              return "Arrancando"
          elif (code == SERVER_STATE_T.READY) :
              return "Listo"
          elif (code == SERVER_STATE_T.SHUT_DOWN):
              return "Apagado"
          elif (code == SERVER_STATE_T.RECONNECTING):
              return "Reestableciendo conexión"
          else :
              return "Apagado - Fallo de conexión"         
      
      def translateRepositoryStatusCode(self, code): 
          return self.__translateServerStatusCode(code)
      
      def translateErrorDescriptionCode(self, code):
          if (code == ERROR_DESC_T.IR_IMAGE_DELETED) :
              return "La imagen ya ha sido borrada del repositorio"
          elif (code == ERROR_DESC_T.IR_UNKNOWN_IMAGE) :
              return "La imagen no existe en el repositorio"
          elif (code == ERROR_DESC_T.IR_IMAGE_EDITED or code == ERROR_DESC_T.VMSRVR_LOCKED_IMAGE) :
              return "Otro usuario está editando la imagen"
          elif (code == ERROR_DESC_T.IR_NOT_EDITED_IMAGE or code == ERROR_DESC_T.CLSRVR_NOT_EDITED_IMAGE) :
              return "La imagen no se está editando. No se puede sobreescribir la copia del repositorio"
          elif (code == ERROR_DESC_T.VMSRVR_INTERNAL_ERROR) :
              return "Error interno del servidor de máquinas virtuales"
          elif (code == ERROR_DESC_T.VMSRVR_UNKNOWN_IMAGE or code == ERROR_DESC_T.CLSRVR_UNKNOWN_IMAGE) :
              return "Imagen desconocida"
          elif (code == ERROR_DESC_T.VMSRVR_COMPRESSION_ERROR) :
              return "Error al comprimir o descomprimir la imagen"
          elif (code == ERROR_DESC_T.VMSRVR_IR_CONNECTION_ERROR or code == ERROR_DESC_T.CLSRVR_IR_CONNECTION_ERROR) :
              return "No se puede establecer la conexión con el repositorio"
          elif (code == ERROR_DESC_T.VMSRVR_RETR_TRANSFER_ERROR) :
              return "Error al realizar la transferencia FTP RETR"
          elif (code == ERROR_DESC_T.VMSRVR_STOR_TRANSFER_ERROR) :
              return "Error al realizar la transferencia FTP STOR"
          elif (code == ERROR_DESC_T.CLSRVR_AUTODEPLOYED):
              return "El despliegue automático de la imagen ya ha comenzado"
          elif (code == ERROR_DESC_T.CLSRVR_AUTOD_TOO_MANY_INSTANCES):
              return "Demasiadas instancias a desplegar"
          elif (code == ERROR_DESC_T.CLSRVR_LOCKED_IMAGE):
              return "La imagen se está editando"
          elif (code == ERROR_DESC_T.CLSRVR_DELETED_IMAGE):
              return "La imagen se está borrando"
          elif (code == ERROR_DESC_T.CLSRVR_IR_NO_DISK_SPACE) :
              return "No hay suficiente espacio en disco en el repositorio"   
          elif (code == ERROR_DESC_T.CLSRVR_VMSRVR_NOT_READY) :
              return "No hay servidores de máquinas virtuales preparados"    
          elif (code == ERROR_DESC_T.CLSRVR_IMAGE_HOSTED_ON_VMSRVR) :
              return "La imagen ya está desplegada en el servidor de máquinas virtuales"   
          elif (code == ERROR_DESC_T.CLSRVR_IMAGE_NOT_HOSTED_ON_VMSRVR) :
              return "La imagen no está desplegada en el servidor de máquinas virtuales"   
          elif (code == ERROR_DESC_T.CLSRVR_VMSRVR_NO_DISK_SPACE) :
              return "No hay suficiente espacio en disco en el servidor de máquinas virtuales"   
          elif (code == ERROR_DESC_T.CLSRVR_UNKNOWN_VMSRVR):
              return "El servidor de máquinas virtuales no está registrado"
          elif (code == ERROR_DESC_T.CLSRVR_VMSRVR_CONNECTION_ERROR) :
              return "No se puede establecer la conexión con el servidor de máquinas virtuales"   
          elif (code == ERROR_DESC_T.CLSRVR_VMSRVR_CONNECTION_LOST) :
              return "Se ha perdido la conexión con el servidor de máquinas virtuales"   
          elif (code == ERROR_DESC_T.CLSRVR_DOMAIN_NOT_REGISTERED) :
              return "La máquina virtual no está registrada"   
          elif (code == ERROR_DESC_T.CLSRVR_ACTIVE_VMSRVR) :
              return "El servidor de máquinas virtuales está activo"   
          elif (code == ERROR_DESC_T.CLSRVR_VMSRVR_IDS_IN_USE) :
              return "La IP o el puerto especificados están en uso"   
          elif (code == ERROR_DESC_T.CLSRVR_AUTOD_ERROR) :
              return "El despliegue automático ha fallado en algunos servidores de máquinas virtuales"   
          elif (code == ERROR_DESC_T.CLSRVR_VM_BOOT_TIMEOUT) :
              return "La máquina virtual no se puede arrancar (timeout)"   
          elif (code == ERROR_DESC_T.CLSRVR_IMAGE_NOT_AVAILABLE) :
              return "La máquina virtual no se puede arrancar (no hay servidores disponibles)"   
          elif (code == ERROR_DESC_T.CLSRVR_NO_EDITION_SRVRS) :
              return "No hay servidores en los que editar la imagen"   
          elif (code == ERROR_DESC_T.CLSRVR_NO_CANDIDATE_SRVRS) :
              return "No hay servidores en los que desplegar la imagen"         
          elif (code == ERROR_DESC_T.CLSRVR_EDITION_VMSRVRS_UNDER_FULL_LOAD) :
              return "Los servidores de edición no admiten más peticiones"       
          elif (code == ERROR_DESC_T.CLSRVR_EDITION_VMSRVRS_UNDER_FULL_LOAD) :
              return "Los servidores de máquinas virtuales no admiten más peticiones"
          
      def translateNotificationCode(self, code):
          if (code == COMMAND_TYPE.DEPLOY_IMAGE or code == COMMAND_TYPE.AUTO_DEPLOY_IMAGE) :
              return "La imagen ha terminado de desplegarse"
          elif (code == COMMAND_TYPE.DELETE_IMAGE) :
              return "La imagen se ha borrado del servidor"
          elif (code == COMMAND_TYPE.CREATE_IMAGE) :
              return "La creación de la imagen ha terminado"
          elif (code == COMMAND_TYPE.EDIT_IMAGE):
              return "La edición de la imagen ha terminado"
          elif (code == COMMAND_TYPE.DELETE_IMAGE_FROM_INFRASTRUCTURE):
              return "La imagen se ha borrado de la infraestructura"