Beispiel #1
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")
Beispiel #2
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")
Beispiel #3
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")
Beispiel #4
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")
Beispiel #5
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")