|
@@ -1,11 +1,12 @@
|
|
|
from rest_framework import serializers
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
|
|
+from dcim.constants import CONNECTION_STATUS_CHOICES
|
|
|
from dcim.models import (
|
|
from dcim.models import (
|
|
|
Cable, ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceType, DeviceRole, FrontPort, FrontPortTemplate,
|
|
Cable, ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceType, DeviceRole, FrontPort, FrontPortTemplate,
|
|
|
Interface, Manufacturer, Platform, PowerOutlet, PowerPort, Rack, RackGroup, RackRole, RearPort, RearPortTemplate,
|
|
Interface, Manufacturer, Platform, PowerOutlet, PowerPort, Rack, RackGroup, RackRole, RearPort, RearPortTemplate,
|
|
|
Region, Site, VirtualChassis,
|
|
Region, Site, VirtualChassis,
|
|
|
)
|
|
)
|
|
|
-from utilities.api import WritableNestedSerializer
|
|
|
|
|
|
|
+from utilities.api import ChoiceField, WritableNestedSerializer
|
|
|
|
|
|
|
|
__all__ = [
|
|
__all__ = [
|
|
|
'NestedCableSerializer',
|
|
'NestedCableSerializer',
|
|
@@ -149,46 +150,51 @@ class NestedDeviceSerializer(WritableNestedSerializer):
|
|
|
class NestedConsoleServerPortSerializer(WritableNestedSerializer):
|
|
class NestedConsoleServerPortSerializer(WritableNestedSerializer):
|
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:consoleserverport-detail')
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:consoleserverport-detail')
|
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
|
|
|
+ connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = ConsoleServerPort
|
|
model = ConsoleServerPort
|
|
|
- fields = ['id', 'url', 'device', 'name', 'cable']
|
|
|
|
|
|
|
+ fields = ['id', 'url', 'device', 'name', 'cable', 'connection_status']
|
|
|
|
|
|
|
|
|
|
|
|
|
class NestedConsolePortSerializer(WritableNestedSerializer):
|
|
class NestedConsolePortSerializer(WritableNestedSerializer):
|
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:consoleport-detail')
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:consoleport-detail')
|
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
|
|
|
+ connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = ConsolePort
|
|
model = ConsolePort
|
|
|
- fields = ['id', 'url', 'device', 'name', 'cable']
|
|
|
|
|
|
|
+ fields = ['id', 'url', 'device', 'name', 'cable', 'connection_status']
|
|
|
|
|
|
|
|
|
|
|
|
|
class NestedPowerOutletSerializer(WritableNestedSerializer):
|
|
class NestedPowerOutletSerializer(WritableNestedSerializer):
|
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:poweroutlet-detail')
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:poweroutlet-detail')
|
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
|
|
|
+ connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = PowerOutlet
|
|
model = PowerOutlet
|
|
|
- fields = ['id', 'url', 'device', 'name', 'cable']
|
|
|
|
|
|
|
+ fields = ['id', 'url', 'device', 'name', 'cable', 'connection_status']
|
|
|
|
|
|
|
|
|
|
|
|
|
class NestedPowerPortSerializer(WritableNestedSerializer):
|
|
class NestedPowerPortSerializer(WritableNestedSerializer):
|
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:powerport-detail')
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:powerport-detail')
|
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
|
|
|
+ connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = PowerPort
|
|
model = PowerPort
|
|
|
- fields = ['id', 'url', 'device', 'name', 'cable']
|
|
|
|
|
|
|
+ fields = ['id', 'url', 'device', 'name', 'cable', 'connection_status']
|
|
|
|
|
|
|
|
|
|
|
|
|
class NestedInterfaceSerializer(WritableNestedSerializer):
|
|
class NestedInterfaceSerializer(WritableNestedSerializer):
|
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
device = NestedDeviceSerializer(read_only=True)
|
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:interface-detail')
|
|
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:interface-detail')
|
|
|
|
|
+ connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = Interface
|
|
model = Interface
|
|
|
- fields = ['id', 'url', 'device', 'name', 'cable']
|
|
|
|
|
|
|
+ fields = ['id', 'url', 'device', 'name', 'cable', 'connection_status']
|
|
|
|
|
|
|
|
|
|
|
|
|
class NestedRearPortSerializer(WritableNestedSerializer):
|
|
class NestedRearPortSerializer(WritableNestedSerializer):
|