コード例 #1
0
def MakeTreeDevice():

    #create list whit elements shows
    list_elements_shows = []

    #generate connection
    database = Comunication.BeginComunication()

    #get list elements fathers
    query = "SELECT serialp from conecta"
    list_serialesp = []  #generate list whit information

    serialesp = Comunication.MakeQueryDB(query, database[1])  #manage the query

    #storage list of serials
    for element in serialesp:
        list_serialesp.append(element[0])

    #delete elements repeats in list
    list_serialesp = list(set(list_serialesp))

    #for each element in list
    for element in list_serialesp:

        #check if exist in elements already show
        if ExisteInLista(list_elements_shows, element) == 0:

            list_parcial = Query.CreateTreeBySerial(element,
                                                    list_elements_shows,
                                                    '')  #create tree of device
            #append element to list show.
            Query.AddElement(list_parcial, list_elements_shows)
コード例 #2
0
def ShowElementsinDataBase(query, title):
	
	#start connection whit data base
	database = Comunication.BeginComunication()
	response = Comunication.MakeQueryDB (query, database[1])#get the response in base of query makye

	#create file for send element in response
	file_response = open("temp", 'w')
	var = "%s\n"%title
	file_response.write(var)
	#shows the results whit format ->
	for element in response:
		file_response.write("->")
		cont=0#for ask if is the first element or no
		for element_in_response in element:
			if cont < len(element)-1:
				var =  "%s;"%element_in_response
				file_response.write(var)
			else:
				file_response.write(element_in_response)
			cont+=1
		file_response.write("\n")

	#close file...
	file_response.close()

	#show file whit less option...
	os.system("less temp")
コード例 #3
0
def GetNameModel(id_model):

	query = "select nom_modelo from modelo where id_modelo = %s" % id_model

	database_elements = Comunication.BeginComunication()#init connection
	response = Comunication.MakeQueryDB(query, database_elements[1])#manage query

	return response[0][0]
コード例 #4
0
ファイル: UpdateDataBase.py プロジェクト: odbelix/mnTool
def GetSerialDevice(ip_device):

    query = "select serial from dispositivo where ip_disp = '%s'" % ip_device
    print query
    database_elements = Comunication.BeginComunication()  #init connection
    response = Comunication.MakeQueryDB(query,
                                        database_elements[1])  #manage query

    return response[0][0]
コード例 #5
0
def GenerateCSVOfTable(table, query):

	database_elements = Comunication.BeginComunication()#init connection
	response = Comunication.MakeQueryDB(query, database_elements[1])#manage query

	#create file whit information
	name_faile = "%s.csv" % table
	file_write = open(name_faile, 'w')
	WriteInFile(file_write, response)#print element in file csv format...
	file_write.close()
コード例 #6
0
def MakeQuery(query):

	#start connection whit data base
	database = Comunication.BeginComunication()
	response = Comunication.MakeQueryDB (query, database[1])#get the response in base of query makye
	#shows the results whit format ->
	for element in response:
		print "->",
		cont=0#for ask if is the first element or no
		for element_in_response in element:
			if cont < len(element)-1:
				print element_in_response, ";",
			else:
				print element_in_response
			cont+=1
		print 
コード例 #7
0
ファイル: UpdateDataBase.py プロジェクト: odbelix/mnTool
def UpdateModelDevice(
        model_device,
        serial):  #Falta el id de la marca y del tipo de dispositivo!!!

    #evaluate if exists the model in data base...
    query = "select * from modelo where nom_modelo = '%s'" % model_device
    if Query.ExistElementInDB(query) == 0:  #exists in db...

        #get the id of model
        query = "select id_modelo from modelo where nom_modelo = '%s'" % model_device
        database_elements = Comunication.BeginComunication()  #init connection
        response = Comunication.MakeQueryDB(
            query, database_elements[1])  #manage query

        #update the id of model device...
        query = "update dispositivo set id_modelo = %d where serial = '%s'" % (
            int(response[0][0]), serial)
        Query.UpdateDBWithOutMessage(query)
    else:  #the model device not exist in data base...

        #insert model in data base...
        id_model = Query.GetMaxIDinTable(
            'modelo',
            'id_modelo')  #falta agregar el tipo de dispositivo y la marca...
        if id_model == None:
            id_model = 0
            query = "insert into modelo values (%d, %d, %d, '%s')" % (
                id_model, 0, 0, model_device)
            Query.InsertDBWithOutMessage(query)

            query = "update dispositivo set id_modelo = %d where serial = '%s'" % (
                id_model, serial)
            Query.UpdateDBWithOutMessage(query)
        else:
            id_model += 1
            query = "insert into modelo values (%d, %d, %d, '%s')" % (
                id_model, 0, 0, model_device)
            Query.InsertDBWithOutMessage(query)

            query = "update dispositivo set id_modelo = %d where serial = '%s'" % (
                id_model, serial)
            Query.UpdateDBWithOutMessage(query)
コード例 #8
0
def MakeTree():

    #establecemos la comunicacion
    database = Comunication.BeginComunication()

    #obtenemos en una lista aparte la informacion de los niveles...
    query = "SELECT * FROM nivel"
    niveles = Comunication.MakeQueryDB(query,
                                       database[1])  #gestionamos la consulta

    #creamos una consulta...
    query = "SELECT * FROM campus"

    info_campus = Comunication.MakeQueryDB(
        query, database[1])  #gestionamos la consulta

    for element in info_campus:

        #No mostrare los campus si no tienen edificios...
        #se obtiene la informacion de los edificios...
        query = "SELECT * FROM edificio where id_campus = %d" % element[0]

        if Query.ExistElementInDB(query) == 0:
            info_edificios = Comunication.MakeQueryDB(
                query, database[1])  #gestionamos la consulta
            print "├─Campus: %s" % element[1]
            for edificios in info_edificios:

                #no mostrare los edificios si no tiene racks asociados
                query = "select * from edificio join rack on (edificio.id_edif = rack.id_edif) where edificio.id_edif=%d" % int(
                    edificios[0])
                if Query.ExistElementInDB(query) == 0:
                    print "│    ├─Edificio: '%s'" % edificios[2]
                    #por cada nivel del edificio obtenemos los rack...
                    for nivel in niveles:
                        query = "select * from rack join edificio on (rack.id_edif = edificio.id_edif) join nivel on (nivel.id_nivel = rack.id_nivel) where rack.id_nivel = %d AND rack.id_edif = %d" % (
                            nivel[0], edificios[0])
                        #evaluamos si el edificio tiene los niveles indicados...
                        if Query.ExistElementInDB(query) == 0:
                            racks_niveles = Comunication.MakeQueryDB(
                                query, database[1])
                            print "│    │    ├─Nivel : ", nivel[1]
                            for rack in racks_niveles:  #informacion de los rack
                                print "│    │    │    ├─Rack: ", rack[3]
                                #por cada rack obtenemos la informacion de los dispositivos existentes en el...
                                query = "select dispositivo.serial, dispositivo.nom_disp, dispositivo.ip_disp, modelo.nom_modelo, tipo_disp.nom_tipo_disp, marca.nom_marca from dispositivo join rack on (rack.id_rack = dispositivo.id_rack) join modelo on (dispositivo.id_modelo = modelo.id_modelo) join tipo_disp on (tipo_disp.id_tipo_disp = modelo.id_tipo_disp) join marca on (marca.id_marca = modelo.id_marca) where dispositivo.id_rack= %d" % rack[
                                    0]
                                dispositivo_rack = Comunication.MakeQueryDB(
                                    query, database[1])
                                #evaluamos aquellos que son papas y con ellos formamos el arbol
                                dispositivo_rack_papa = []
                                for dispositivo in dispositivo_rack:
                                    if Query.IsPapa(dispositivo[0]) == 1:
                                        dispositivo_rack_papa.append(
                                            dispositivo[0])
                                #ahora hacemos el arbol en base a la lista obtenida...
                                #creamos una lista con los elementos que ya han sido buscados...
                                list_elements_shows = []
                                #recorremos la lista de seriales que son papas...
                                for element in dispositivo_rack_papa:
                                    #evaluamos si ya mostramos a el y sus hijos...
                                    if MakeTreeDispositivos.ExisteInLista(
                                            list_elements_shows, element) == 0:
                                        list_parcial = Query.CreateTreeBySerial(
                                            element, list_elements_shows,
                                            '│    │    │    │    '
                                        )  #creamos el arbol para ese dispositivo...
                                        #agregamos los elementos a la lista de elementos mostrados...
                                        Query.AddElement(
                                            list_parcial, list_elements_shows)
    return 0