Beispiel #1
0
 def initDeviceListFromDB(self, sqlMana=None):
     sql = 'select ID from device where roomID = %d' % self.ID
     res = sqlMana.query(sql)
     for temp in res:
         tempDevice = device()
         tempDevice.readInfoFromDB(temp.get('ID'), sqlMana)
         self.deviceList.append(tempDevice)
Beispiel #2
0
def add2list(pkt):
    stre = -(256-ord(pkt.notdecoded[-4]))
    dev_found = False
    for dev in device_list:
        if pkt.addr2 == dev.mac_addr:
            dev.update(stre,get_current_minute(), get_current_time())
            dev_found = True
            break
    if not dev_found:
        device_list.append(device(stre, get_current_minute(), get_current_time(), pkt.addr2))
Beispiel #3
0
def add2list(pkt):
    stre = -(256 - ord(pkt.notdecoded[-4]))
    dev_found = False
    for dev in device_list:
        if pkt.addr2 == dev.mac_addr:
            dev.update(stre, get_current_minute(), get_current_time())
            dev_found = True
            break
    if not dev_found:
        device_list.append(
            device(stre, get_current_minute(), get_current_time(), pkt.addr2))
Beispiel #4
0
async def run_client(request, user, password):
    """

    :param request: Equipamento que será realizado a conexão
    :param user: Login
    :param password: Senha
    :return: Se todas as condições forem aceitas, será retornado OK.
    """
    date_time = strftime("%d%m%Y", time.localtime())
   
    if (request[0:3] == 'LDA' or request[0:3] == 'APS'):
        directory = '/home/***/Backup/BACKUP_'+date_time+'/'+request[0:6]+'_'+ date_time+'/'
        path = os.path.exists(directory)
    if request[0:3] == 'APU' or request[0:3] == 'CAB' or request[0:3] == 'RLA':
        directory = '/home/***/Backup/BACKUP_'+date_time+'/'+request[0:3]+'OLT_'+ date_time+'/'
        path = os.path.exists(directory)

    print(request)
    print (path)
    if path == True:

        if request[:11] =='MyHost'or request[:11] == 'MyHost': ##used paramiko connection because my equipment did not accept asyncssh
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect(devices.device(request), port=22, username=user, password=password, look_for_keys='', timeout=200 * 60)
            connection = ssh.invoke_shell()
			
            output=''
            stdout= connection.recv(64).decode(encoding='utf-8')
            outFile = open(directory + request + '_' + date_time+'.txt', "w")
            outFile.write(stdout[:])
          
            commands = devices.commands(request)
			
            for p in commands:
                connection.send(p + '\n')
                time.sleep(2)
                if p == 'Show running-config':
                    time.sleep(10)
                stdout= connection.recv(2500000).decode(encoding='utf-8')
                output_final= output_final+ stdout
               
            
			outFile = open(directory + request + '_' + date_time+'.txt', "a+")
            outFile.write(output[:]+ '\n')
            return 'ok'

        else:

            async with asyncssh.connect(devices.device(request), port=22, username=user, password=password, known_hosts=None, client_keys=None) as conn:
                process = await conn.create_process()
              
				##used to separate citys and equipments
                if request[0:3] == 'MyHost' or request[0:3] == 'MyHost' or request[0:3] == 'MyHost':
                    output_final= ''
                    output_final= await  process.stdout.readuntil(">") ##used because a huawei equipment.
                    outFile = open(directory + request + '_' + date_time+'.txt', "w")
                    commands = devices.commands(request)
                    outFile.write(output+ '\n')

                    for command_send in commands:
                        process.stdin.write(command_send + '\n')
                        await save_output(process, request, command_send)
                    return "ok"
					
                else:
                    if request[6:11] == 'MyHost' or request[6:11] == 'MyHost': ##used because a huawei equipment.
                        output_final= await  process.stdout.readuntil(">")
                        outFile = open(directory + request + '_' + date_time + '.txt', "w")
                    else:                       
                        output_final= await  process.stdout.readuntil("*") ## used to equipment cisco
                        outFile = open(directory + request + '_' + date_time + '.txt', "w")
                    
                    commands = devices.commands(request)
                    outFile.write(output_final+ '\n')

                    for command_send in commands:
                        print (command_send)
                        if command_send == 'show running-config verbose full':
                            process.stdin.write(command_send + '\n')

                            await save_output(process, request, command_send)
                        else:
                            process.stdin.write(command_send + '\n')
                            await save_output(process, request, command_send)
                    return "ok"
Beispiel #5
0
def sys_infinite(out_file,
                 pot,
                 pot_kwargs,
                 dev_kwargs,
                 prog_kwargs,
                 is_plot=True,
                 is_plot_sublat=False,
                 is_spectral=True,
                 e_params=[-0.1, 0.1, 400],
                 **kwargs):

    if dev_kwargs['is_wrap_finite']:

        out_file.prnt('\'is_wrap_finite\' cannot be True for an infinite ' + \
            'system. Setting to False\n')

        dev_kwargs['is_wrap_finite'] = False

    # Create the dev
    dev = device(pot=pot, **dev_kwargs)

    # ------------------------------------------------------------------------ #

    # Include parameters in the output file for comparison

    param_dict = {**dev.get_req_params(), **pot.get_req_params()}

    out_file.prnt_dict(param_dict, is_newline=False)

    # ------------------------------------------------------------------------ #

    # Generate leads
    lead_left = make_lead(dev, 'L', pot=pot, **dev_kwargs)
    lead_right = make_lead(dev, 'R', pot=pot, **dev_kwargs)

    if not pot.pot_params['is_const_channel']:

        smoothing_info = pot.get_pot_smoothing_info(dev.get_xyz(),
                                                    dev.get_sublat())

        for info in smoothing_info:

            out_file.prnt(info)

    if is_plot:

        # Check if we are meant to pass sublat to the plotting function
        if is_plot_sublat:
            pot.plot_pot_3D(dev.get_xyz(), dev.get_sublat())

        else:
            pot.plot_pot_3D(dev.get_xyz())

        dev.plot_interface(pot.int_loc)

        dev.plot_energies()

    param_dict = {**dev.get_req_params(), **pot.get_req_params()}

    ####                            LDOS                                ####

    energy = 0.0
    #plot_LDOS_k_average(lead_left, lead_right, dev, energy)

    ####                    SPECTRAL FUNCTION                           ####

    if is_spectral:

        str_ex = None  #'_atom_2'

        start_spectral = time.time()

        k_num, en_num, spec_data = get_spectral(out_file, lead_left,
                                                lead_right, dev,
                                                pot_kwargs['gap_val'],
                                                **prog_kwargs)

        out_file.prnt('Time to calculate spectral data : ' +
                      time_elapsed_str(time.time() - start_spectral))

        save_spectral(spec_data, dev, pot, k_num, en_num)

    out_file.prnt('Calculating transmission')

    en_list = np.linspace(*e_params)

    k_list = [0]  #np.linspace(-np.pi, np.pi, 400)

    get_transmission(out_file, lead_left, lead_right, dev, pot, en_list,
                     k_list, prog_kwargs)
Beispiel #6
0
    def initDeviceList(self):
        # print 'in initDeviceList:	', self.getType()
        # Livingroom
        if (self.roomType == 'livingRoom'):
            livingRoomTV = device(0, 'livingRoomTV', 'TV', 0, 0)
            self.deviceList.append(livingRoomTV)

            livingRoomLamp = device(1, 'livingRoomLamp', 'lamp', 0, 0)
            self.deviceList.append(livingRoomLamp)

            livingRoomDoor = device(2, 'livingRoomDoor', 'door', 0, 0)
            self.deviceList.append(livingRoomDoor)

            livingRoomWindow = device(3, 'livingRoomWindow', 'window', 0, 0)
            self.deviceList.append(livingRoomWindow)

            livingRoomComputer = device(4, 'livingRoomComputer', 'computer', 0,
                                        0)
            self.deviceList.append(livingRoomComputer)

            livingRoomCharger = device(5, 'livingRoomCharger', 'charger', 0, 0)
            self.deviceList.append(livingRoomCharger)

            livingRoomAirCondition = device(6, 'livingRoomAirCondition',
                                            'airCondition', 0, 25)
            self.deviceList.append(livingRoomAirCondition)

            livingRoomAudioSystem = device(7, 'livingRoomAudioSystem', 'other',
                                           0, 0)
            self.deviceList.append(livingRoomAudioSystem)

        # Master Bedroom
        if (self.roomType == 'masterBedroom'):
            masterBedRoomTV = device(100, 'masterBedRoomTV', 'TV', 0, 0)
            self.deviceList.append(masterBedRoomTV)

            masterBedRoomCeilingLamp = device(101, 'masterBedRoomCeilingLamp',
                                              'lamp', 0, 0)
            self.deviceList.append(masterBedRoomCeilingLamp)

            masterBedRoomBedLamp = device(102, 'masterBedRoomBedLamp', 'lamp',
                                          0, 0)
            self.deviceList.append(masterBedRoomBedLamp)

            masterBedRoomDoor = device(103, 'masterBedRoomDoor', 'door', 0, 0)
            self.deviceList.append(masterBedRoomDoor)

            masterBedRoomWindow = device(104, 'masterBedRoomWindow', 'window',
                                         0, 0)
            self.deviceList.append(masterBedRoomWindow)

            masterBedRoomAirCondition = device(105,
                                               'masterBedRoomAirCondition',
                                               'airCondition', 0, 25)
            self.deviceList.append(masterBedRoomAirCondition)

            masterBedRoomComputer = device(106, 'masterBedRoomComputer',
                                           'computer', 0, 0)
            self.deviceList.append(masterBedRoomComputer)

            masterBedRoomCharger = device(107, 'masterBedRoomCharger',
                                          'charger', 0, 0)
            self.deviceList.append(masterBedRoomCharger)

        # Second Bedroom
        if (self.roomType == 'secondBedroom'):
            secondBedRoomTV = device(200, 'secondBedRoomTV', 'TV', 0, 0)
            self.deviceList.append(secondBedRoomTV)

            secondBedRoomCeilingLamp = device(201, 'secondBedRoomCeilingLamp',
                                              'lamp', 0, 0)
            self.deviceList.append(secondBedRoomCeilingLamp)

            secondBedRoomBedLamp = device(202, 'secondBedRoomBedLamp', 'lamp',
                                          0, 0)
            self.deviceList.append(secondBedRoomBedLamp)

            secondBedRoomDoor = device(203, 'secondBedRoomDoor', 'door', 0, 0)
            self.deviceList.append(secondBedRoomDoor)

            secondBedRoomWindow = device(204, 'secondBedRoomWindow', 'window',
                                         0, 0)
            self.deviceList.append(secondBedRoomWindow)

            secondBedRoomAirCondition = device(205,
                                               'secondBedRoomAirCondition',
                                               'airCondition', 0, 25)
            self.deviceList.append(secondBedRoomAirCondition)

            secondBedRoomComputer = device(206, 'secondBedRoomComputer',
                                           'computer', 0, 0)
            self.deviceList.append(secondBedRoomComputer)

            secondBedRoomCharger = device(207, 'secondBedRoomCharger',
                                          'charger', 0, 0)
            self.deviceList.append(secondBedRoomCharger)

        # Third Bedroom
        if (self.roomType == 'thirdBedroom'):
            thirdBedRoomTV = device(300, 'thirdBedRoomTV', 'TV', 0, 0)
            self.deviceList.append(thirdBedRoomTV)

            thirdBedRoomCeilingLamp = device(301, 'thirdBedRoomCeilingLamp',
                                             'lamp', 0, 0)
            self.deviceList.append(thirdBedRoomCeilingLamp)

            thirdBedRoomBedLamp = device(302, 'thirdBedRoomBedLamp', 'lamp', 0,
                                         0)
            self.deviceList.append(thirdBedRoomBedLamp)

            thirdBedRoomDoor = device(303, 'thirdBedRoomDoor', 'door', 0, 0)
            self.deviceList.append(thirdBedRoomDoor)

            thirdBedRoomWindow = device(304, 'thirdBedRoomWindow', 'window', 0,
                                        0)
            self.deviceList.append(thirdBedRoomWindow)

            thirdBedRoomAirCondition = device(305, 'thirdBedRoomAirCondition',
                                              'airCondition', 0, 25)
            self.deviceList.append(thirdBedRoomAirCondition)

            thirdBedRoomComputer = device(306, 'thirdBedRoomComputer',
                                          'computer', 0, 0)
            self.deviceList.append(thirdBedRoomComputer)

            thirdBedRoomCharger = device(307, 'thirdBedRoomCharger', 'charger',
                                         0, 0)
            self.deviceList.append(thirdBedRoomCharger)

        # Bathroom
        if (self.roomType == 'bathroom'):
            bathroomLamp = device(400, 'bathroomLamp', 'lamp', 0, 0)
            self.deviceList.append(bathroomLamp)

            bathroomWaterHeater = device(401, 'bathroomWaterHeater', 'heater',
                                         0, 0)
            self.deviceList.append(bathroomWaterHeater)

            bathroomDoor = device(402, 'bathroomDoor', 'door', 0, 0)
            self.deviceList.append(bathroomDoor)

            bathroomWindow = device(403, 'bathroomWindow', 'window', 0, 0)
            self.deviceList.append(bathroomWindow)

            bathroomCharger = device(404, 'bathroomCharger', 'charger', 0, 0)
            self.deviceList.append(bathroomCharger)

            bathroomFan = device(405, 'bathroomFan', 'other', 0, 0)
            self.deviceList.append(bathroomFan)

        # Kitchen
        if (self.roomType == 'kitchen'):
            kitchenLamp = device(500, 'kitchenLamp', 'lamp', 0, 0)
            self.deviceList.append(kitchenLamp)

            kitchenDoor = device(501, 'kitchenDoor', 'door', 0, 0)
            self.deviceList.append(kitchenDoor)

            kitchenWindow = device(502, 'kitchenWindow', 'window', 0, 0)
            self.deviceList.append(kitchenWindow)

            kitchenVentilator = device(503, 'kitchenVentilator', 'other', 0, 0)
            self.deviceList.append(kitchenVentilator)

        # Dining Room
        if (self.roomType == 'diningRoom'):
            diningRoomLamp = device(600, 'diningRoomLamp', 'lamp', 0, 0)
            self.deviceList.append(diningRoomLamp)

            diningRoomDoor = device(601, 'diningRoomDoor', 'door', 0, 0)
            self.deviceList.append(diningRoomDoor)

            diningRoomFan = device(602, 'diningRoomFan', 'other', 0, 0)
            self.deviceList.append(diningRoomFan)

            diningRoomWindow = device(603, 'diningRoomWindow', 'window', 0, 0)
            self.deviceList.append(diningRoomWindow)

            diningRoomAirCondition = device(604, 'diningRoomAirCondition',
                                            'airCondition', 0, 0)
            self.deviceList.append(diningRoomAirCondition)

        # Study Room
        if (self.roomType == 'studyRoom'):
            studyRoomCeilingLamp = device(700, 'studyRoomCeilingLamp', 'lamp',
                                          0, 0)
            self.deviceList.append(studyRoomCeilingLamp)

            studyRoomDeskLamp = device(701, 'studyRoomDeskLamp', 'lamp', 0, 0)
            self.deviceList.append(studyRoomDeskLamp)

            studyRoomAirCondition = device(702, 'studyRoomAirCondition',
                                           'airCondition', 0, 0)
            self.deviceList.append(studyRoomAirCondition)

            studyRoomDoor = device(703, 'studyRoomDoor', 'door', 0, 0)
            self.deviceList.append(studyRoomDoor)

            studyRoomWindow = device(704, 'studyRoomWindow', 'window', 0, 0)
            self.deviceList.append(studyRoomWindow)

            studyRoomComputer = device(705, 'studyRoomComputer', 'computer', 0,
                                       0)
            self.deviceList.append(studyRoomComputer)

            studyRoomCharger = device(706, 'studyRoomCharger', 'charger', 0, 0)
            self.deviceList.append(studyRoomCharger)

            studyRoomAudioSystem = device(707, 'studyRoomAudioSystem', 'other',
                                          0, 0)
            self.deviceList.append(studyRoomAudioSystem)

        self.setDevicesPosRandom()
Beispiel #7
0
async def run_client(request, user, password):
    date_time = strftime("%d%m%Y", time.localtime())
    if (request[0:3] == 'LDA' or request[0:3] == 'APS'):
        dir = '/home/data/Backup/BACKUP_' + date_time + '/' + request[
            0:6] + '_' + date_time + '/'
        path = os.path.exists(dir)
    if request[0:3] == 'APU' or request[0:3] == 'CAB' or request[0:3] == 'RLA':
        dir = '/home/data/Backup/BACKUP_' + date_time + '/' + request[
            0:3] + 'OLT_' + date_time + '/'
        path = os.path.exists(dir)

    if path == True:

        if request[:11] == 'APSDTCRTD01' or request[:11] == 'LDADTCCMT06':
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect(devices.device(request),
                        port=22,
                        username=user,
                        password=password,
                        look_for_keys='',
                        timeout=200 * 60)
            connection = ssh.invoke_shell()
            output = ''
            stdout = connection.recv(64).decode(encoding='utf-8')
            outFile = open(dir + request + '_' + date_time + '.txt', "w")
            outFile.write(stdout[:])

            comandos = devices.comandos(request)
            for p in comandos:
                connection.send(p + '\n')
                time.sleep(2)
                if p == 'Show running-config':
                    time.sleep(10)
                stdout = connection.recv(2500000).decode(encoding='utf-8')
                output = output + stdout
                print(output[:])
            outFile = open(dir + request + '_' + date_time + '.txt', "a+")
            outFile.write(output[:] + '\n')
            return 'ok'
        else:

            async with asyncssh.connect(devices.device(request),
                                        port=22,
                                        username=user,
                                        password=password,
                                        known_hosts=None,
                                        client_keys=None) as conn:
                process = await conn.create_process()
                print("passei")
                if request[0:3] == 'APU' or request[0:3] == 'CAB' or request[
                        0:3] == 'RLA':
                    output = ''
                    output = await process.stdout.readuntil(">")
                    outFile = open(dir + request + '_' + date_time + '.txt',
                                   "w")
                    comandos = devices.comandos(request)
                    outFile.write(output + '\n')

                    for cmd in comandos:
                        process.stdin.write(cmd + '\n')
                        await save_output(process, request, cmd)
                    return "ok"
                else:
                    if request[6:11] == 'RTD03' or request[6:11] == 'RTD04':
                        output = await process.stdout.readuntil(">")
                        outFile = open(
                            dir + request + '_' + date_time + '.txt', "w")
                    elif request[6:11] == 'CMT06':

                        output = await process.stdout.readuntil(request)
                        outFile = open(
                            dir + request + '_' + date_time + '.txt', "w")
                    else:

                        output = await process.stdout.readuntil("*")
                        outFile = open(
                            dir + request + '_' + date_time + '.txt', "w")

                    comandos = devices.comandos(request)
                    outFile.write(output + '\n')

                    for cmd in comandos:
                        print(cmd)
                        if cmd == 'show running-config verbose full':
                            process.stdin.write(cmd + '\n')

                            await save_output(process, request, cmd)
                        else:
                            process.stdin.write(cmd + '\n')
                            await save_output(process, request, cmd)
                    return "ok"
    else:
        return "Pasta não está criada!."