mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 00:58:16 -06:00
9627 update views
This commit is contained in:
parent
2f38ecc268
commit
0411f0dc62
@ -441,18 +441,6 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
|
|||||||
required=False,
|
required=False,
|
||||||
label=_('Rack')
|
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')
|
|
||||||
# )
|
|
||||||
cluster = DynamicModelMultipleChoiceField(
|
cluster = DynamicModelMultipleChoiceField(
|
||||||
queryset=Cluster.objects.all(),
|
queryset=Cluster.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
|
@ -89,16 +89,10 @@ class VLANGroup(OrganizationalModel):
|
|||||||
if self.scope_id and not self.scope_type:
|
if self.scope_id and not self.scope_type:
|
||||||
raise ValidationError(_("Cannot set scope_id without scope_type."))
|
raise ValidationError(_("Cannot set scope_id without scope_type."))
|
||||||
|
|
||||||
# Validate min/max child VID limits
|
|
||||||
if self.max_vid < self.min_vid:
|
|
||||||
raise ValidationError({
|
|
||||||
'max_vid': _("Maximum child VID must be greater than or equal to minimum child VID")
|
|
||||||
})
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self._total_vlan_ids = 0
|
self._total_vlan_ids = 0
|
||||||
for range in vland_id_ranges:
|
for vlan_range in vland_id_ranges:
|
||||||
self._total_vlan_ids += range.upper - range.lower + 1
|
self._total_vlan_ids += vlan_range.upper - vlan_range.lower + 1
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
@ -106,7 +100,9 @@ class VLANGroup(OrganizationalModel):
|
|||||||
"""
|
"""
|
||||||
Return all available VLANs within this group.
|
Return all available VLANs within this group.
|
||||||
"""
|
"""
|
||||||
available_vlans = {vid for vid in range(self.min_vid, self.max_vid + 1)}
|
available_vlans = {}
|
||||||
|
for vlan_range in self.vlan_id_ranges:
|
||||||
|
available_vlans = {vid for vid in range(vlan_range.lower, vlan_range.upper + 1)}
|
||||||
available_vlans -= set(VLAN.objects.filter(group=self).values_list('vid', flat=True))
|
available_vlans -= set(VLAN.objects.filter(group=self).values_list('vid', flat=True))
|
||||||
|
|
||||||
return sorted(available_vlans)
|
return sorted(available_vlans)
|
||||||
@ -115,8 +111,7 @@ class VLANGroup(OrganizationalModel):
|
|||||||
"""
|
"""
|
||||||
Return the first available VLAN ID (1-4094) in the group.
|
Return the first available VLAN ID (1-4094) in the group.
|
||||||
"""
|
"""
|
||||||
available_vids = []
|
available_vids = self.get_available_vids()
|
||||||
# available_vids = self.get_available_vids()
|
|
||||||
if available_vids:
|
if available_vids:
|
||||||
return available_vids[0]
|
return available_vids[0]
|
||||||
return None
|
return None
|
||||||
@ -127,6 +122,10 @@ class VLANGroup(OrganizationalModel):
|
|||||||
"""
|
"""
|
||||||
return VLAN.objects.filter(group=self).order_by('vid')
|
return VLAN.objects.filter(group=self).order_by('vid')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def vlan_ranges(self):
|
||||||
|
return ','.join([f"{self.vlan_id_ranges.lower}-{self.vlan_id_ranges.upper}" for val in value])
|
||||||
|
|
||||||
|
|
||||||
class VLAN(PrimaryModel):
|
class VLAN(PrimaryModel):
|
||||||
"""
|
"""
|
||||||
|
@ -63,7 +63,7 @@ class VLANGroupQuerySet(RestrictedQuerySet):
|
|||||||
|
|
||||||
return self.annotate(
|
return self.annotate(
|
||||||
vlan_count=count_related(VLAN, 'group'),
|
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('_total_vlan_ids') * 100, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,6 +72,10 @@ class VLANGroupTable(NetBoxTable):
|
|||||||
linkify=True,
|
linkify=True,
|
||||||
orderable=False
|
orderable=False
|
||||||
)
|
)
|
||||||
|
vlan_ranges = tables.Column(
|
||||||
|
verbose_name=_('VLAN Ranges'),
|
||||||
|
orderable=False
|
||||||
|
)
|
||||||
vlan_count = columns.LinkedCountColumn(
|
vlan_count = columns.LinkedCountColumn(
|
||||||
viewname='ipam:vlan_list',
|
viewname='ipam:vlan_list',
|
||||||
url_params={'group_id': 'pk'},
|
url_params={'group_id': 'pk'},
|
||||||
@ -91,11 +95,10 @@ class VLANGroupTable(NetBoxTable):
|
|||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'scope_type', 'scope', 'vlan_id_ranges', 'vlan_count', 'slug', 'description',
|
'pk', 'id', 'name', 'scope_type', 'scope', 'vlan_ranges', 'vlan_count', 'slug', 'description',
|
||||||
'tags', 'created', 'last_updated', 'actions', 'utilization',
|
'tags', 'created', 'last_updated', 'actions', 'utilization',
|
||||||
)
|
)
|
||||||
# default_columns = ('pk', 'name', 'scope_type', 'scope', 'vlan_count', 'utilization', 'description')
|
default_columns = ('pk', 'name', 'scope_type', 'scope', 'vlan_count', 'utilization', 'description')
|
||||||
default_columns = ('pk', 'name', 'scope_type', 'scope', 'vlan_count', 'description')
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -40,14 +40,12 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Permitted VIDs" %}</th>
|
<th scope="row">{% trans "Permitted VIDs" %}</th>
|
||||||
<td>{{ object.min_vid }} - {{ object.max_vid }}</td>
|
<td>{{ object.vlan_ranges }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% comment %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Utilization</th>
|
<th scope="row">Utilization</th>
|
||||||
<td>{% utilization_graph object.utilization %}</td>
|
<td>{% utilization_graph object.utilization %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endcomment %}
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% include 'inc/panels/tags.html' %}
|
{% include 'inc/panels/tags.html' %}
|
||||||
|
@ -43,8 +43,7 @@ class NumericRangeArrayField(forms.CharField):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def prepare_value(self, value):
|
def prepare_value(self, value):
|
||||||
range_str = ','.join([f"{val.lower}-{val.upper}" for val in value])
|
return ','.join([f"{val.lower}-{val.upper}" for val in value])
|
||||||
return range_str
|
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if not value:
|
if not value:
|
||||||
|
Loading…
Reference in New Issue
Block a user