def send_config_commands(device, config_commands, verbose=True): if verbose: print('Подключаюсь к {}...\n'.format(device['ip'])) with co(**device) as ssh: ssh.enable() res = ssh.send_config_set(config_commands) return res
def send_commands(device, show=False, config=False): print('Подключение к устройству {}\n'.format(device['ip'])) with co(**device) as ssh: ssh.enable() if show == False: res = ssh.send_config_set(config) else: res = ssh.send_command(show) return res
def send_show_command (device, command): try: print ('Подключение к устройству {}\n'.format(device['ip'])) with co(**device) as ssh: ssh.enable() res=ssh.send_command(command) except (netmiko.ssh_exception.NetMikoAuthenticationException,netmiko.ssh_exception.NetMikoTimeoutException) as e: print('Error: {}'.format(e)) return'\n' else: return res
def send_config_commands (device, config_commands, verbose=True): g,b={},{} if verbose: print ('Подключаюсь к {}...\n'.format(device['ip'])) with co(**device) as ssh: reg = re.compile(r'(Ambiguous|Invalid|Incomplete).+') ssh.enable() ssh.config_mode() for com in config_commands: res=ssh.send_command(com, strip_prompt=False, strip_command=False) match=reg.search(res) if (match): print('Команда "{}" выполнилась с ошибкой "{}" на устройстве {}'.format(com,match.group(),device['ip'])) b[com]=res else: g[com]=res ssh.exit_config_mode() return (g,b)
def send_config_commands(device, config_commands): print('Подключение к устройству {}\n'.format(device['ip'])) with co(**device) as ssh: ssh.enable() res = ssh.send_config_set(config_commands) return res