Beispiel #1
0
def reboot(ssh):
    '''
         :param ssh: Recibe una conexión SSH al o los dispositivos que se desean reiniciar.
         :return:
    '''

    print("El dispositivo se reiniciará a las: ")
    time_string = tiempo(ssh)
    print(time_string)  #Hora en la cual el dispositivo se reiniciará
    stdin, stdout1, stderr = ssh.exec_command(
        '/system script remove [/system script find]'
    )  #Elimina todos los scripts
    stdin, stdout2, stderr = ssh.exec_command(
        '/system scheduler remove [/system scheduler find]'
    )  #Elimina todos los planificadores del dispositivo
    stdout = stdout2.readlines()
    print(stdout)
    print(time_string)
    '''
        Se crea el script y el planificador de tal forma que se reinicia el dispositivo
    '''
    stdin, stdout3, stderr = ssh.exec_command(
        '/system script add name="reinicio" source="/system reboot"')  #
    stdin, stdout4, stderr = ssh.exec_command(
        '/system scheduler add name=reinicio start-time=' + time_string +
        ' on-event=reinicio')  #
    stdout = stdout4.readlines()

    print(stdout)
    print("Reiniciando...")
    ssh.close()
Beispiel #2
0
def un_transborde(viaje):
	for linea2 in viaje.ls2:
		l2 = datos.obtener_linea(linea2)
		for linea1 in viaje.ls1:
			l1 = datos.obtener_linea(linea1)
			for estacion in l2:
				if estacion[2] != None and linea1 in estacion[2]:
					viaje.time = tiempo.tiempo(viaje.e1, estacion[0], datos.obtener_linea(linea1))
					viaje.time = viaje.time + tiempo.tiempo(viaje.e2, estacion[0], l2)
					viaje.time = viaje.time + tiempo.tiempo_transborde(estacion[0])
					viaje.pasos.append([viaje.time, viaje.e1, linea1, estacion[0], linea2, viaje.e2])

	if len(viaje.pasos) >= 1:
		viaje.time, viaje.pasos = mejores_opciones(viaje.pasos)
		viaje.pasos = acomodar_opciones(viaje.pasos, 4)
		return True, viaje

	return False, viaje
Beispiel #3
0
def misma_linea(viaje):
	for linea in viaje.ls1:
		if linea in viaje.ls2:
			l = datos.obtener_linea(linea)
			viaje.pasos = [viaje.e1, direccion(viaje.e1, viaje.e2, l), viaje.e2]
			viaje.time = tiempo.tiempo(viaje.e1, viaje.e2, l)
			return True, viaje

	return False, viaje
Beispiel #4
0
def dos_transbordes(viaje):
	lc = []
	posibles_transbordes = []

	for linea1 in viaje.ls1:
		l1 = datos.obtener_linea(linea1)
		for linea2 in viaje.ls2:
			l2 = datos.obtener_linea(linea2)
			lc = lineas_comunes(l1, l2)
			for lineacomun in lc:
				viaje.time = 0

				#Encuentra transborde1 y mide el tiempo entre e1 y transborde1
				transb_1 = existe_transborde(linea1, lineacomun)
				if transb_1 == viaje.e1:
					continue
				viaje.time += tiempo.tiempo(viaje.e1, transb_1, l1)
				viaje.time += tiempo.tiempo_transborde(transb_1)

				#Encuentra transborde2 y mide el tiempo entre transborde1 y transborde2
				transb_2 = existe_transborde(linea2, lineacomun)
				if transb_2 == transb_1 or transb_2 == viaje.e2:
					continue
				viaje.time += tiempo.tiempo(transb_1, transb_2, datos.obtener_linea(lineacomun))
				viaje.time += tiempo.tiempo_transborde(transb_2)

				#Mide el tiempo entre transborde2 y e2
				viaje.time += tiempo.tiempo(transb_2, viaje.e2, l2)

				#Agrega los recorridos a una lista de posibles transbordes
				viaje.pasos.append([viaje.time, viaje.e1, linea1, transb_1, lineacomun, transb_2, linea2, viaje.e2])

	if len(viaje.pasos) >= 1:
		viaje.time, viaje.pasos = mejores_opciones(viaje.pasos)
		#Cambia las lineas por las direcciones en el mejor recorrido
		viaje.pasos = acomodar_opciones(viaje.pasos, 6)
		return True, viaje
				
		
	return False, viaje
Beispiel #5
0
def reboot(ssh):
    print("El dispositivo se reiniciará a las: ")
    time_string = tiempo(ssh)
    print(time_string) #Hora en la cual el dispositivo se reiniciará
    stdin, stdout1, stderr = ssh.exec_command('/system script remove [/system script find]') #Elimina todos los scripts
    stdin, stdout2, stderr = ssh.exec_command('/system scheduler remove [/system scheduler find]') #Elimina todos los planificadores del dispositivo
    stdout = stdout2.readlines()
    print(stdout)
    print(time_string)
    stdin, stdout3, stderr = ssh.exec_command('/system script add name="reinicio" source="/system reboot"') #
    stdin, stdout4, stderr = ssh.exec_command('/system scheduler add name=reinicio start-time='+time_string+' on-event=reinicio') #
    stdout = stdout4.readlines()
    #print('/system scheduler add name=reinicio start-time='+time_string+'on-event=reinicio')
    print(stdout)
    print("Reiniciando...")
Beispiel #6
0
def apagar(ssh):

    print("El dispositivo se apagará a las: ")
    time_string = tiempo(ssh)
    print(time_string)  # Hora en la cual el dispositivo se apagará
    stdin1, stdout1, stderr1 = ssh.exec_command(
        '/system script remove [/system script find]')  # Elimina todos los scripts
    stdin2, stdout2, stderr2 = ssh.exec_command(
        '/system scheduler remove [/system scheduler find]')  # Elimina todos los planificadores del dispositivo
    stdout = stdout2.readlines()
    print(stdout)
    print(time_string)
    stdin3, stdout3, stderr3 = ssh.exec_command('/system script add name="apagado" source="/system shutdown"')  #
    stdin4, stdout4, stderr4 = ssh.exec_command(
        '/system scheduler add name=apagado start-time=' + time_string + ' on-event=apagado')  #
    stdout = stdout4.readlines()
    print(stdout)
    print("Apagando...")
Beispiel #7
0
def apagar(ssh):
    '''
      :param ssh: Recibe una conexión SSH al o los dispositivos que se desean apagar.
      :return: No devuelve nada
      '''
    print("El dispositivo se apagará a las: ")
    time_string = tiempo(ssh)
    print(time_string)  # Hora en la cual el dispositivo se apagará
    stdin1, stdout1, stderr1 = ssh.exec_command(
        '/system script remove [/system script find]')  # Elimina todos los scripts
    stdin2, stdout2, stderr2 = ssh.exec_command(
        '/system scheduler remove [/system scheduler find]')  # Elimina todos los planificadores del dispositivo
    stdout = stdout2.readlines()
    print(stdout)
    print(time_string)
    stdin3, stdout3, stderr3 = ssh.exec_command('/system script add name="apagado" source="/system shutdown"')  #
    stdin4, stdout4, stderr4 = ssh.exec_command(
        '/system scheduler add name=apagado start-time=' + time_string + ' on-event=apagado')  #
    stdout = stdout4.readlines()
    print(stdout)
    print("Apagando...")
    ssh.close()