예제 #1
0
def collect_info():
    """
    read inventory.yml as input information, out_templates.yml as information about textfsm templates and return dic of
    collected info
    :return:
    """
    parsed_yaml_inventory = read_yaml(path="inventory.yml")
    parsed_yaml_template = read_yaml(path="out_templates.yml")
    # pprint(parsed_yaml_template)
    connection_params = form_connection_params_from_yaml(parsed_yaml_inventory)
    # pprint(connection_params)

    # check wrong names in inventory file
    wrong_names = []
    for device_type in connection_params.keys():
        if device_type not in parsed_yaml_template.keys():
            print(
                'device type {type} does not have OUT template in out_templates.yml\nDelete it'.format(
                    type=device_type))
            wrong_names.append(device_type)
    for name in wrong_names:
        del (connection_params[name])

    total_result = {}
    for device_type, device_list in connection_params.items():
        device_count = len(device_list)
        type_result_list = collect_info_device_type(
            device_list, parsed_yaml_template[device_type], device_count, parsed_yaml_template['command_list'])
        total_result.update({device_type: type_result_list})
    return total_result
예제 #2
0
def main():
    parsed_yaml = read_yaml()
    loop = asyncio.get_event_loop()
    tasks = [
        loop.create_task(collect_outputs(device, COMMANDS_LIST))
        for device in form_connection_params_from_yaml(parsed_yaml, site=SITE_NAME)
    ]
    loop.run_until_complete(asyncio.wait(tasks))
    for task in tasks:
        print(task.result())
def main():
    start_time = time.time()

    parsed_yaml = read_yaml()
    devices_params_gen = form_connection_params_from_yaml(parsed_yaml,
                                                          site_name='sjc')

    loop = asyncio.get_event_loop()

    tasks = [
        loop.create_task(configure_device_from_netbox(device_params))
        for device_params in devices_params_gen
    ]

    loop.run_until_complete(asyncio.wait(tasks))

    # for task in tasks:
    #     print(task.result())

    print('It took {} seconds to run'.format(time.time() - start_time))
예제 #4
0
def main():
    parsed_yaml = read_yaml()
    connection_params = form_connection_params_from_yaml(parsed_yaml,
                                                         site=SITE_NAME)
    for device_result in collect_outputs(connection_params, COMMANDS_LIST):
        print(device_result)
예제 #5
0
def add_devices():
    parsed_yaml = read_yaml()
    devices_params_gen = form_connection_params_from_yaml(parsed_yaml)
    for device_params in devices_params_gen:
        add_device(**device_params)
    print("All devices have been imported")