def initConnect(self, num=2): # judge driver file is exists exists = True try: mod = __import__(self.driverFile) except Exception as e: #print repr(e) logger.error( 'device %s[%s] can not load the driver \'%s\', detail: producttype=%s and version=%s; %s' % (self.name, self.deviceid, self.driverFile, self.productType, self.version, e)) exists = False while (exists and num > 0): connect = ConnectM(self.ip, self.port, self.username, self.password, self.driverFile, num) connect.set_multi_ipaddress(self.subdevices) self.connlist.append(connect) num = num - 1
def getEsnBySpeical(self, ip, port, username, password, driverFile): # recreate connection of device esnString = None if (self.connesn == None): exists = True try: mod = __import__(self.driverFile) except Exception as e: logger.error( 'device %s[%s] can not load the driver \'%s\', detail: producttype=%s and version=%s; %s' % (self.name, self.deviceid, self.driverFile, self.productType, self.version, e)) exists = False if (exists == True): self.connesn = ConnectM(ip, port, username, password, driverFile, 1) if (self.connesn != None): self.connesn.closeDevice() self.connesn.set_main_device(ip, port, username=username, password=password) logger.info( 'device %s[%s] getting esn , detail: ipaddress=%s, port=%s, username=%s' % (self.name, self.deviceid, ip, port, username)) try: esnString = self.connesn.get_esn() except Exception as e: logger.error( 'device %s[%s] getting esn , detail: ipaddress=%s, port=%s, username=%s, %s' % (self.name, self.deviceid, ip, port, username, e)) finally: self.connesn.closeDevice() return esnString