Exemplo n.º 1
0
def consultarSlaveRAM():
    if os.path.isfile(config.BDSlave) == True:
        try:
            slave = opJson.abrirArchivo(config.BDSlave)
            for key, atributos in slave.items():
                comando = 'curl http://' + key + ':' + str(
                    atributos['Port']) + '/ObtenerRAM'
                logger.warning('Ejecutando..' + comando)
                output = RunCLI.runCommand(comando)
                opJson.escribirJson(config.MSGSlaveStatus, key, output)
                data = opJson.abrirArchivo(config.MSGSlaveStatus)
                manageBD.modificarSlaveRAM(key, data[str(key)]['MemFree'])
                return True
        except Exception as e:
            logger.error(sys.exc_info()[1])
Exemplo n.º 2
0
def crearProyecto(proyecto='default'):
    ruta = config.VAGRANTSERVICEHOME + proyecto
    if request.method == 'POST':
        try:
            f = request.files['file']
            filename = secure_filename(f.filename)
            SLAVE = manageBD.seleccionarSlave()
            if SLAVE:
                if os.path.isdir(ruta) == False:
                    os.mkdir(ruta)
                    f.save(os.path.join(ruta, filename))
                    opJson.limpiarJson(config.MSGSlave)
                    thread1 = threading.Thread(target=opSlave.enviarVM,
                                               args=(proyecto, SLAVE['IP']))
                    thread1.start()
                    manageBD.addProyecto(proyecto, SLAVE['id'])
                    while os.stat(config.MSGSlave).st_size == 2:
                        time.sleep(5)

                    return jsonify(opJson.abrirArchivo(config.MSGSlave))

                else:
                    return jsonify("Error 400, Ya exite el proyecto")
            return jsonify("No hay host disponibles para crear el proyecto")
        except Exception as e:
            logger.error(sys.exc_info()[1])
    else:
        return jsonify("Error 400, no se adjunto VagranFile")
Exemplo n.º 3
0
def existeProyecto(llave):
    if os.path.isfile(config.BDProyectos) == True:
        data = opJson.abrirArchivo(config.BDProyectos)
        if llave in data.keys():
            return True
        else:
            return False
Exemplo n.º 4
0
def buscarSlave(llave):
    if os.path.isfile(config.BDSlave) == True:
        data = opJson.abrirArchivo(config.BDSlave)
        if llave in data.keys():
            return True
        else:
            return False
Exemplo n.º 5
0
def borrarVM(proyecto, VM):
    data = {}
    data = manageBD.getProyecto(proyecto)
    if data:
        opJson.limpiarJson(config.MSGSlave)
        thread7 = threading.Thread(target=opSlave.enviarBorrarVM,
                                   args=(proyecto, VM, data['SLAVE']))
        thread7.start()
        #        thread7.join()
        while os.stat(config.MSGSlave).st_size == 2:
            time.sleep(5)
# <PENDIENTE CREAR METODO PARA BORRAR  VM EN BD DEL MASTER      >
        while len(opJson.abrirArchivo(config.MSGSlave)) == 0:
            time.sleep(3)
        return jsonify(opJson.abrirArchivo(config.MSGSlave))
    else:
        return jsonify("Error 400, el proyecto no existe")
Exemplo n.º 6
0
def borrarProyecto(proyecto):
    data = {}
    data = manageBD.getProyecto(proyecto)
    if data:
        opJson.limpiarJson(config.MSGSlave)
        thread3 = threading.Thread(target=opSlave.enviarBorrarProyecto,
                                   args=(proyecto, data['SLAVE']))
        thread3.start()
        #        thread3.join()
        while os.stat(config.MSGSlave).st_size == 2:
            time.sleep(5)

        while len(opJson.abrirArchivo(config.MSGSlave)) == 0:
            time.sleep(3)

        manageBD.rmProyecto(proyecto, data['SLAVE'])
        ruta = config.VAGRANTSERVICEHOME + proyecto
        os.remove(ruta + "/Vagrantfile")
        os.rmdir(ruta)
        return jsonify(opJson.abrirArchivo(config.MSGSlave))
    else:
        return jsonify("Error 400, el proyecto no existe")
Exemplo n.º 7
0
def seleccionarSlave():
    slave = {}
    memoria = 0
    Proyectos = 0
    if os.path.isfile(config.BDSlave) == True:
        data = opJson.abrirArchivo(config.BDSlave)
        for key, estructura in data.items():
            if estructura and 'MemLibre' in estructura.keys():
                if estructura['MemLibre'] > memoria:
                    memoria = estructura['MemLibre']
                    slave = {"id": key, "IP": estructura['IP']}
        return slave
    return slave
Exemplo n.º 8
0
def preguntarEstadoProyecto(proyecto,slave):
    comando="curl http://" + slave + ":" + config.SLAVE1PORT + "/StatusProyecto/" + proyecto
    logger.warning('Ingresando a preguntarEstadoProyecto')
    try:
        logger.warning('Ejecutando..' + comando)
        output=RunCLI.runCommand(comando)
        opJson.escribirJson(config.MSGSlave,proyecto,output) 
        #del mensaje del slave se saca la info del estado de cada virtual
        data=opJson.abrirArchivo(config.MSGSlave)
        if proyecto in data:
            for VM,atributo in data[proyecto][0]["VMs"].items():
                manageBD.modificarVM(proyecto,VM,"",atributo["Status"])
    except Exception as e:
        logger.error(sys.exc_info()[1])
Exemplo n.º 9
0
def estadoProyecto(proyecto):
    data = {}
    data = manageBD.getProyecto(proyecto)
    #    if manageBD.buscarProyecto(proyecto)==True:
    if data:
        opJson.limpiarJson(config.MSGSlave)
        thread2 = threading.Thread(target=opSlave.preguntarEstadoProyecto,
                                   args=(proyecto, data['SLAVE']))
        thread2.start()
        #        thread2.join()
        while os.stat(config.MSGSlave).st_size == 2:
            time.sleep(3)
        while len(opJson.abrirArchivo(config.MSGSlave)) == 0:
            time.sleep(3)

        return jsonify(manageBD.getProyecto(proyecto))
#        return jsonify(opJson.abrirArchivo(config.MSGSlave))
    else:
        return jsonify("Error 400, el proyecto no existe")
Exemplo n.º 10
0
def apagarVM(proyecto, VM):
    data = {}
    opSlave.consultarSlaveRAM()
    data = manageBD.getProyecto(proyecto)

    if data:
        SLAVE = manageBD.buscarSlave(data['SLAVE'])
        opJson.limpiarJson(config.MSGSlave)
        thread6 = threading.Thread(target=opSlave.enviarApagarVM,
                                   args=(proyecto, VM, data['SLAVE'],
                                         SLAVE['Port']))
        thread6.start()
        #        thread6.join()
        while os.stat(config.MSGSlave).st_size == 2:
            time.sleep(5)
# <PENDIENTE CREAR METODO PARA CAMBIAR ESTADO VM EN BD DEL MASTER      >
        return jsonify(opJson.abrirArchivo(config.MSGSlave))
    else:
        return jsonify("Error 400, el proyecto no existe")