mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 00:58:16 -06:00
9627 numeric range field
This commit is contained in:
parent
8e67c548af
commit
8f8ba2c86c
@ -914,7 +914,8 @@ class VLANGroupFilterSet(OrganizationalModelFilterSet):
|
||||
|
||||
class Meta:
|
||||
model = VLANGroup
|
||||
fields = ('id', 'name', 'slug', 'min_vid', 'max_vid', 'description', 'scope_id')
|
||||
fields = ('id', 'name', 'slug', 'description', 'scope_id')
|
||||
# fields = ('id', 'name', 'slug', 'min_vid', 'max_vid', 'description', 'scope_id')
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
if not value.strip():
|
||||
|
@ -486,7 +486,8 @@ class VLANGroupBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = VLANGroup
|
||||
fieldsets = (
|
||||
FieldSet('site', 'min_vid', 'max_vid', 'description'),
|
||||
# FieldSet('site', 'min_vid', 'max_vid', 'description'),
|
||||
FieldSet('site', 'description'),
|
||||
FieldSet(
|
||||
'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster', name=_('Scope')
|
||||
),
|
||||
|
@ -413,7 +413,7 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('region', 'sitegroup', 'site', 'location', 'rack', name=_('Location')),
|
||||
FieldSet('cluster_group', 'cluster', name=_('Cluster')),
|
||||
FieldSet('min_vid', 'max_vid', name=_('VLAN ID')),
|
||||
# FieldSet('min_vid', 'max_vid', name=_('VLAN ID')),
|
||||
)
|
||||
model = VLANGroup
|
||||
region = DynamicModelMultipleChoiceField(
|
||||
@ -441,18 +441,18 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
|
||||
required=False,
|
||||
label=_('Rack')
|
||||
)
|
||||
min_vid = forms.IntegerField(
|
||||
required=False,
|
||||
min_value=VLAN_VID_MIN,
|
||||
max_value=VLAN_VID_MAX,
|
||||
label=_('Minimum VID')
|
||||
)
|
||||
max_vid = forms.IntegerField(
|
||||
required=False,
|
||||
min_value=VLAN_VID_MIN,
|
||||
max_value=VLAN_VID_MAX,
|
||||
label=_('Maximum VID')
|
||||
)
|
||||
# min_vid = forms.IntegerField(
|
||||
# required=False,
|
||||
# min_value=VLAN_VID_MIN,
|
||||
# max_value=VLAN_VID_MAX,
|
||||
# label=_('Minimum VID')
|
||||
# )
|
||||
# max_vid = forms.IntegerField(
|
||||
# required=False,
|
||||
# min_value=VLAN_VID_MIN,
|
||||
# max_value=VLAN_VID_MAX,
|
||||
# label=_('Maximum VID')
|
||||
# )
|
||||
cluster = DynamicModelMultipleChoiceField(
|
||||
queryset=Cluster.objects.all(),
|
||||
required=False,
|
||||
|
@ -633,15 +633,11 @@ class VLANGroupForm(NetBoxModelForm):
|
||||
}
|
||||
)
|
||||
slug = SlugField()
|
||||
# vlan_id_ranges = SimpleArrayField(
|
||||
# IntegerRangeField(),
|
||||
# delimiter="|"
|
||||
# )
|
||||
vlan_id_ranges = NumericRangeArrayField()
|
||||
|
||||
fieldsets = (
|
||||
FieldSet('name', 'slug', 'description', 'tags', name=_('VLAN Group')),
|
||||
FieldSet('min_vid', 'max_vid', 'vlan_id_ranges', name=_('Child VLANs')),
|
||||
FieldSet('vlan_id_ranges', name=_('Child VLANs')),
|
||||
FieldSet(
|
||||
'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster',
|
||||
name=_('Scope')
|
||||
@ -652,7 +648,7 @@ class VLANGroupForm(NetBoxModelForm):
|
||||
model = VLANGroup
|
||||
fields = [
|
||||
'name', 'slug', 'description', 'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack',
|
||||
'clustergroup', 'cluster', 'min_vid', 'max_vid', 'vlan_id_ranges', 'tags',
|
||||
'clustergroup', 'cluster', 'vlan_id_ranges', 'tags',
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -3,6 +3,15 @@
|
||||
import django.contrib.postgres.fields
|
||||
import django.contrib.postgres.fields.ranges
|
||||
from django.db import migrations
|
||||
from django.db.backends.postgresql.psycopg_any import NumericRange
|
||||
|
||||
|
||||
def move_min_max(apps, schema_editor):
|
||||
VLANGroup = apps.get_model('ipam', 'VLANGroup')
|
||||
for group in VLANGroup.objects.all():
|
||||
if group.min_vid or group.max_vid:
|
||||
group.vlan_id_ranges = [NumericRange(group.min_vid, group.max_vid)]
|
||||
group.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -17,4 +26,16 @@ class Migration(migrations.Migration):
|
||||
name='vlan_id_ranges',
|
||||
field=django.contrib.postgres.fields.ArrayField(base_field=django.contrib.postgres.fields.ranges.BigIntegerRangeField(), blank=True, null=True, size=None),
|
||||
),
|
||||
migrations.RunPython(
|
||||
code=move_min_max,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='vlangroup',
|
||||
name='max_vid',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='vlangroup',
|
||||
name='min_vid',
|
||||
),
|
||||
]
|
||||
|
@ -46,24 +46,6 @@ class VLANGroup(OrganizationalModel):
|
||||
ct_field='scope_type',
|
||||
fk_field='scope_id'
|
||||
)
|
||||
min_vid = models.PositiveSmallIntegerField(
|
||||
verbose_name=_('minimum VLAN ID'),
|
||||
default=VLAN_VID_MIN,
|
||||
validators=(
|
||||
MinValueValidator(VLAN_VID_MIN),
|
||||
MaxValueValidator(VLAN_VID_MAX)
|
||||
),
|
||||
help_text=_('Lowest permissible ID of a child VLAN')
|
||||
)
|
||||
max_vid = models.PositiveSmallIntegerField(
|
||||
verbose_name=_('maximum VLAN ID'),
|
||||
default=VLAN_VID_MAX,
|
||||
validators=(
|
||||
MinValueValidator(VLAN_VID_MIN),
|
||||
MaxValueValidator(VLAN_VID_MAX)
|
||||
),
|
||||
help_text=_('Highest permissible ID of a child VLAN')
|
||||
)
|
||||
vlan_id_ranges = ArrayField(
|
||||
BigIntegerRangeField(),
|
||||
verbose_name=_('min/max VLAN IDs'),
|
||||
@ -71,7 +53,6 @@ class VLANGroup(OrganizationalModel):
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
# vlan_id_ranges = BigIntegerRangeField(null=True, blank=True)
|
||||
|
||||
objects = VLANGroupQuerySet.as_manager()
|
||||
|
||||
|
@ -63,7 +63,7 @@ class VLANGroupQuerySet(RestrictedQuerySet):
|
||||
|
||||
return self.annotate(
|
||||
vlan_count=count_related(VLAN, 'group'),
|
||||
utilization=Round(F('vlan_count') / (F('max_vid') - F('min_vid') + 1.0) * 100, 2)
|
||||
# utilization=Round(F('vlan_count') / (F('max_vid') - F('min_vid') + 1.0) * 100, 2)
|
||||
)
|
||||
|
||||
|
||||
|
@ -156,7 +156,8 @@ class VLANGroupIndex(SearchIndex):
|
||||
('description', 500),
|
||||
('max_vid', 2000),
|
||||
)
|
||||
display_attrs = ('scope_type', 'min_vid', 'max_vid', 'description')
|
||||
# display_attrs = ('scope_type', 'min_vid', 'max_vid', 'description')
|
||||
display_attrs = ('scope_type', 'description')
|
||||
|
||||
|
||||
@register_search
|
||||
|
@ -91,7 +91,7 @@ class VLANGroupTable(NetBoxTable):
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = VLANGroup
|
||||
fields = (
|
||||
'pk', 'id', 'name', 'scope_type', 'scope', 'min_vid', 'max_vid', 'vlan_count', 'slug', 'description',
|
||||
'pk', 'id', 'name', 'scope_type', 'scope', 'vlan_id_ranges', 'vlan_count', 'slug', 'description',
|
||||
'tags', 'created', 'last_updated', 'actions', 'utilization',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'scope_type', 'scope', 'vlan_count', 'utilization', 'description')
|
||||
|
@ -52,6 +52,6 @@ class NumericRangeArrayField(forms.CharField):
|
||||
ranges = value.split(",")
|
||||
values = []
|
||||
for dash_range in value.split(','):
|
||||
begin, end = dash_range.split('-')
|
||||
values.append(NumericRange(begin, end))
|
||||
lower, upper = dash_range.split('-')
|
||||
values.append(NumericRange(lower, upper))
|
||||
return values
|
||||
|
Loading…
Reference in New Issue
Block a user