def connect_dslam(host, default=False): #Создание объекта dslam ip = host[0] model = host[1] if model == '5600': try: if default: dslam = DslamHuawei.DslamHuawei5600(ip, Settings.login_5600, Settings.password_5600, 20) else: dslam = DslamHuawei.DslamHuawei5600(ip, Settings.login, Settings.password, 20) except: return None elif model == '5616': try: if default: dslam = DslamHuawei.DslamHuawei5616(ip, Settings.login_5616, Settings.password_5616, 20) else: dslam = DslamHuawei.DslamHuawei5616(ip, Settings.login, Settings.password, 20) except: return None else: return None return dslam
def connect_dslam(host): #Создание объекта dslam ip = host[0] model = host[1] for i in range(1, 4): if model == '5600': try: dslam = DslamHuawei.DslamHuawei5600(ip, Settings.login_5600, Settings.password_5600, 20) except: if i == 3: return None else: time.sleep(60) continue elif model == '5616': try: dslam = DslamHuawei.DslamHuawei5616(ip, Settings.login_5616, Settings.password_5616, 20) except: if i == 3: return None else: time.sleep(60) continue else: return None break return dslam
def connect_dslam(host): #Создание объекта dslam ip = host[0] model = host[1] for i in range(1, 4): print('Попытка подключения к {} №{}'.format(ip, i)) if model == '5600': try: dslam = DslamHuawei.DslamHuawei5600(ip, Settings.login_5600, Settings.password_5600, 20) except: print('Не удалось подключиться к {}'.format(ip)) if i == 3: return None else: time.sleep(60) continue elif model == '5616': try: dslam = DslamHuawei.DslamHuawei5616(ip, Settings.login_5616, Settings.password_5616, 20) except: print('Не удалось подключиться к {}'.format(ip)) if i == 3: return None else: time.sleep(60) continue else: print('Не знакомый тип DSLAM {}'.format(ip)) return None break return dslam
def connect_dslam(host): # # Создание объекта dslam # ip = host[0] model = host[1] DEVNULL = os.open(os.devnull, os.O_WRONLY) response = subprocess.call('ping -c 3 {}'.format(ip), shell='True', stdout=DEVNULL, stderr=subprocess.STDOUT) if response != 0: print('{} не доступен'.format(ip)) return None if model == '5600': try: dslam = DslamHuawei.DslamHuawei5600(ip, Settings.login, Settings.password, 20) except: print('{} не удалось подключиться'.format(ip)) return None elif model == '5616': try: dslam = DslamHuawei.DslamHuawei5616(ip, Settings.login_5616, Settings.password_5616, 20) except: print('{} не удалось подключиться'.format(ip)) return None else: return None return dslam
def connect_dslam(host): ip = host[0] model = host[1] if model == '5600': dslam = DslamHuawei.DslamHuawei5600(ip, Settings.login_5600, Settings.password_5600) elif model == '5616': dslam = DslamHuawei.DslamHuawei5616(ip, Settings.login_5616, Settings.password_5616) dslam.program_profiles = {} re_string = r'^petr_(\d+)-\d+-\d+$' for profile in dslam.adsl_line_profile: work_profile = re.search( re_string, dslam.adsl_line_profile[profile]['profile_name']) if work_profile: dslam.program_profiles[int(work_profile.group(1))] = profile return dslam
command_list = [ 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 1024 32 896 name petr_1-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 2048 32 896 name petr_2-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 3072 32 896 name petr_3-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 4096 32 896 name petr_4-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 5120 32 896 name petr_5-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 6144 32 896 name petr_6-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 7168 32 896 name petr_7-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 8192 32 896 name petr_8-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 9216 32 896 name petr_9-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 10240 32 896 name petr_10-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 11264 32 896 name petr_11-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 12288 32 896 name petr_12-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 13312 32 896 name petr_13-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 14336 32 896 name petr_14-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 15360 32 896 name petr_15-1-10', 'adsl line-profile quickadd basic-para all trellis 1 bitswap 0 0 channel interleaved 6 6 adapt at-startup snr 10 0 31 8 0 31 rate 32 16384 32 896 name petr_16-1-10' ] for host in Settings.hosts: if host[1] == '5600': dslam = DslamHuawei.DslamHuawei5600(host[0], Settings.login_5600, Settings.password_5600) elif host[1] == '5616': dslam = DslamHuawei.DslamHuawei5616(host[0], Settings.login_5616, Settings.password_5616) dslam.execute_command('config', short=True) for command in command_list: out = dslam.execute_command(command) print(dslam.hostname, ': ',out) del dslam