From 6b45a57bea7ab506a204a2822ba04fcbe3e2ebc0 Mon Sep 17 00:00:00 2001 From: Leonardo Parente <23251360+leoparente@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:42:34 -0300 Subject: [PATCH 1/3] fix: remove vlan and hardcoded interface type --- diode-napalm-agent/README.md | 15 ++++++++++++++- diode-napalm-agent/diode_napalm/cli/cli.py | 1 - diode-napalm-agent/diode_napalm/client.py | 1 - diode-napalm-agent/diode_napalm/translate.py | 2 +- diode-napalm-agent/tests/test_client.py | 1 + diode-napalm-agent/tests/test_translate.py | 2 ++ 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/diode-napalm-agent/README.md b/diode-napalm-agent/README.md index b85e9c5..68be197 100644 --- a/diode-napalm-agent/README.md +++ b/diode-napalm-agent/README.md @@ -61,7 +61,7 @@ diode: Variables (using `${ENV}` syntax) can be referenced in the configuration file from environmental variables or from a provided `.env` file. -The `driver` device attribute is optional. If not specified, the agent will attempt to find a match from NAPALM supported drivers. +The `driver` device attribute is optional. If not specified, the agent will attempt to find a match from NAPALM supported/installed drivers. Detailed information about `optional_args` can be found in the NAPALM [documentation](https://napalm.readthedocs.io/en/latest/support/#optional-arguments). @@ -100,6 +100,19 @@ The default supported drivers are the natively supported [NAPALM](https://napalm - Cisco NX-OS ("nxos") - Juniper JunOS ("junos") +Moreover, if a NAPALM [community driver](https://github.com/napalm-automation-community) is installed in the environment, it can be used in the agent's policy and also in automatic driver matching when none are specified. + +### Supported Netbox Object Types + +Currently, once napalm agent connects to a network device, it tries to fetch and ingest to Diode the following Netbox Object Types: + +- [DCIM.Device](https://netboxlabs.com/docs/netbox/en/stable/models/dcim/device/) +- [DCIM.DeviceType](https://netboxlabs.com/docs/netbox/en/stable/models/dcim/devicetype/) +- [DCIM.Interface](https://netboxlabs.com/docs/netbox/en/stable/models/dcim/interface/) +- [DCIM.Platform](https://netboxlabs.com/docs/netbox/en/stable/models/dcim/platform/) +- [IPAM.IPAddress](https://netboxlabs.com/docs/netbox/en/stable/models/ipam/ipaddress/) +- [IPAM.Prefix](https://netboxlabs.com/docs/netbox/en/stable/models/ipam/prefix/) + ## License Distributed under the Apache 2.0 License. See [LICENSE.txt](./diode-proto/LICENSE.txt) for more information. diff --git a/diode-napalm-agent/diode_napalm/cli/cli.py b/diode-napalm-agent/diode_napalm/cli/cli.py index 190d178..fe14995 100644 --- a/diode-napalm-agent/diode_napalm/cli/cli.py +++ b/diode-napalm-agent/diode_napalm/cli/cli.py @@ -64,7 +64,6 @@ def run_driver(info: Napalm, config: DiscoveryConfig): "device": device.get_facts(), "interface": device.get_interfaces(), "interface_ip": device.get_interfaces_ip(), - "vlan": device.get_vlans(), } Client().ingest(info.hostname, data) diff --git a/diode-napalm-agent/diode_napalm/client.py b/diode-napalm-agent/diode_napalm/client.py index b4ed148..2a1f6e1 100644 --- a/diode-napalm-agent/diode_napalm/client.py +++ b/diode-napalm-agent/diode_napalm/client.py @@ -4,7 +4,6 @@ import logging import threading -from typing import Optional from netboxlabs.diode.sdk import DiodeClient diff --git a/diode-napalm-agent/diode_napalm/translate.py b/diode-napalm-agent/diode_napalm/translate.py index c97faf0..2f88367 100644 --- a/diode-napalm-agent/diode_napalm/translate.py +++ b/diode-napalm-agent/diode_napalm/translate.py @@ -64,7 +64,7 @@ def translate_interface( interface = Interface( device=device, name=if_name, - type="other", + type=interface_info.get("type"), enabled=interface_info.get("is_enabled"), mtu=interface_info.get("mtu"), mac_address=interface_info.get("mac_address"), diff --git a/diode-napalm-agent/tests/test_client.py b/diode-napalm-agent/tests/test_client.py index d81728b..a388285 100644 --- a/diode-napalm-agent/tests/test_client.py +++ b/diode-napalm-agent/tests/test_client.py @@ -29,6 +29,7 @@ def sample_data(): "mac_address": "00:1C:58:29:4A:71", "speed": 1000, "description": "Uplink Interface", + "type": "ethernet" } }, "interface_ip": { diff --git a/diode-napalm-agent/tests/test_translate.py b/diode-napalm-agent/tests/test_translate.py index 2466184..5f94162 100644 --- a/diode-napalm-agent/tests/test_translate.py +++ b/diode-napalm-agent/tests/test_translate.py @@ -36,6 +36,7 @@ def sample_interface_info(): "mac_address": "00:1C:58:29:4A:71", "speed": 1000, "description": "Uplink Interface", + "type": "ethernet", } } @@ -69,6 +70,7 @@ def test_translate_interface(sample_device_info, sample_interface_info): assert interface.mac_address == "00:1C:58:29:4A:71" assert interface.speed == 1000 assert interface.description == "Uplink Interface" + assert interface.type == "ethernet" def test_translate_interface_ips( From ef8719d67a005091fa85c5b722f63ceee7317ed3 Mon Sep 17 00:00:00 2001 From: Leonardo Parente <23251360+leoparente@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:27:15 -0300 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Richard Boucher <58948528+rboucher-me@users.noreply.github.com> --- diode-napalm-agent/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diode-napalm-agent/README.md b/diode-napalm-agent/README.md index 68be197..f3ba172 100644 --- a/diode-napalm-agent/README.md +++ b/diode-napalm-agent/README.md @@ -61,7 +61,7 @@ diode: Variables (using `${ENV}` syntax) can be referenced in the configuration file from environmental variables or from a provided `.env` file. -The `driver` device attribute is optional. If not specified, the agent will attempt to find a match from NAPALM supported/installed drivers. +The `driver` device attribute is optional. If not specified, the agent will attempt to find a match from NAPALM supported and installed drivers. Detailed information about `optional_args` can be found in the NAPALM [documentation](https://napalm.readthedocs.io/en/latest/support/#optional-arguments). @@ -100,11 +100,11 @@ The default supported drivers are the natively supported [NAPALM](https://napalm - Cisco NX-OS ("nxos") - Juniper JunOS ("junos") -Moreover, if a NAPALM [community driver](https://github.com/napalm-automation-community) is installed in the environment, it can be used in the agent's policy and also in automatic driver matching when none are specified. +For NAPALM [community drivers](https://github.com/napalm-automation-community) installed in the environment, they can be referenced in the agent policy and will be used for automatic driver matching if no driver is specified. ### Supported Netbox Object Types -Currently, once napalm agent connects to a network device, it tries to fetch and ingest to Diode the following Netbox Object Types: +The Diode NAPALM agent tries to fetch information from network devices about the following NetBox object types: - [DCIM.Device](https://netboxlabs.com/docs/netbox/en/stable/models/dcim/device/) - [DCIM.DeviceType](https://netboxlabs.com/docs/netbox/en/stable/models/dcim/devicetype/) From 58f53cb47c22ea4aed3897eed4f5a7f774078643 Mon Sep 17 00:00:00 2001 From: Leonardo Parente <23251360+leoparente@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:13:22 -0300 Subject: [PATCH 3/3] let server handle interface type --- diode-napalm-agent/diode_napalm/translate.py | 1 - diode-napalm-agent/tests/test_client.py | 1 - diode-napalm-agent/tests/test_translate.py | 2 -- 3 files changed, 4 deletions(-) diff --git a/diode-napalm-agent/diode_napalm/translate.py b/diode-napalm-agent/diode_napalm/translate.py index 2f88367..476d9f3 100644 --- a/diode-napalm-agent/diode_napalm/translate.py +++ b/diode-napalm-agent/diode_napalm/translate.py @@ -64,7 +64,6 @@ def translate_interface( interface = Interface( device=device, name=if_name, - type=interface_info.get("type"), enabled=interface_info.get("is_enabled"), mtu=interface_info.get("mtu"), mac_address=interface_info.get("mac_address"), diff --git a/diode-napalm-agent/tests/test_client.py b/diode-napalm-agent/tests/test_client.py index a388285..d81728b 100644 --- a/diode-napalm-agent/tests/test_client.py +++ b/diode-napalm-agent/tests/test_client.py @@ -29,7 +29,6 @@ def sample_data(): "mac_address": "00:1C:58:29:4A:71", "speed": 1000, "description": "Uplink Interface", - "type": "ethernet" } }, "interface_ip": { diff --git a/diode-napalm-agent/tests/test_translate.py b/diode-napalm-agent/tests/test_translate.py index 5f94162..2466184 100644 --- a/diode-napalm-agent/tests/test_translate.py +++ b/diode-napalm-agent/tests/test_translate.py @@ -36,7 +36,6 @@ def sample_interface_info(): "mac_address": "00:1C:58:29:4A:71", "speed": 1000, "description": "Uplink Interface", - "type": "ethernet", } } @@ -70,7 +69,6 @@ def test_translate_interface(sample_device_info, sample_interface_info): assert interface.mac_address == "00:1C:58:29:4A:71" assert interface.speed == 1000 assert interface.description == "Uplink Interface" - assert interface.type == "ethernet" def test_translate_interface_ips(