Skip to content

Commit

Permalink
separate shortname dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishka17 committed Feb 4, 2025
1 parent e53f699 commit 3357f2b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions annet/adapters/netbox/v37/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(self, opts: Optional[NetboxStorageOpts] = None):
self._all_fqdns: Optional[list[str]] = None
self._id_devices: dict[int, models.NetboxDevice] = {}
self._name_devices: dict[str, models.NetboxDevice] = {}
self._short_name_devices: dict[str, models.NetboxDevice] = {}

def __enter__(self):
return self
Expand Down Expand Up @@ -145,6 +146,8 @@ def make_devices(
for glob in query.globs:
if glob in self._name_devices:
devices.append(self._name_devices[glob])
if glob in self._short_name_devices:
devices.append(self._short_name_devices[glob])
else:
globs.append(glob)
if not globs:
Expand Down Expand Up @@ -198,10 +201,10 @@ def _make_devices(

def _record_device(self, device: models.NetboxDevice):
self._id_devices[device.id] = device
self._name_devices[device.name] = device
self._short_name_devices[device.name] = device
if not self.exact_host_filter:
short_name = device.name.split(".")[0]
self._name_devices[short_name] = device
self._short_name_devices[short_name] = device

def _load_devices(self, query: NetboxQuery) -> List[api_models.Device]:
if not query.globs:
Expand Down

0 comments on commit 3357f2b

Please sign in to comment.