Skip to content

Commit

Permalink
Merge pull request #56 from netboxlabs/develop
Browse files Browse the repository at this point in the history
release device-discovery 🚚
  • Loading branch information
leoparente authored Jan 17, 2025
2 parents 668dfb3 + 45c4213 commit b515c2b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
4 changes: 2 additions & 2 deletions device-discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Orb device discovery backend
```bash
usage: device-discovery [-h] [-V] [-s HOST] [-p PORT] -t DIODE_TARGET -k DIODE_API_KEY

Orb Discovery Backend
Orb Device Discovery Backend

options:
-h, --help show this help message and exit
-V, --version Display Discovery, NAPALM and Diode SDK versions
-V, --version Display Device Discovery, NAPALM and Diode SDK versions
-s HOST, --host HOST Server host
-p PORT, --port PORT Server port
-t DIODE_TARGET, --diode-target DIODE_TARGET
Expand Down
2 changes: 1 addition & 1 deletion device-discovery/device_discovery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""NetBox Labs - Orb Discovery namespace."""
"""NetBox Labs - Device Discovery namespace."""
8 changes: 4 additions & 4 deletions device-discovery/device_discovery/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Orb Discovery entry point."""
"""Device Discovery entry point."""

import argparse
import os
Expand All @@ -21,14 +21,14 @@ def main():
Parses command-line arguments and starts the backend.
"""
parser = argparse.ArgumentParser(description="Orb Discovery Backend")
parser = argparse.ArgumentParser(description="Orb Device Discovery Backend")
parser.add_argument(
"-V",
"--version",
action="version",
version=f"Discovery version: {version_semver()}, NAPALM version: {version('napalm')}, "
version=f"Device Discovery version: {version_semver()}, NAPALM version: {version('napalm')}, "
f"Diode SDK version: {SdkVersion.version_semver()}",
help="Display Discovery, NAPALM and Diode SDK versions",
help="Display Device Discovery, NAPALM and Diode SDK versions",
)
parser.add_argument(
"-s",
Expand Down
2 changes: 1 addition & 1 deletion device-discovery/device_discovery/policy/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Orb Discovery Policy Manager."""
"""Device Discovery Policy Manager."""

import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion device-discovery/device_discovery/policy/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Orb Discovery Policy Models."""
"""Device Discovery Policy Models."""

from enum import Enum
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion device-discovery/device_discovery/policy/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Orb Discovery Policy Runner."""
"""Device Discovery Policy Runner."""

import logging
import uuid
Expand Down
2 changes: 1 addition & 1 deletion device-discovery/device_discovery/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Orb Discovery Server."""
"""Device Discovery Server."""


from contextlib import asynccontextmanager
Expand Down
2 changes: 1 addition & 1 deletion device-discovery/device_discovery/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def translate_interface_ips(
ip_entities = []

for if_ip_name, ip_info in interfaces_ip.items():
if interface.name in if_ip_name:
if interface.name == if_ip_name:
for ip_version, default_prefix in (("ipv4", 32), ("ipv6", 128)):
for ip, details in ip_info.get(ip_version, {}).items():
ip_address = f"{ip}/{details.get('prefix_length', default_prefix)}"
Expand Down
31 changes: 26 additions & 5 deletions device-discovery/tests/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def sample_device_info():
"serial_number": "123456789",
"site": "New York",
"driver": "ios",
"interface_list": ["GigabitEthernet0/0"],
"interface_list": ["GigabitEthernet0/0", "GigabitEthernet0/0/1"],
}


Expand All @@ -38,6 +38,13 @@ def sample_interface_info():
"mac_address": "00:1C:58:29:4A:71",
"speed": 1000,
"description": "Uplink Interface",
},
"GigabitEthernet0/0/1": {
"is_enabled": True,
"mtu": 1500,
"mac_address": "00:1C:58:29:4A:72",
"speed": 10000,
"description": "Uplink Interface",
}
}

Expand All @@ -59,7 +66,7 @@ def sample_interface_overflows_info():
@pytest.fixture
def sample_interfaces_ip():
"""Sample interface IPs for testing."""
return {"GigabitEthernet0/0": {"ipv4": {"192.0.2.1": {"prefix_length": 24}}}}
return {"GigabitEthernet0/0/1": {"ipv4": {"192.0.2.1": {"prefix_length": 24}}}}


@pytest.fixture
Expand Down Expand Up @@ -144,6 +151,19 @@ def test_translate_interface_ips(
ip_entities = list(
translate_interface_ips(interface, sample_interfaces_ip, sample_defaults)
)

assert len(ip_entities) == 0

interface = translate_interface(
device,
"GigabitEthernet0/0/1",
sample_interface_info["GigabitEthernet0/0/1"],
sample_defaults,
)
ip_entities = list(
translate_interface_ips(interface, sample_interfaces_ip, sample_defaults)
)

assert len(ip_entities) == 2
assert ip_entities[0].prefix.prefix == "192.0.2.0/24"
assert ip_entities[1].ip_address.address == "192.0.2.1/24"
Expand All @@ -164,8 +184,9 @@ def test_translate_data(
"driver": "ios",
}
entities = list(translate_data(data))
assert len(entities) == 4
assert len(entities) == 5
assert entities[0].device.name == "router1"
assert entities[1].interface.name == "GigabitEthernet0/0"
assert entities[2].prefix.prefix == "192.0.2.0/24"
assert entities[3].ip_address.address == "192.0.2.1/24"
assert entities[2].interface.name == "GigabitEthernet0/0/1"
assert entities[3].prefix.prefix == "192.0.2.0/24"
assert entities[4].ip_address.address == "192.0.2.1/24"

0 comments on commit b515c2b

Please sign in to comment.