1
- from dcim.constants import CONNECTION_STATUS_PLANNED, DEVICE_STATUS_ACTIVE
1
+ from dcim.choices import DeviceStatusChoices
2
2
from dcim.models import ConsolePort, Device, PowerPort
3
3
from extras.reports import Report
4
4
@@ -9,13 +9,14 @@ class DeviceConnectionsReport(Report):
9
9
def test_console_connection(self):
10
10
11
11
# Check that every console port for every active device has a connection defined.
12
- for console_port in ConsolePort.objects.select_related('device').filter(device__status=DEVICE_STATUS_ACTIVE):
12
+ active = DeviceStatusChoices.STATUS_ACTIVE
13
+ for console_port in ConsolePort.objects.prefetch_related('device').filter(device__status=active):
13
14
if console_port.connected_endpoint is None:
14
15
self.log_failure(
15
16
console_port.device,
16
17
"No console connection defined for {}".format(console_port.name)
17
18
)
18
- elif console_port.connection_status == CONNECTION_STATUS_PLANNED :
19
+ elif not console_port.connection_status:
19
20
self.log_warning(
20
21
console_port.device,
21
22
"Console connection for {} marked as planned".format(console_port.name)
@@ -26,12 +27,12 @@ class DeviceConnectionsReport(Report):
26
27
def test_power_connections(self):
27
28
28
29
# Check that every active device has at least two connected power supplies.
29
- for device in Device.objects.filter(status=DEVICE_STATUS_ACTIVE ):
30
+ for device in Device.objects.filter(status=DeviceStatusChoices.STATUS_ACTIVE ):
30
31
connected_ports = 0
31
32
for power_port in PowerPort.objects.filter(device=device):
32
33
if power_port.connected_endpoint is not None:
33
34
connected_ports += 1
34
- if power_port.connection_status == CONNECTION_STATUS_PLANNED :
35
+ if not power_port.connection_status:
35
36
self.log_warning(
36
37
device,
37
38
"Power connection for {} marked as planned".format(power_port.name)
@@ -43,4 +44,3 @@ class DeviceConnectionsReport(Report):
43
44
)
44
45
else:
45
46
self.log_success(device)
46
-
0 commit comments