-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnornir_inventory.py
36 lines (31 loc) · 1.15 KB
/
nornir_inventory.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
#!/usr/bin/env python
"""
Author: Denis Pointer
Purpose: A framework for a custom Nornir Inventory Plugin
"""
from nornir.core.deserializer.inventory import Inventory
import yaml
class MyInventory(Inventory):
def __init__(self, **kwargs):
# TODO write the code...
# code to get the data
secrets_file = kwargs.pop("secrets_file", "secrets.yaml")
with open(secrets_file) as f:
secrets = yaml.safe_load(f)
hosts = {
"R1": {"hostname": "192.168.122.121", "data": {"site": "GNS3"}},
"R2": {"hostname": "192.168.122.193", "data": {"site": "GNS3"}},
"R3": {"hostname": "192.168.122.191", "data": {"site": "GNS3"}},
}
groups = {}
defaults = {
"platform": "ios",
"username": secrets["defaults"]["username"],
"password": secrets["defaults"]["password"],
}
# passing the data to the parent class so the data is
# transformed into actual Host/Group objects
# and set default data for all hosts
super().__init__(
hosts=hosts, groups=groups, defaults=defaults, **kwargs
)