Skip to content

Commit 6ccaa0d

Browse files
committed
Initial work on #792
1 parent b8f1585 commit 6ccaa0d

File tree

12 files changed

+305
-25
lines changed

12 files changed

+305
-25
lines changed

netbox/dcim/api/serializers.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from rest_framework.validators import UniqueTogetherValidator
55
from taggit_serializer.serializers import TaggitSerializer, TagListSerializerField
66

7+
from dcim.choices import PowerOutletTypes, PowerPortTypes
78
from dcim.constants import *
89
from dcim.models import (
910
Cable, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
@@ -218,14 +219,22 @@ class Meta:
218219

219220
class PowerPortTemplateSerializer(ValidatedModelSerializer):
220221
device_type = NestedDeviceTypeSerializer()
222+
type = ChoiceField(
223+
choices=PowerPortTypes.CHOICES,
224+
required=False
225+
)
221226

222227
class Meta:
223228
model = PowerPortTemplate
224-
fields = ['id', 'device_type', 'name', 'maximum_draw', 'allocated_draw']
229+
fields = ['id', 'device_type', 'name', 'type', 'maximum_draw', 'allocated_draw']
225230

226231

227232
class PowerOutletTemplateSerializer(ValidatedModelSerializer):
228233
device_type = NestedDeviceTypeSerializer()
234+
type = ChoiceField(
235+
choices=PowerOutletTypes.CHOICES,
236+
required=False
237+
)
229238
power_port = PowerPortTemplateSerializer(
230239
required=False
231240
)
@@ -237,7 +246,7 @@ class PowerOutletTemplateSerializer(ValidatedModelSerializer):
237246

238247
class Meta:
239248
model = PowerOutletTemplate
240-
fields = ['id', 'device_type', 'name', 'power_port', 'feed_leg']
249+
fields = ['id', 'device_type', 'name', 'type', 'power_port', 'feed_leg']
241250

242251

243252
class InterfaceTemplateSerializer(ValidatedModelSerializer):
@@ -400,6 +409,10 @@ class Meta:
400409

401410
class PowerOutletSerializer(TaggitSerializer, ConnectedEndpointSerializer):
402411
device = NestedDeviceSerializer()
412+
type = ChoiceField(
413+
choices=PowerOutletTypes.CHOICES,
414+
required=False
415+
)
403416
power_port = NestedPowerPortSerializer(
404417
required=False
405418
)
@@ -418,20 +431,24 @@ class PowerOutletSerializer(TaggitSerializer, ConnectedEndpointSerializer):
418431
class Meta:
419432
model = PowerOutlet
420433
fields = [
421-
'id', 'device', 'name', 'power_port', 'feed_leg', 'description', 'connected_endpoint_type',
434+
'id', 'device', 'name', 'type', 'power_port', 'feed_leg', 'description', 'connected_endpoint_type',
422435
'connected_endpoint', 'connection_status', 'cable', 'tags',
423436
]
424437

425438

426439
class PowerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer):
427440
device = NestedDeviceSerializer()
441+
type = ChoiceField(
442+
choices=PowerPortTypes.CHOICES,
443+
required=False
444+
)
428445
cable = NestedCableSerializer(read_only=True)
429446
tags = TagListSerializerField(required=False)
430447

431448
class Meta:
432449
model = PowerPort
433450
fields = [
434-
'id', 'device', 'name', 'maximum_draw', 'allocated_draw', 'description', 'connected_endpoint_type',
451+
'id', 'device', 'name', 'type', 'maximum_draw', 'allocated_draw', 'description', 'connected_endpoint_type',
435452
'connected_endpoint', 'connection_status', 'cable', 'tags',
436453
]
437454

netbox/dcim/api/views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ class DCIMFieldChoicesViewSet(FieldChoicesViewSet):
5252
(FrontPortTemplate, ['type']),
5353
(Interface, ['type', 'mode']),
5454
(InterfaceTemplate, ['type']),
55-
(PowerOutlet, ['feed_leg']),
56-
(PowerOutletTemplate, ['feed_leg']),
57-
(PowerPort, ['connection_status']),
55+
(PowerOutlet, ['type', 'feed_leg']),
56+
(PowerOutletTemplate, ['type', 'feed_leg']),
57+
(PowerPort, ['type', 'connection_status']),
58+
(PowerPortTemplate, ['type']),
5859
(Rack, ['outer_unit', 'status', 'type', 'width']),
5960
(RearPort, ['type']),
6061
(RearPortTemplate, ['type']),

netbox/dcim/choices.py

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,180 @@ def slug_to_integer(cls, slug):
6262
}.get(slug)
6363

6464

65+
#
66+
# Power port types
67+
#
68+
69+
class PowerPortTypes:
70+
# TODO: Add more power port types
71+
# IEC 60320
72+
TYPE_IEC_C6 = 'iec-60320-c6'
73+
TYPE_IEC_C8 = 'iec-60320-c8'
74+
TYPE_IEC_C14 = 'iec-60320-c14'
75+
TYPE_IEC_C16 = 'iec-60320-c16'
76+
TYPE_IEC_C20 = 'iec-60320-c20'
77+
# IEC 60309
78+
TYPE_IEC_PNE4H = 'iec-60309-p-n-e-4h'
79+
TYPE_IEC_PNE6H = 'iec-60309-p-n-e-6h'
80+
TYPE_IEC_PNE9H = 'iec-60309-p-n-e-9h'
81+
TYPE_IEC_2PE4H = 'iec-60309-2p-e-4h'
82+
TYPE_IEC_2PE6H = 'iec-60309-2p-e-6h'
83+
TYPE_IEC_2PE9H = 'iec-60309-2p-e-9h'
84+
TYPE_IEC_3PE4H = 'iec-60309-3p-e-4h'
85+
TYPE_IEC_3PE6H = 'iec-60309-3p-e-6h'
86+
TYPE_IEC_3PE9H = 'iec-60309-3p-e-9h'
87+
TYPE_IEC_3PNE4H = 'iec-60309-3p-n-e-4h'
88+
TYPE_IEC_3PNE6H = 'iec-60309-3p-n-e-6h'
89+
TYPE_IEC_3PNE9H = 'iec-60309-3p-n-e-9h'
90+
# NEMA non-locking
91+
TYPE_NEMA_515P = 'nema-5-15p'
92+
TYPE_NEMA_520P = 'nema-5-20p'
93+
TYPE_NEMA_530P = 'nema-5-30p'
94+
TYPE_NEMA_550P = 'nema-5-50p'
95+
TYPE_NEMA_615P = 'nema-6-15p'
96+
TYPE_NEMA_620P = 'nema-6-20p'
97+
TYPE_NEMA_630P = 'nema-6-30p'
98+
TYPE_NEMA_650P = 'nema-6-50p'
99+
# NEMA locking
100+
TYPE_NEMA_L515P = 'nema-l5-15p'
101+
TYPE_NEMA_L520P = 'nema-l5-20p'
102+
TYPE_NEMA_L530P = 'nema-l5-30p'
103+
TYPE_NEMA_L615P = 'nema-l5-50p'
104+
TYPE_NEMA_L620P = 'nema-l6-20p'
105+
TYPE_NEMA_L630P = 'nema-l6-30p'
106+
TYPE_NEMA_L650P = 'nema-l6-50p'
107+
108+
CHOICES = (
109+
('IEC 60320', (
110+
(TYPE_IEC_C6, 'C6'),
111+
(TYPE_IEC_C8, 'C8'),
112+
(TYPE_IEC_C14, 'C14'),
113+
(TYPE_IEC_C16, 'C16'),
114+
(TYPE_IEC_C20, 'C20'),
115+
)),
116+
('IEC 60309', (
117+
(TYPE_IEC_PNE4H, 'P+N+E 4H'),
118+
(TYPE_IEC_PNE6H, 'P+N+E 6H'),
119+
(TYPE_IEC_PNE9H, 'P+N+E 9H'),
120+
(TYPE_IEC_2PE4H, '2P+E 4H'),
121+
(TYPE_IEC_2PE6H, '2P+E 6H'),
122+
(TYPE_IEC_2PE9H, '2P+E 9H'),
123+
(TYPE_IEC_3PE4H, '3P+E 4H'),
124+
(TYPE_IEC_3PE6H, '3P+E 6H'),
125+
(TYPE_IEC_3PE9H, '3P+E 9H'),
126+
(TYPE_IEC_3PNE4H, '3P+N+E 4H'),
127+
(TYPE_IEC_3PNE6H, '3P+N+E 6H'),
128+
(TYPE_IEC_3PNE9H, '3P+N+E 9H'),
129+
)),
130+
('NEMA (Non-locking)', (
131+
(TYPE_NEMA_515P, 'NEMA 5-15P'),
132+
(TYPE_NEMA_520P, 'NEMA 5-20P'),
133+
(TYPE_NEMA_530P, 'NEMA 5-30P'),
134+
(TYPE_NEMA_550P, 'NEMA 5-50P'),
135+
(TYPE_NEMA_615P, 'NEMA 6-15P'),
136+
(TYPE_NEMA_620P, 'NEMA 6-20P'),
137+
(TYPE_NEMA_630P, 'NEMA 6-30P'),
138+
(TYPE_NEMA_650P, 'NEMA 6-50P'),
139+
)),
140+
('NEMA (Locking)', (
141+
(TYPE_NEMA_L515P, 'NEMA L5-15P'),
142+
(TYPE_NEMA_L520P, 'NEMA L5-20P'),
143+
(TYPE_NEMA_L530P, 'NEMA L5-30P'),
144+
(TYPE_NEMA_L615P, 'NEMA L6-15P'),
145+
(TYPE_NEMA_L620P, 'NEMA L6-20P'),
146+
(TYPE_NEMA_L630P, 'NEMA L6-30P'),
147+
(TYPE_NEMA_L650P, 'NEMA L6-50P'),
148+
)),
149+
)
150+
151+
152+
#
153+
# Power outlet types
154+
#
155+
156+
class PowerOutletTypes:
157+
# TODO: Add more power outlet types
158+
# IEC 60320
159+
TYPE_IEC_C5 = 'iec-60320-c5'
160+
TYPE_IEC_C7 = 'iec-60320-c7'
161+
TYPE_IEC_C13 = 'iec-60320-c13'
162+
TYPE_IEC_C15 = 'iec-60320-c15'
163+
TYPE_IEC_C19 = 'iec-60320-c19'
164+
# IEC 60309
165+
TYPE_IEC_PNE4H = 'iec-60309-p-n-e-4h'
166+
TYPE_IEC_PNE6H = 'iec-60309-p-n-e-6h'
167+
TYPE_IEC_PNE9H = 'iec-60309-p-n-e-9h'
168+
TYPE_IEC_2PE4H = 'iec-60309-2p-e-4h'
169+
TYPE_IEC_2PE6H = 'iec-60309-2p-e-6h'
170+
TYPE_IEC_2PE9H = 'iec-60309-2p-e-9h'
171+
TYPE_IEC_3PE4H = 'iec-60309-3p-e-4h'
172+
TYPE_IEC_3PE6H = 'iec-60309-3p-e-6h'
173+
TYPE_IEC_3PE9H = 'iec-60309-3p-e-9h'
174+
TYPE_IEC_3PNE4H = 'iec-60309-3p-n-e-4h'
175+
TYPE_IEC_3PNE6H = 'iec-60309-3p-n-e-6h'
176+
TYPE_IEC_3PNE9H = 'iec-60309-3p-n-e-9h'
177+
# NEMA non-locking
178+
TYPE_NEMA_515R = 'nema-5-15r'
179+
TYPE_NEMA_520R = 'nema-5-20r'
180+
TYPE_NEMA_530R = 'nema-5-30r'
181+
TYPE_NEMA_550R = 'nema-5-50r'
182+
TYPE_NEMA_615R = 'nema-6-15r'
183+
TYPE_NEMA_620R = 'nema-6-20r'
184+
TYPE_NEMA_630R = 'nema-6-30r'
185+
TYPE_NEMA_650R = 'nema-6-50r'
186+
# NEMA locking
187+
TYPE_NEMA_L515R = 'nema-l5-15r'
188+
TYPE_NEMA_L520R = 'nema-l5-20r'
189+
TYPE_NEMA_L530R = 'nema-l5-30r'
190+
TYPE_NEMA_L615R = 'nema-l5-50r'
191+
TYPE_NEMA_L620R = 'nema-l6-20r'
192+
TYPE_NEMA_L630R = 'nema-l6-30r'
193+
TYPE_NEMA_L650R = 'nema-l6-50r'
194+
195+
CHOICES = (
196+
('IEC 60320', (
197+
(TYPE_IEC_C5, 'C5'),
198+
(TYPE_IEC_C7, 'C7'),
199+
(TYPE_IEC_C13, 'C13'),
200+
(TYPE_IEC_C15, 'C15'),
201+
(TYPE_IEC_C19, 'C19'),
202+
)),
203+
('IEC 60309', (
204+
(TYPE_IEC_PNE4H, 'P+N+E 4H'),
205+
(TYPE_IEC_PNE6H, 'P+N+E 6H'),
206+
(TYPE_IEC_PNE9H, 'P+N+E 9H'),
207+
(TYPE_IEC_2PE4H, '2P+E 4H'),
208+
(TYPE_IEC_2PE6H, '2P+E 6H'),
209+
(TYPE_IEC_2PE9H, '2P+E 9H'),
210+
(TYPE_IEC_3PE4H, '3P+E 4H'),
211+
(TYPE_IEC_3PE6H, '3P+E 6H'),
212+
(TYPE_IEC_3PE9H, '3P+E 9H'),
213+
(TYPE_IEC_3PNE4H, '3P+N+E 4H'),
214+
(TYPE_IEC_3PNE6H, '3P+N+E 6H'),
215+
(TYPE_IEC_3PNE9H, '3P+N+E 9H'),
216+
)),
217+
('NEMA (Non-locking)', (
218+
(TYPE_NEMA_515R, 'NEMA 5-15R'),
219+
(TYPE_NEMA_520R, 'NEMA 5-20R'),
220+
(TYPE_NEMA_530R, 'NEMA 5-30R'),
221+
(TYPE_NEMA_550R, 'NEMA 5-50R'),
222+
(TYPE_NEMA_615R, 'NEMA 6-15R'),
223+
(TYPE_NEMA_620R, 'NEMA 6-20R'),
224+
(TYPE_NEMA_630R, 'NEMA 6-30R'),
225+
(TYPE_NEMA_650R, 'NEMA 6-50R'),
226+
)),
227+
('NEMA (Locking)', (
228+
(TYPE_NEMA_L515R, 'NEMA L5-15R'),
229+
(TYPE_NEMA_L520R, 'NEMA L5-20R'),
230+
(TYPE_NEMA_L530R, 'NEMA L5-30R'),
231+
(TYPE_NEMA_L615R, 'NEMA L6-15R'),
232+
(TYPE_NEMA_L620R, 'NEMA L6-20R'),
233+
(TYPE_NEMA_L630R, 'NEMA L6-30R'),
234+
(TYPE_NEMA_L650R, 'NEMA L6-50R'),
235+
)),
236+
)
237+
238+
65239
#
66240
# Interface type values
67241
#

netbox/dcim/filters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ class PowerPortTemplateFilter(DeviceTypeComponentFilterSet):
360360

361361
class Meta:
362362
model = PowerPortTemplate
363-
fields = ['id', 'name', 'maximum_draw', 'allocated_draw']
363+
fields = ['id', 'name', 'type', 'maximum_draw', 'allocated_draw']
364364

365365

366366
class PowerOutletTemplateFilter(DeviceTypeComponentFilterSet):
367367

368368
class Meta:
369369
model = PowerOutletTemplate
370-
fields = ['id', 'name', 'feed_leg']
370+
fields = ['id', 'name', 'type', 'feed_leg']
371371

372372

373373
class InterfaceTemplateFilter(DeviceTypeComponentFilterSet):
@@ -681,7 +681,7 @@ class PowerPortFilter(DeviceComponentFilterSet):
681681

682682
class Meta:
683683
model = PowerPort
684-
fields = ['id', 'name', 'maximum_draw', 'allocated_draw', 'description', 'connection_status']
684+
fields = ['id', 'name', 'type', 'maximum_draw', 'allocated_draw', 'description', 'connection_status']
685685

686686

687687
class PowerOutletFilter(DeviceComponentFilterSet):
@@ -693,7 +693,7 @@ class PowerOutletFilter(DeviceComponentFilterSet):
693693

694694
class Meta:
695695
model = PowerOutlet
696-
fields = ['id', 'name', 'feed_leg', 'description', 'connection_status']
696+
fields = ['id', 'name', 'type', 'feed_leg', 'description', 'connection_status']
697697

698698

699699
class InterfaceFilter(django_filters.FilterSet):

0 commit comments

Comments
 (0)