Repository: netbox-community/netbox
Pull request: Closes #16926 Adds various USB cable types to front/rear ports and cable choices
### Fixes: #16926

Add front/rear port and cable choices for various USB styles.

USB-A
USB-B
USB-C
USB-Mini-A
USB-Mini-B
USB-Micro-A
USB-Micro-B
USB-Micro-AB


Problem statement:
Add USB type to Front/Rear Ports choices
### NetBox version

v4.0.7

### Feature type

Data model extension

### Proposed functionality

I propose to add USB choices for Front/Rear ports.
Changes proposed include modifying dcim/choices.py to add USB front and rear ports.
No other data or UI changes required beyond the addition of USB choices

### Use case

Use Cases:
* Patch Panels with modular/keystone ports and pass-through USB keystones. 
* USB WiFi and Network Adapters

Specific Scenario:
Firewalla sells a 1u rack adapter/shelf for their Firewalla GOLD line of firewall appliances.  It has an optional USB Wifi adapter that they provide keystone slots to move from the rear of the firewalla appliance to the front of the 1u rack adapter.

General other benefits:
Netbox already supports USB cable types for consoles, but does not have a way to model using a usb cable and a patch panel to relocate the port from the rear/inside the rack to the front/outside of the rack.  These cables should be treated as any other patch cable.
This modification could also support USB attached celluar backup modems, and USB attached SMS gateways.

Code changes already completed in fork, just waiting on approval to submit a PR.

### Database changes

n/a -- only requires adding lines to dcim/choices.py

### External dependencies

n/a

Hints from issue discussion:
Thanks for your interest in improving NetBox!

I've moved this issue to `accepted` status and assigning it to you for implementation, since you've expressed interest in working it through to a PR.

Commit message: Closes #16926 Changes USB cable types to reflect versions-physical differences. Updated human readable labels on USB front/rear ports to match style of usb console ports

Patch to review:
diff --git a/netbox/dcim/choices.py b/netbox/dcim/choices.py
index fe8d8a158f6..931d1614453 100644
--- a/netbox/dcim/choices.py
+++ b/netbox/dcim/choices.py
@@ -1315,6 +1315,14 @@ class PortTypeChoices(ChoiceSet):
     TYPE_URM_P2 = 'urm-p2'
     TYPE_URM_P4 = 'urm-p4'
     TYPE_URM_P8 = 'urm-p8'
+    TYPE_USB_A = 'usb-a'
+    TYPE_USB_B = 'usb-b'
+    TYPE_USB_C = 'usb-c'
+    TYPE_USB_MINI_A = 'usb-mini-a'
+    TYPE_USB_MINI_B = 'usb-mini-b'
+    TYPE_USB_MICRO_A = 'usb-micro-a'
+    TYPE_USB_MICRO_B = 'usb-micro-b'
+    TYPE_USB_MICRO_AB = 'usb-micro-ab'
     TYPE_OTHER = 'other'
 
     CHOICES = (
@@ -1374,6 +1382,19 @@ class PortTypeChoices(ChoiceSet):
                 (TYPE_SPLICE, 'Splice'),
             ),
         ),
+        (
+            _('USB'),
+            (
+                (TYPE_USB_A, 'USB Type A'),
+                (TYPE_USB_B, 'USB Type B'),
+                (TYPE_USB_C, 'USB Type C'),
+                (TYPE_USB_MINI_A, 'USB Mini A'),
+                (TYPE_USB_MINI_B, 'USB Mini B'),
+                (TYPE_USB_MICRO_A, 'USB Micro A'),
+                (TYPE_USB_MICRO_B, 'USB Micro B'),
+                (TYPE_USB_MICRO_AB, 'USB Micro AB'),
+            ),
+        ),
         (
             _('Other'),
             (
@@ -1412,6 +1433,14 @@ class CableTypeChoices(ChoiceSet):
     TYPE_SMF_OS2 = 'smf-os2'
     TYPE_AOC = 'aoc'
     TYPE_POWER = 'power'
+    TYPE_USB_1 = 'usb-1'
+    TYPE_USB_1_1 = 'usb-1-1'
+    TYPE_USB_2 = 'usb-2'
+    TYPE_USB_3 = 'usb-3'
+    TYPE_USB_3_1 = 'usb-3-1'
+    TYPE_USB_3_2 = 'usb-3-2'
+    TYPE_USB_4 = 'usb-4'
+    TYPE_USB_4_2 = 'usb-4-2'
 
     CHOICES = (
         (
@@ -1444,6 +1473,18 @@ class CableTypeChoices(ChoiceSet):
                 (TYPE_AOC, 'Active Optical Cabling (AOC)'),
             ),
         ),
+        (
+            _('USB'), (
+                (TYPE_USB_1, 'USB 1.0'),
+                (TYPE_USB_1_1, 'USB 1.1'),
+                (TYPE_USB_2, 'USB 2.0'),
+                (TYPE_USB_3, 'USB 3.0'),
+                (TYPE_USB_3_1, 'USB 3.1'),
+                (TYPE_USB_3_2, 'USB 3.2'),
+                (TYPE_USB_4, 'USB 4'),
+                (TYPE_USB_4_2, 'USB 4 2.0'),
+            ),
+        ),
         (TYPE_POWER, _('Power')),
     )
 


Code review comments:
diff_hunk: @@ -1444,6 +1473,18 @@ class CableTypeChoices(ChoiceSet):
                 (TYPE_AOC, 'Active Optical Cabling (AOC)'),
             ),
         ),
+        (
+            _('USB'), (
+                (TYPE_USB_1, 'USB 1.0'),
+                (TYPE_USB_1_1, 'USB 1.1'),
+                (TYPE_USB_2, 'USB 2.0'),
+                (TYPE_USB_3, 'USB 3.0'),
+                (TYPE_USB_3_1, 'USB 3.1'),
+                (TYPE_USB_3_2, 'USB 3.2'),
+                (TYPE_USB_4, 'USB 4'),
+                (TYPE_USB_4_2, 'USB 4 2.0'),
path: netbox/dcim/choices.py
text: @user1:
Not all of these specify a new cable type. I spent a few minutes looking over the [Wikipedia page](https://en.wikipedia.org/wiki/USB) but it wasn't clear to me what the different classes of USB cabling actually are. Let's just add a single generic "USB" type for now. It doesn't need to be in a separate subgroup; it can be listed before "power.")

@author:
@user1 I'm ok going to generic USB overall, but I would like to make a case for distinction between at least USB 2 and USB 3 series as the bandwidth capacity is vastly different with USB2 capping out at 480gb and USB3 series ranging between 5Gb and 20gb.  I would think it would be more in line with other  various data capacity cables, but if the distinction isn't deemed important, I'll go ahead and make the suggested generic modifications.