mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-16 12:38:17 -06:00
parent
90f7122fde
commit
4a7758c847
@ -4,12 +4,14 @@ from django.db.models.expressions import RawSQL
|
||||
from .constants import NONCONNECTABLE_IFACE_TYPES
|
||||
|
||||
# Regular expressions for parsing Interface names
|
||||
TYPE_RE = r"SUBSTRING({} FROM '^([^0-9\.:]+)')"
|
||||
SLOT_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(\d{{1,9}})/') AS integer), NULL)"
|
||||
SUBSLOT_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9\.:]+)?\d{{1,9}}/(\d{{1,9}})') AS integer), NULL)"
|
||||
POSITION_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}/){{2}}(\d{{1,9}})') AS integer), NULL)"
|
||||
SUBPOSITION_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}/){{3}}(\d{{1,9}})') AS integer), NULL)"
|
||||
ID_RE = r"CAST(SUBSTRING({} FROM '^(?:[^0-9\.:]+)?(\d{{1,9}})([^/]|$)') AS integer)"
|
||||
TYPE_RE = r"SUBSTRING({} FROM '^([^0-9\.:]+|\d{{2,3}}GE)')"
|
||||
SLOT_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+|\d{{2,3}}GE)?(\d{{1,9}})/') AS integer), NULL)"
|
||||
SUBSLOT_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9\.:]+|\d{{2,3}}GE)?\d{{1,9}}/(\d{{1,9}})') AS integer), NULL)"
|
||||
POSITION_RE = \
|
||||
r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+|\d{{2,3}}GE)?(?:\d{{1,9}}/){{2}}(\d{{1,9}})') AS integer), NULL)"
|
||||
SUBPOSITION_RE = \
|
||||
r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+|\d{{2,3}}GE)?(?:\d{{1,9}}/){{3}}(\d{{1,9}})') AS integer), NULL)"
|
||||
ID_RE = r"CAST(SUBSTRING({} FROM '^(?:[^0-9\.:]+|\d{{2,3}}GE)?(\d{{1,9}})([^/]|$)') AS integer)"
|
||||
CHANNEL_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*:(\d{{1,9}})(\.\d{{1,9}})?$') AS integer), 0)"
|
||||
VC_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*\.(\d{{1,9}})$') AS integer), 0)"
|
||||
|
||||
@ -55,7 +57,7 @@ class InterfaceManager(Manager):
|
||||
|
||||
sql_col = '{}.name'.format(self.model._meta.db_table)
|
||||
ordering = [
|
||||
'_slot', '_subslot', '_position', '_subposition', '_type', '_id', '_channel', '_vc', 'name', 'pk'
|
||||
'_slot', '_type', '_subslot', '_position', '_subposition', '_id', '_channel', '_vc', 'name', 'pk'
|
||||
|
||||
]
|
||||
|
||||
|
@ -155,3 +155,30 @@ class NaturalOrderingTestCase(TestCase):
|
||||
iface.save()
|
||||
|
||||
self._compare_names(Interface.objects.filter(device=self.device), INTERFACES)
|
||||
|
||||
|
||||
def test_interface_ordering_huawei_vrp(self):
|
||||
|
||||
INTERFACES = (
|
||||
'100GE1/0/1',
|
||||
'100GE1/0/2',
|
||||
'100GE1/0/10',
|
||||
'10GE1/0/1',
|
||||
'10GE1/0/2',
|
||||
'10GE1/0/10',
|
||||
'25GE1/0/1',
|
||||
'25GE1/0/2',
|
||||
'25GE1/0/10',
|
||||
'40GE1/0/1',
|
||||
'40GE1/0/2',
|
||||
'40GE1/0/10',
|
||||
'10GE2/0/1',
|
||||
'25GE2/0/1',
|
||||
'100GE/2/0/4',
|
||||
)
|
||||
|
||||
for name in INTERFACES:
|
||||
iface = Interface(device=self.device, name=name)
|
||||
iface.save()
|
||||
|
||||
self._compare_names(Interface.objects.filter(device=self.device), INTERFACES)
|
||||
|
Loading…
Reference in New Issue
Block a user