def send_and_parse_command(devices, command): result = {} attr = {'Command': command} output = send_show_command(devices, command) for ip, out in output.items(): result[ip] = parse_command_dynamic(attr, out, tmpl_dir='templates_jun') return result
def send_and_parse_command(device_params, attributes, index='index', templates='templates'): ip = device_params['ip'] output = send_show_command(device_params, attributes['Command']) parse_result = parse_command_dynamic(attributes, output[ip]) return {ip: parse_result}
def send_commands(device, show='', filename='', config=None): if show: return send_show_command(device, show) elif filename: return send_commands_from_file(device, filename) else: return send_config_commands(device, config)
def send_commands(device, show=None, config=None): if show != None and config == None: return (send_show_command(device, command)) elif config != None and show == None: return (send_config_commands(device, commands)) else: return ("Должен быть указан ОДИН аргумент - show ИЛИ config")
def send_commands(device, show=None, config=None): r = '' if show: r = send_show_command(device, show) elif config: r = send_config_commands(device, config) return r
def send_commands(device, com): #show - функция send_show_command из задания 19.1 if com == show: result = send_show_command(device, com) return result #config - функция send_config_commands из задания 19.2 elif com == config: result = send_config_commands(device, com) return result
def send_commands(device, show='', config=''): commands = [ "logging 10.255.255.1", "logging buffered 20010", "no logging console" ] command = "sh ip int br" if show: out = (send_show_command(device, command)) if config: out = (send_config_commands(device, config)) return out
def send_and_parse_command(devices, command, index='index', index_dir='templates'): attributes = {'Command': command, 'Vendor': 'cisco_ios'} result = {} show_sent = send_show_command(devices, attributes['Command']) for ip, output in show_sent.items(): parse_done = parse_command_dynamic(attributes, output) result[ip] = parse_done return result
def send_commands(device, show = False, filename = False, config = False): if show and not filename and not config: result = send_show_command(device, show) return result if config and not show and not filename: result = send_config_command(device, config) return result if filename and not show and not config: result = send_commands_from_file(device, filename) return result else: return('Band arguments assignment')
def send_commands(device, show=False, config=False): """ Function connects to device by ssh and runs commands depending on argument(show, config). :param device: dict with parameters of device :param show: calls function send_show_command from task 19.1 :param config: calls function end_config_commands from task 19.2 :return: string with results of running commands """ if show != False: result = send_show_command(device, command) if config != False: result = send_config_commands(device, commands) return result
def test_function_return_value(r1_test_connection, first_router_from_devices_yaml): """ Тест проверяет работу функции send_show_command first_router_from_devices_yaml - это первое устройство из файла devices.yaml r1_test_connection - это сессия SSH с первым устройством из файла devices.yaml Используется для проверки вывода """ correct_return_value = r1_test_connection.send_command('sh ip int br') return_value = task_19_1.send_show_command(first_router_from_devices_yaml, 'sh ip int br') assert return_value != None, "Функция ничего не возвращает" assert type(return_value) == str, "Функция должна возвращать строку" assert return_value == correct_return_value, "Функция возвращает неправильное значение"
def send_commands(device, **kwargs): if 'show' in kwargs: #если есть show выполняем функцию send_show_command из задания 19.1 # print('we need show') command = kwargs['show'] # print(command) result = send_show_command(device, command) elif 'config' in kwargs: #если есть config выполняем функцию send_config_commands из задания 19.2 # print('we have config') conf_commands = kwargs['config'] #список команд # print(conf_commands) result = send_config_commands(device, conf_commands) else: # Если нет ни show ни config print('something wrong in ' + kwargs) return result
def test_function_return_value_different_args(r1_test_connection, first_router_from_devices_yaml): """ Проверка работы функции с другими аргументами """ correct_return_value = r1_test_connection.send_command( "sh int description") return_value = task_19_1.send_show_command(first_router_from_devices_yaml, "sh int description") assert return_value != None, "Функция ничего не возвращает" assert ( type(return_value) == str ), f"По заданию функция должна возвращать строку, а возвращает {type(return_value).__name__}" assert (return_value == correct_return_value ), "Функция возвращает неправильное значение"
def test_function_return_value(r1_test_connection, first_router_from_devices_yaml): """ Тест проверяет работу функции send_show_command first_router_from_devices_yaml - это первое устройство из файла devices.yaml r1_test_connection - это сессия SSH с первым устройством из файла devices.yaml Используется для проверки вывода """ correct_return_value = r1_test_connection.send_command("sh ip int br") return_value = task_19_1.send_show_command( first_router_from_devices_yaml, "sh ip int br" ) assert return_value != None, "Функция ничего не возвращает" assert ( type(return_value) == str ), f"По заданию функция должна возвращать строку, а возвращает {type(return_value).__name__}" assert strip_empty_lines(return_value) == strip_empty_lines( correct_return_value ), "Функция возвращает неправильное значение"
def send_and_parse_command(fdev, attributes, idx, tmpl, command, verbose): USER = '******' PASSWORD = '******' print(fdev) with open('devices2.yaml', 'r') as f: y = yaml.load(f) for r in y['routers']: r['username'] = USER r['password'] = PASSWORD rrr = {} #for device in y['routers']: #r = send.send_show_command(device, command) r = send.send_show_command(fdev, command) for k in r.keys(): rr = parse.parse_command_dynamic(attributes, idx, tmpl, r[k], verbose) rrr[k] = rr return rrr
def test_function_1(device_example, device_connection): result = send_show_command(device_example, 'sh ip int br') assert device_example['host'] in result
def test_function_1(device_example, device_connection): result = send_show_command(device_example, "sh ip int br") assert device_example["host"] in result
def test_function_2(device_example, device_connection): correct_result = device_connection.send_command("sh ip int br") result = send_show_command(device_example, "sh ip int br") assert result == correct_result
def send_commands(device, show=False, config=False): if show: return send_show_command(device, show) elif config: return send_config_commands(device, config)