Skip to content

Commit

Permalink
Closes #2649: Add connected_endpoint_type to connectable device compo…
Browse files Browse the repository at this point in the history
…nent API representations
  • Loading branch information
jeremystretch committed Dec 6, 2018
1 parent 360303f commit 45a1dfb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ NetBox now supports modeling physical cables for console, power, and interface c
* [#2632](https://github.com/digitalocean/netbox/issues/2632) - Change representation of null values from `0` to `null`
* [#2639](https://github.com/digitalocean/netbox/issues/2639) - Fix preservation of length/dimensions unit for racks and cables
* [#2648](https://github.com/digitalocean/netbox/issues/2648) - Include the `connection_status` field in nested represenations of connectable device components
* [#2649](https://github.com/digitalocean/netbox/issues/2649) - Add `connected_endpoint_type` to connectable device component API representations

## API Changes

Expand Down
2 changes: 1 addition & 1 deletion netbox/circuits/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ class Meta:
model = CircuitTermination
fields = [
'id', 'circuit', 'term_side', 'site', 'port_speed', 'upstream_speed', 'xconnect_id', 'pp_info',
'description', 'connected_endpoint', 'connection_status', 'cable',
'description', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable',
]
33 changes: 27 additions & 6 deletions netbox/dcim/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@


class ConnectedEndpointSerializer(ValidatedModelSerializer):
connected_endpoint_type = serializers.SerializerMethodField(read_only=True)
connected_endpoint = serializers.SerializerMethodField(read_only=True)
connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, read_only=True)

def get_connected_endpoint_type(self, obj):
if obj.connected_endpoint is None:
return None
return '{}.{}'.format(
obj.connected_endpoint._meta.app_label,
obj.connected_endpoint._meta.model_name
)

def get_connected_endpoint(self, obj):
"""
Return the appropriate serializer for the type of connected object.
Expand Down Expand Up @@ -331,7 +340,10 @@ class ConsoleServerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer)

class Meta:
model = ConsoleServerPort
fields = ['id', 'device', 'name', 'connected_endpoint', 'connection_status', 'cable', 'tags']
fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable',
'tags',
]


class ConsolePortSerializer(TaggitSerializer, ConnectedEndpointSerializer):
Expand All @@ -341,7 +353,10 @@ class ConsolePortSerializer(TaggitSerializer, ConnectedEndpointSerializer):

class Meta:
model = ConsolePort
fields = ['id', 'device', 'name', 'connected_endpoint', 'connection_status', 'cable', 'tags']
fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable',
'tags',
]


class PowerOutletSerializer(TaggitSerializer, ConnectedEndpointSerializer):
Expand All @@ -351,7 +366,10 @@ class PowerOutletSerializer(TaggitSerializer, ConnectedEndpointSerializer):

class Meta:
model = PowerOutlet
fields = ['id', 'device', 'name', 'connected_endpoint', 'connection_status', 'cable', 'tags']
fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable',
'tags',
]


class PowerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer):
Expand All @@ -361,7 +379,10 @@ class PowerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer):

class Meta:
model = PowerPort
fields = ['id', 'device', 'name', 'connected_endpoint', 'connection_status', 'cable', 'tags']
fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable',
'tags',
]


class InterfaceSerializer(TaggitSerializer, ConnectedEndpointSerializer):
Expand All @@ -383,8 +404,8 @@ class Meta:
model = Interface
fields = [
'id', 'device', 'name', 'form_factor', 'enabled', 'lag', 'mtu', 'mac_address', 'mgmt_only', 'description',
'connected_endpoint', 'connection_status', 'cable', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags',
'count_ipaddresses',
'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable', 'mode', 'untagged_vlan',
'tagged_vlans', 'tags', 'count_ipaddresses',
]

# TODO: This validation should be handled by Interface.clean()
Expand Down

0 comments on commit 45a1dfb

Please sign in to comment.