Verified Commit 6a6747fb authored by Adrian Schollmeyer's avatar Adrian Schollmeyer
Browse files

device: Add report for device uplink connections


Signed-off-by: Adrian Schollmeyer's avatarAdrian 'nex' Schollmeyer <adrian.schollmeyer@fem.tu-ilmenau.de>
parent d2a355c1
......@@ -7,3 +7,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
* `aruba.py` report
* ArubaApNetworkIntegration (ensure valid network configuration and uplink connection)
* `devices.py` report
* DeviceUplinkConnection (ensure valid uplink connection for regular devices)
from circuits.models import *
from dcim.choices import DeviceStatusChoices
from dcim.models import *
from ipam.models import *
from extras.reports import Report
class DeviceUplinkConnection(Report):
description = "Validate that every device has a valid uplink connection"
def test_uplink_has_cable(self):
for device in Device.objects.all():
device_role = device.device_role.name
if device_role == "Access Switch" or \
device_role == "Core Switch" or \
device_role == "External":
continue
has_uplink_cable = False
interfaces = Interface.objects.filter(device = device)
if len(interfaces) == 0:
continue
for interface in interfaces:
if interface.connected_endpoint is None:
continue
if isinstance(interface.connected_endpoint,
CircuitTermination):
self.log_info(device, "Uplink is a circuit!")
has_uplink_cable = True
continue
endpoint_role = \
interface.connected_endpoint.device.device_role.name
if endpoint_role == "Access Switch" or \
endpoint_role == "Core Switch":
has_uplink_cable = True
if has_uplink_cable:
self.log_success(device)
elif device.status == DeviceStatusChoices.STATUS_ACTIVE:
self.log_failure(device, "Missing uplink cable")
elif device.status == DeviceStatusChoices.STATUS_PLANNED:
self.log_info(device, "Missing uplink, but device is planned")
else:
self.log_warning(device,
"Missing uplink cable, but device is not active")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment