mirror of
https://github.com/drygdryg/netbox-plugin-device-map.git
synced 2024-11-26 04:00:54 +03:00
NetBox v3.3 support
This commit is contained in:
parent
f0aa63e6e0
commit
44211d254a
@ -4,7 +4,7 @@ from extras.plugins import PluginConfig
|
|||||||
class DeviceMapConfig(PluginConfig):
|
class DeviceMapConfig(PluginConfig):
|
||||||
name = 'netbox_device_map'
|
name = 'netbox_device_map'
|
||||||
verbose_name = 'Device map'
|
verbose_name = 'Device map'
|
||||||
version = '0.1'
|
version = '0.1.1'
|
||||||
author = 'Victor Golovanenko'
|
author = 'Victor Golovanenko'
|
||||||
author_email = 'drygdryg2014@yandex.com'
|
author_email = 'drygdryg2014@yandex.com'
|
||||||
base_url = 'device-map'
|
base_url = 'device-map'
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
|
from packaging import version
|
||||||
|
|
||||||
from dcim.models import Device
|
from dcim.models import Device
|
||||||
from django.db.models import QuerySet, Q
|
from django.db.models import QuerySet, Q
|
||||||
from ipam.models import VLAN
|
from ipam.models import VLAN
|
||||||
|
from netbox.settings import VERSION
|
||||||
|
|
||||||
from .settings import plugin_settings
|
from .settings import plugin_settings
|
||||||
|
|
||||||
|
|
||||||
LOCATION_CF_NAME = plugin_settings['device_geolocation_cf']
|
LOCATION_CF_NAME = plugin_settings['device_geolocation_cf']
|
||||||
|
NETBOX_VERSION = version.parse(VERSION)
|
||||||
LatLon = tuple[float, float]
|
LatLon = tuple[float, float]
|
||||||
|
|
||||||
|
|
||||||
@ -22,11 +26,19 @@ def get_connected_devices(device: Device, vlan: VLAN = None) -> QuerySet[Device]
|
|||||||
included_interfaces = device.interfaces.all()
|
included_interfaces = device.interfaces.all()
|
||||||
if vlan is not None:
|
if vlan is not None:
|
||||||
included_interfaces = included_interfaces.filter(Q(untagged_vlan=vlan) | Q(tagged_vlans=vlan))
|
included_interfaces = included_interfaces.filter(Q(untagged_vlan=vlan) | Q(tagged_vlans=vlan))
|
||||||
return Device.objects.filter(interfaces___link_peer_id__in=included_interfaces)
|
if NETBOX_VERSION < version.parse('3.3.0'):
|
||||||
|
return Device.objects.filter(interfaces___link_peer_id__in=included_interfaces)
|
||||||
|
else:
|
||||||
|
return Device.objects.filter(
|
||||||
|
interfaces__cable__terminations__interface__in=device.interfaces.all()
|
||||||
|
).exclude(pk=device.id)
|
||||||
|
|
||||||
|
|
||||||
def are_devices_connected(device_a: Device, device_b: Device) -> bool:
|
def are_devices_connected(device_a: Device, device_b: Device) -> bool:
|
||||||
"""Determines whether devices are connected to each other by a direct connection"""
|
"""Determines whether devices are connected to each other by a direct connection"""
|
||||||
return bool(
|
if NETBOX_VERSION < version.parse('3.3.0'):
|
||||||
Device.objects.filter(interfaces___link_peer_id__in=device_a.interfaces.all(), id=device_b.id).values('pk')
|
queryset = Device.objects.filter(interfaces___link_peer_id__in=device_a.interfaces.all(), id=device_b.id)
|
||||||
)
|
else:
|
||||||
|
queryset = Device.objects.filter(
|
||||||
|
interfaces__cable__terminations__interface__in=device_a.interfaces.all(), id=device_b.id)
|
||||||
|
return bool(queryset.values('pk'))
|
||||||
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
setuptools
|
||||||
|
Django
|
||||||
|
packaging
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', encoding='utf-8') as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='netbox-plugin-device-map',
|
name='netbox-plugin-device-map',
|
||||||
version='0.1.0',
|
version='0.1.1',
|
||||||
description='A simple device map with filter criteria',
|
description='A simple device map with filter criteria',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
|
Loading…
Reference in New Issue
Block a user