# -*- coding: UTF8 -*- from utils1.enums import enum from database.utils.connector import BasicDatabaseConnector SERVER_STATE_T = enum("BOOTING", "READY", "SHUT_DOWN") class MainServerDatabaseConnector(BasicDatabaseConnector): """ Nota: esta clase es ServerVMManager, con los métodos específicos de ImagesInServerManager. """ ''' These objects register and delete virtual machine servers to the database. ''' def __init__(self, sqlUser, sqlPassword, databaseName): ''' Constructor de la clase. Recibe el nombre y lla contrasennia del usuario sql encargado de gestionar la base de datos Argumentos: sqlUser: usuario para conectarnos a MySQL sqlPassword: contraseña para conectarnos a MySQL databaseName: nombre de la base de datos a la que nos vamos a conectar Devuelve: Nada ''' BasicDatabaseConnector.__init__(self, sqlUser, sqlPassword, databaseName) #=========================================================================== # No aparecen aquí:
# -*- coding: utf8 -*- ''' Main server packet handler definitions. @author: Luis Barrios Hernández @version: 1.0 ''' from utils1.enums import enum from database.mainServer.mainServerDB import SERVER_STATE_T MAIN_SERVER_PACKET_T = enum("REGISTER_VM_SERVER", "VM_SERVER_REGISTRATION_ERROR", "QUERY_VM_SERVERS_STATUS", "VM_SERVERS_STATUS_DATA", "UNREGISTER_OR_SHUTDOWN_VM_SERVER", "BOOTUP_VM_SERVER", "VM_SERVER_BOOTUP_ERROR", "QUERY_AVAILABLE_IMAGES", "AVAILABLE_IMAGES_DATA", "VM_BOOT_REQUEST", "VM_CONNECTION_DATA", "VM_BOOT_FAILURE") class MainServerPacketHandler(object): def __init__(self, networkManager): self.__packetCreator = networkManager # TODO: paquetes de arranque def createVMServerRegistrationPacket(self, IPAddress, port, name): p = self.__packetCreator.createPacket(3) p.writeInt(MAIN_SERVER_PACKET_T.REGISTER_VM_SERVER) p.writeString(IPAddress) p.writeInt(port) p.writeString(name) return p def createVMRegistrationErrorPacket(self, IPAddress, port, name, reason):
# -*- coding: utf8 -*- ''' Network connection definitions @author: Luis Barrios Hernández @version: 5.0 ''' from utils1.enums import enum from threading import BoundedSemaphore from utils1.multithreadingCounter import MultithreadingCounter # Connection status enum type CONNECTION_STATUS = enum("OPENING", "READY_WAIT", "READY", "CLOSING", "CLOSED", "ERROR") class _ConnectionStatus(object): """ A class that stores a connection's status and allows its modification in a thread-safe manner. """ def __init__(self, status): """ Initializes the status using its argument. """ self.__status = status self.__semaphore = BoundedSemaphore(1) def get(self): """ Returns the status value
# -*- coding: UTF8 -*- from utils1.enums import enum from database.utils.connector import BasicDatabaseConnector SERVER_STATE_T = enum("BOOTING", "READY", "SHUT_DOWN") class MainServerDatabaseConnector(BasicDatabaseConnector): """ Nota: esta clase es ServerVMManager, con los métodos específicos de ImagesInServerManager. """ ''' These objects register and delete virtual machine servers to the database. ''' def __init__(self, sqlUser, sqlPassword, databaseName): ''' Constructor de la clase. Recibe el nombre y lla contrasennia del usuario sql encargado de gestionar la base de datos Argumentos: sqlUser: usuario para conectarnos a MySQL sqlPassword: contraseña para conectarnos a MySQL databaseName: nombre de la base de datos a la que nos vamos a conectar Devuelve: Nada ''' BasicDatabaseConnector.__init__(self, sqlUser, sqlPassword, databaseName) #===========================================================================
# -*- coding: utf8 -*- ''' Main server packet handler definitions. @author: Luis Barrios Hernández @version: 1.0 ''' from utils1.enums import enum from database.mainServer.mainServerDB import SERVER_STATE_T MAIN_SERVER_PACKET_T = enum( "REGISTER_VM_SERVER", "VM_SERVER_REGISTRATION_ERROR", "QUERY_VM_SERVERS_STATUS", "VM_SERVERS_STATUS_DATA", "UNREGISTER_OR_SHUTDOWN_VM_SERVER", "BOOTUP_VM_SERVER", "VM_SERVER_BOOTUP_ERROR", "QUERY_AVAILABLE_IMAGES", "AVAILABLE_IMAGES_DATA", "VM_BOOT_REQUEST", "VM_CONNECTION_DATA", "VM_BOOT_FAILURE") class MainServerPacketHandler(object): def __init__(self, networkManager): self.__packetCreator = networkManager # TODO: paquetes de arranque def createVMServerRegistrationPacket(self, IPAddress, port, name): p = self.__packetCreator.createPacket(3) p.writeInt(MAIN_SERVER_PACKET_T.REGISTER_VM_SERVER) p.writeString(IPAddress) p.writeInt(port) p.writeString(name)
# -*- coding: utf8 -*- """ _Packet-related definitions @author: Luis Barrios Hernández @version: 1.6 """ from utils1.enums import enum from network.exceptions.packetException import PacketException Packet_TYPE = enum('TICK', 'TOCK', 'DATA') class _Packet(object): """ A class that stands for a packet @attention: _Packet instances MUST ONLY be created through a NetworkManager to avoid priority issues that can cause serious errors in the network subsystem. @attention: The single underscore methods are semi-private, and MUST NOT be used along the user's code. @attention: All the read operations are destructive. """ def __init__(self, packetType=Packet_TYPE.DATA, priority=10): """ Creates an empty packet with the type and priority given as arguments Args: packetType: The new packet's type priority: The new packet's priority """ self.__priority = priority
# -*- coding: utf8 -*- ''' Network connection definitions @author: Luis Barrios Hernández @version: 5.0 ''' from utils1.enums import enum from threading import BoundedSemaphore from utils1.multithreadingCounter import MultithreadingCounter # Connection status enum type CONNECTION_STATUS = enum("OPENING", "READY_WAIT", "READY", "CLOSING", "CLOSED", "ERROR") class _ConnectionStatus(object): """ A class that stores a connection's status and allows its modification in a thread-safe manner. """ def __init__(self, status): """ Initializes the status using its argument. """ self.__status = status self.__semaphore = BoundedSemaphore(1) def get(self): """ Returns the status value """ return self.__status def set(self, value):
# -*- coding: utf8 -*- """ _Packet-related definitions @author: Luis Barrios Hernández @version: 1.6 """ from utils1.enums import enum from network.exceptions.packetException import PacketException Packet_TYPE = enum('TICK', 'TOCK', 'DATA') class _Packet(object): """ A class that stands for a packet @attention: _Packet instances MUST ONLY be created through a NetworkManager to avoid priority issues that can cause serious errors in the network subsystem. @attention: The single underscore methods are semi-private, and MUST NOT be used along the user's code. @attention: All the read operations are destructive. """ def __init__(self, packetType=Packet_TYPE.DATA, priority= 10): """ Creates an empty packet with the type and priority given as arguments Args: packetType: The new packet's type priority: The new packet's priority """ self.__priority = priority self.__packetType = packetType