-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcollector.py
48 lines (42 loc) · 1.55 KB
/
collector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from configer import config_gen
from nornir import InitNornir
from nornir_scrapli.tasks import (
get_prompt,
send_command,
send_commands,
send_configs
)
from nornir_utils.plugins.functions import print_result
from nornir.core.task import Task, Result
import logging
from nornir_scrapli.functions import print_structured_result
# def config_checker():
# config_gen()
def get_inv_details(task):
response = task.run(task=send_command,
command='show interfaces', severity_level=logging.DEBUG)
int_results = response.scrapli_response.textfsm_parse_output()
ver_response = task.run(
task=send_command, command='show version', severity_level=logging.DEBUG)
ver_results = ver_response.scrapli_response.textfsm_parse_output()
results = {}
results['hostname'] = ver_results[0]['hostname']
results['platform'] = ver_results[0]['rommon']
results['serial'] = ver_results[0]['serial'][0]
results['interfaces'] = []
for int in int_results:
interface = {}
interface['name'] = int['interface']
interface['mac'] = int['bia']
interface['ip'] = int['ip_address']
interface['media'] = int['media_type']
interface['active'] = int['link_status']
results['interfaces'].append(interface)
return results
if __name__ == "__main__":
response = input("Do you want to gen a config first? (y/N): ")
if response == "y":
config_gen()
nr = InitNornir(config_file="config.yaml")
results = nr.run(task=get_inv_details)
print_result(results)