Skip to content

Commit db177f5

Browse files
authored
Merge pull request #217 from networktocode/dga-nautobot-doc
Update documentation for nautobot and new backend system
2 parents ca87ef0 + 290398c commit db177f5

File tree

8 files changed

+237
-69
lines changed

8 files changed

+237
-69
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The main use cases for the network importer:
1212
- [Configuration file](docs/configuration.md)
1313
- [Supported Features and Architecture](docs/architecture.md)
1414
- [Extensibility](docs/extensibility.md)
15+
- [Upgrade procedure](docs/upgrade.md)
1516

1617
## Questions
1718

docs/architecture.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
# Architecture
33

4-
Internally the network-importer is leveraging the [diffsync](https://github.com/networktocode/diffsync) library to compare the state of the network and the state of the Source of Truth. The diffsync library is designed to compare the state of 2 **adapters** based on a shared data-models.
4+
Internally the network-importer is leveraging the [diffsync](https://github.com/networktocode/diffsync) library to compare the state of the network and the state of the Source of Truth. [The diffsync library is designed to compare the state of 2 **adapters** based on a shared data-models](https://blog.networktocode.com/post/intro-to-diffing-and-syncing-data-with-diffsync/).
55

66
To communicate to the network devices, the network importer is leveraging [Nornir](https://github.com/nornir-automation/nornir) and incorporate a concept of **drivers** to easily add support for more platforms if needed.
77
By default the Network Importer supports 3 main actions to execute against the network devices:
88
- `get_config`: Retrieve the running configuration and store it in the `config_directory` folder.
9-
- `get_neighbors`: Retrieve the list of all neighbors, eiher from LLDP or CDP (based on the configuration)
9+
- `get_neighbors`: Retrieve the list of all neighbors, either from LLDP or CDP (based on the configuration)
1010
- `get_vlans`: Retrieve the list of vlans present on the device.
1111

1212
## Internal Datamodel
@@ -22,13 +22,35 @@ The internal/shared datamodel is defined in the [network_importer/models.py](../
2222

2323
> It's possible to extend the default models and add your own, please check the [extensibility section](extensibility.md) of the documentation
2424
25-
## Adapters
25+
## Backend, Adapters & Inventory
26+
27+
To operate the Network Importer needs 1 inventory and 2 adapters:
28+
- An inventory to get the list of devices to analyze and get the minimum information to connect to them (platform, address, cred
29+
entials ..)
30+
- One adapter to read the information from the network and one to read/write information to the Source of Truth backend.
31+
32+
Since the inventory is usually leveraging the SOT, the SOT adapter and the inventory are packaged into a **backend**. Both Nautobot and Netbox are supported as backend systems. When a specific backend is selected it will update both the SOT adapter and the inventory.
33+
With or without leveraging the default backends, it's possible to provide your own adapter or extend one of the default adapters.
34+
35+
> The base adapter for Network Importer is defined in [network_importer/adapters/base.py](../network_importer/adapters/base.py). The main difference with a standard diffsync adapter is that a Network Importer adapter needs to accept a NetworkImporter inventory (based on a Nornir inventory) as parameters at init time (nornir).
2636
27-
To operate the Network Importer needs 2 adapters.
37+
### Nautobot API Adapter
2838

29-
An adapter to read the information from the network and one to read/write information to Netbox via its Rest API are provided by default but it's possible to provide your own adapter or extend either or both default adapters.
39+
The Nautobot API adapter is designed to read the status of a Nautobot server over its Rest API and update Nautobot based on the status of the network.
3040

31-
> The base adapter for Network Importer is defined in [network_importer/adapters/base.py](../network_importer/adapters/base.py). The main difference with a standard diffsync adapter is that a Network Importer adapter needs to accept a nornir inventory as parameters at init time (nornir).
41+
The table below present the capabilities in term of : Read, Create, Update and Delete supported for each model by the netbox_api adapter.
42+
43+
| Model | Inherit from | Create | Read | Update | Delete |
44+
|--------------------|--------------|--------|--------|--------|--------|
45+
| NautobotSite | Site | No | Yes | No | No |
46+
| NautobotDevice | Device | No | Yes | No | No |
47+
| NautobotInterface | Interface | Yes | Yes | Yes | Yes |
48+
| NautobotIPAddress | IPAddress | Yes | Yes | Yes | Yes |
49+
| NautobotPrefix | Prefix | Yes | Yes | Yes | No |
50+
| NautobotVlan | Vlan | Yes | Yes | Yes | No |
51+
| NautobotCable | Cable | Yes | Yes | No | No |
52+
53+
> It's possible to extend the default models and add your own, please check the [extensibility section](extensibility.md) of the documentation
3254
3355
### NetBox API Adapter
3456

@@ -54,7 +76,7 @@ The Network Importer Adapter is designed to read the status of the network prima
5476

5577
## Drivers
5678

57-
The communicate with the network devices, the network importer is leveraging Nornir and support some drivers per platform to easily support more device type.
79+
The communicate with the network devices, the network-importer is leveraging Nornir and support some drivers per platform to easily support more device type.
5880

5981
Each driver, should support each of the following actions:
6082
- `get_config`: Retrieve the running configuration and store it in the `config_directory` folder.
@@ -72,7 +94,7 @@ By default, 4 drivers are available `default`, `cisco_default`, `juniper_junos`
7294
| juniper_junos | juniper_junos |
7395
| arista_eos | arista_eos |
7496

75-
> The name of the platform must match the name of the slug platform defined in NetBox for a given device
97+
> The name of the platform must match the name of the slug platform defined in the inventory for a given device
7698
7799
### Drivers available by default
78100

docs/backend/nautobot.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# Nautobot Backend
3+
4+
The Nautobot backend is composed of an inventory and a SOT adapter designed to work with Nautobot 1.0+.
5+
Both the inventory and the SOT adapter can accept some specific settings as described below.
6+
7+
## Inventory
8+
9+
### Available Settings
10+
11+
```toml
12+
[inventory.settings]
13+
14+
address = "http://localhost:8080" # Alternative Env Variable : NAUTOBOT_ADDRESS
15+
token = "113954578a441fbe487e359805cd2cb6e9c7d317" # Alternative Env Variable : NAUTOBOT_TOKEN
16+
verify_ssl = true # Alternative Env Variable : NAUTOBOT_VERIFY_SSL
17+
18+
19+
# The default method is to use the primary IP defined in Nautobot.
20+
# As an alternative it's possible to use the name of the device and provide your own FQDN.
21+
use_primary_ip = false (default: true)
22+
fqdn = "mydomain.com"
23+
24+
# Optional filter to limit the scope of the inventory, takes a comma separated string of key value pair"
25+
filter = "site=XXX,site=YYY,status=active" # Alternative Env Variable : INVENTORY_FILTER
26+
```
27+
28+
## SOT Adapter
29+
30+
### Available Settings
31+
```toml
32+
[adapters.sot_settings]
33+
# Settings for applying diffsync flags to diffsync model objects, in order to alter
34+
# the underlying sync behaviour. The model_flag is applied to any objects that have a
35+
# tag assigned within model_flag_tags. Further details on model_flags can be found
36+
# at: https://github.com/networktocode/diffsync/blob/269df51ce248beaef17d72374e96d19e6df95a13/diffsync/enum.py
37+
model_flag_tags = ["your_tag"]
38+
model_flag = 1 # flag enum int() representation
39+
```

docs/backend/netbox.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# Netbox Backend
3+
4+
The NetBox backend is composed of an inventory and a SOT adapter designed to work with NetBox 2.8+.
5+
Both the inventory and the SOT adapter can accept some specific settings as described below.
6+
7+
## Inventory
8+
9+
### Available Settings
10+
11+
```toml
12+
[inventory.settings]
13+
14+
address = "http://localhost:8080" # Alternative Env Variable : NETBOX_ADDRESS
15+
token = "113954578a441fbe487e359805cd2cb6e9c7d317" # Alternative Env Variable : NETBOX_TOKEN
16+
verify_ssl = true # Alternative Env Variable : NETBOX_VERIFY_SSL
17+
18+
19+
# The default method is to use the primary IP defined in NetBox.
20+
# As an alternative it's possible to use the name of the device and provide your own FQDN.
21+
use_primary_ip = false (default: true)
22+
fqdn = "mydomain.com"
23+
24+
# Optional filter to limit the scope of the inventory, takes a comma separated string of key value pair"
25+
filter = "site=XXX,site=YYY,status=active" # Alternative Env Variable : INVENTORY_FILTER
26+
```
27+
28+
## SOT Adapter
29+
30+
### Available Settings
31+
```toml
32+
[adapters.sot_settings]
33+
# Settings for applying diffsync flags to diffsync model objects, in order to alter
34+
# the underlying sync behaviour. The model_flag is applied to any objects that have a
35+
# tag assigned within model_flag_tags. Further details on model_flags can be found
36+
# at: https://github.com/networktocode/diffsync/blob/269df51ce248beaef17d72374e96d19e6df95a13/diffsync/enum.py
37+
model_flag_tags = ["your_tag"]
38+
model_flag = 1 # flag enum int() representation
39+
```

docs/configuration.md

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Configuration File
22

3-
By default the network importer will try to load a configuration file name `network_importer.toml`, this configuration file is not mandatory as long as the required information to connect to NetBox, Batfish and/or the network devices are provided via environment variables.
3+
By default the network importer will try to load a configuration file name `network_importer.toml`, this configuration file is not mandatory as long as the required information to connect to the SOT, Batfish and/or the network devices are provided via environment variables.
44

55
It's possible to specify which configuration file should be used in cli with the option `--config`.
66

7-
The configuration file is organized in 8 sections detailed below.
7+
The configuration file is organized in 7 sections detailed below.
88

99
## Main Section
1010

@@ -32,39 +32,35 @@ import_vlans = "config" # Valid options are ["cli", "config", "no", true
3232
import_cabling = "lldp" # Valid options are ["lldp", "cdp", "config", "no", true, false]
3333
excluded_platforms_cabling = ["cisco_asa"]
3434

35-
# Number of Nornir tasks to execute at the same tim
36-
nbr_workers= 25
35+
# Number of Nornir tasks to execute at the same time
36+
nbr_workers = 25
3737

3838
# Directory where the configuration can be find, organized in Batfish format
3939
configs_directory = "configs"
40+
41+
# Valid Backend
42+
# Only Netbox and Nautobot backend are included by default, if you want to use another backend
43+
# you must leave backend empty and define inventory.inventory_class and adapters.sot_class manually.
44+
backend = "nautobot"
4045
```
4146

42-
# NetBox Section
47+
# Inventory Section
4348

44-
The `[netbox]` section regroup all parameters to connect to NetBox and it also include an optional list of supported platforms.
49+
The `[inventory]` section regroup all parameters related to the inventory and also includes an optional list of supported platforms. network-importer supports multiple inventories, you can define your own inventory by defining `inventory_class` and each inventory can define its own list of settings which will need to be configurated under `[inventory.settings]`. The settings for the [nautobot inventory](backend/nautobot.md) and for the [netbox inventory](backend/netbox.md) are available in their respective documentation.
4550

4651
```toml
47-
[netbox]
48-
address = "http://localhost:8080" # Alternative Env Variable : NETBOX_ADDRESS
49-
token = "113954578a441fbe487e359805cd2cb6e9c7d317" # Alternative Env Variable : NETBOX_TOKEN
50-
verify_ssl = true # Alternative Env Variable : NETBOX_VERIFY_SSL
52+
[inventory]
5153

5254
# Define a list of supported platform,
5355
# if defined all devices without platform or with a different platforms will be removed from the inventory
5456
supported_platforms = [ "cisco_ios", "cisco_nxos" ]
5557

56-
# Settings for applying diffsync flags to diffsync model objects, in order to alter
57-
# the underlying sync behaviour. The model_flag is applied to any objects that have a
58-
# tag assigned within model_flag_tags. Further details on model_flags can be found
59-
# at: https://github.com/networktocode/diffsync/blob/269df51ce248beaef17d72374e96d19e6df95a13/diffsync/enum.py
60-
model_flag_tags = ["your_tag"]
61-
model_flag = 1 # flag enum int() representation
62-
```
63-
64-
65-
model_flag_tags: List[str] = list() # List of tags that defines what objects to assign the model_flag to.
66-
model_flag: Optional[DiffSyncModelFlags] # The model flag that will be applied to objects based on tag.
58+
# Configure which Inventory will be loaded by the network importer.
59+
inventory_class = "network_importer.inventory.NetboxInventory"
6760

61+
[inventory.settings]
62+
# Inventory specific settings, please refer to the documentation of each backend/inventory.
63+
```
6864

6965
## Batfish Section
7066

@@ -93,43 +89,40 @@ login = "username" # Alternative Env Variable : NETWORK_DEVICE_LOGIN
9389
password = "password" # Alternative Env Variable : NETWORK_DEVICE_PWD
9490
enable = true # Alternative Env Variable : NETWORK_DEVICE_ENABLE
9591

96-
# Connection parameters for Netmiko
97-
global_delay_factor = 5
98-
banner_timeout = 15
99-
conn_timeout = 5
100-
10192
# List of valid FQDN that can be found in the network,
10293
# The FQDNs in this list will be automatically removed from all neighbors discovered from LLDP/CDP
10394
fqdns = [ ]
104-
```
105-
106-
## Inventory Section
10795

108-
Define what method should be used to connect to the network devices.
96+
[network.netmiko_extras]
97+
# Any additional parameters for Netmiko defined in this section will be automatically configured
98+
# as part of the Nornir inventory.
10999

110-
```toml
111-
[inventory]
112-
# The default method is to use the primary IP defined in NetBox.
113-
# As an alternative it's possible to use the name of the device and provide your own FQDN.
114-
use_primary_ip = false (default: true)
115-
fqdn = "mydomain.com"
116-
117-
# Optional filter to limit the scope of the inventory, takes a comma separated string of key value pair"
118-
filter = "site=XXX,site=YYY,status=active" # Alternative Env Variable : INVENTORY_FILTER
119-
120-
# Configure what Inventory will be loaded bu the network importer.
121-
inventory_class = "network_importer.inventory.NetboxInventory"
100+
[network.napalm_extras]
101+
# Any additional parameters for Napalm defined in this section will be automatically configured
102+
# as part of the Nornir inventory.
122103
```
123104

124105
## Adapters Section
125106

126107
Configure which adapters will be loaded by the network importer.
127108
Please see the [extensibility section](extensibility.md) of the documentation for more details on how to create your own adapter.
109+
The settings for the [nautobot adapter](backend/nautobot.md) and for the [netbox adapter](backend/netbox.md) are available in their respective documentation.
128110

129111
```toml
130112
[adapters]
131113
network_class = "network_importer.adapters.network_importer.adapter.NetworkImporterAdapter"
114+
115+
132116
sot_class = "network_importer.adapters.netbox_api.adapter.NetBoxAPIAdapter"
117+
118+
[adapters.network_settings]
119+
# Network Adapter specific settings, any settings defined in this section will be passed to the Network Adapter.
120+
# The default network adapter doesn't accept additional settings, nonetheless this section remains available if you want to
121+
# customize the default Network Adapter
122+
123+
[adapters.sot_settings]
124+
# SOT Adapter specific settings, any settings defined in this section will be passed to the SOT Adapter.
125+
# Please refer to the documentation of each adapter to see what settings are required/supported.
133126
```
134127

135128
## Drivers Section

docs/extensibility.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ The extensibility principles leverages Python object extensibility. It's recomme
77
You can use [setuptools](https://python-packaging-tutorial.readthedocs.io/en/latest/setup_py.html) or [Poetry](http://blog.networktocode.com/post/upgrade-your-python-project-with-poetry/) to quickly create a new python package.
88

99
There are different ways the Network Importer can be extended depending on what you are trying to achieve:
10-
- [Add support for new device platform by extending the default drivers](#extend-the-default-drivers)
11-
- [Add support for new features buy extending the adapters](#extend-an-existing-adapter-or-provide-your-own)
12-
- [Add support for new data by extending the models](#extend-the-default-models)
10+
- [Extend the default drivers](#extend-the-default-drivers)
11+
- [Extend an existing adapter or provide your own](#extend-an-existing-adapter-or-provide-your-own)
12+
- [Extend the default inventory](#extend-the-default-inventory)
13+
- [Extend the default models](#extend-the-default-models)
1314

1415
## Extend the default drivers
1516

@@ -40,7 +41,8 @@ class NetworkImporterDriver(DefaultNetworkImporterDriver):
4041
Result: Nornir Result object with a dict as a result containing the running configuration
4142
{ "config: <running configuration> }
4243
"""
43-
pass
44+
pass
45+
4446
@staticmethod
4547
def get_neighbors(task: Task) -> Result:
4648
"""Get a list of neighbors from the device.
@@ -99,7 +101,7 @@ class MyAdapter(NetworkImporterAdapter):
99101

100102
### Create a new adapter
101103

102-
All adapters must implement the `load` method. The load method is called during the initilization process and is expected to load all the data from the remote system into the local cache, following the Models defined.
104+
All adapters must implement the `load` method. The load method is called during the initialization process and is expected to load all the data from the remote system into the local cache, following the Models defined.
103105

104106
```python
105107
from network_importer.adapters.base import BaseAdapter
@@ -120,6 +122,14 @@ network_class = "my_python_package.adapters.MyAdapter"
120122
sot_class = "my_python_package.adapters.MyOtherAdapter"
121123
```
122124

125+
## Extend the default inventory
126+
127+
It's possible to extend the default inventory or provide your own inventory.
128+
129+
A Network Importer inventory must be a valid Nornir 3.x inventory and it must be based of the NetworkImporterInventory class.
130+
131+
Once you have created your own inventory, you need to register it with Nornir in order for Nornir to successfully load it. You than need to define your inventory name in [inventory.inventory_class]
132+
123133
## Extend the default models
124134

125135
It's possible to extend the default models by creating new classes and attaching them to an adapter.

0 commit comments

Comments
 (0)