2017-04-20 13:07:22 -04:00
|
|
|
import re
|
2017-02-28 14:15:15 -05:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
from django import forms
|
2017-10-31 13:52:35 -04:00
|
|
|
from django.contrib.auth.models import User
|
2018-10-22 16:58:24 -04:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2017-02-16 13:46:58 -05:00
|
|
|
from django.contrib.postgres.forms.array import SimpleArrayField
|
2018-10-31 17:05:25 -04:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2020-05-01 15:40:34 -04:00
|
|
|
from django.utils.safestring import mark_safe
|
2021-03-01 17:24:30 -05:00
|
|
|
from django.utils.translation import gettext as _
|
2019-07-18 21:21:56 -04:00
|
|
|
from netaddr import EUI
|
|
|
|
from netaddr.core import AddrFormatError
|
2017-12-19 17:24:14 -05:00
|
|
|
from timezone_field import TimeZoneFormField
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-08-12 12:58:32 -04:00
|
|
|
from circuits.models import Circuit, CircuitTermination, Provider
|
2019-09-06 11:42:56 -05:00
|
|
|
from extras.forms import (
|
2021-03-01 13:37:53 -05:00
|
|
|
AddRemoveTagsForm, CustomFieldBulkEditForm, CustomFieldForm, CustomFieldModelCSVForm, CustomFieldFilterForm,
|
|
|
|
CustomFieldModelForm, LocalConfigContextFilterForm,
|
2019-09-06 11:42:56 -05:00
|
|
|
)
|
2020-06-12 09:58:59 -04:00
|
|
|
from extras.models import Tag
|
2020-01-15 14:53:46 -05:00
|
|
|
from ipam.constants import BGP_ASN_MAX, BGP_ASN_MIN
|
|
|
|
from ipam.models import IPAddress, VLAN
|
2019-10-04 12:08:48 -04:00
|
|
|
from tenancy.forms import TenancyFilterForm, TenancyForm
|
2021-03-01 17:24:30 -05:00
|
|
|
from tenancy.models import Tenant
|
2016-05-18 16:02:53 -04:00
|
|
|
from utilities.forms import (
|
2020-12-18 12:09:41 -05:00
|
|
|
APISelect, APISelectMultiple, add_blank_choice, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect,
|
2021-03-03 10:20:08 -05:00
|
|
|
ColorSelect, CommentField, CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, CSVTypedChoiceField,
|
|
|
|
DynamicModelChoiceField, DynamicModelMultipleChoiceField, ExpandableNameField, form_from_model, JSONField,
|
|
|
|
NumericArrayField, SelectWithPK, SmallTextarea, SlugField, StaticSelect2, StaticSelect2Multiple, TagFilterField,
|
|
|
|
BOOLEAN_WITH_BLANK_CHOICES,
|
2016-05-18 16:02:53 -04:00
|
|
|
)
|
2020-06-24 10:02:40 -04:00
|
|
|
from virtualization.models import Cluster, ClusterGroup
|
2019-10-30 16:31:04 -04:00
|
|
|
from .choices import *
|
2018-10-03 14:04:16 -04:00
|
|
|
from .constants import *
|
2021-03-08 13:28:53 -05:00
|
|
|
from .models import *
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2018-06-27 17:23:32 +02:00
|
|
|
DEVICE_BY_PK_RE = r'{\d+\}'
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2018-03-14 14:53:28 -04:00
|
|
|
INTERFACE_MODE_HELP_TEXT = """
|
|
|
|
Access: One untagged VLAN<br />
|
|
|
|
Tagged: One untagged VLAN and/or one or more tagged VLANs<br />
|
2020-02-05 17:26:44 +01:00
|
|
|
Tagged (All): Implies all VLANs are available (w/optional untagged VLAN)
|
2018-03-14 14:53:28 -04:00
|
|
|
"""
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
def get_device_by_name_or_pk(name):
|
|
|
|
"""
|
|
|
|
Attempt to retrieve a device by either its name or primary key ('{pk}').
|
|
|
|
"""
|
|
|
|
if re.match(DEVICE_BY_PK_RE, name):
|
|
|
|
pk = name.strip('{}')
|
|
|
|
device = Device.objects.get(pk=pk)
|
|
|
|
else:
|
|
|
|
device = Device.objects.get(name=name)
|
|
|
|
return device
|
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class DeviceComponentFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
2019-12-05 16:10:49 -06:00
|
|
|
field_order = [
|
2021-03-25 16:09:28 -04:00
|
|
|
'q', 'name', 'label', 'region_id', 'site_group_id', 'site_id',
|
2019-12-05 16:10:49 -06:00
|
|
|
]
|
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2019-12-05 16:10:49 -06:00
|
|
|
)
|
2021-03-24 14:48:38 -04:00
|
|
|
name = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
label = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2019-12-05 16:10:49 -06:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2019-12-05 16:10:49 -06:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label=_('Site group')
|
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-12-05 16:10:49 -06:00
|
|
|
queryset=Site.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2020-02-06 23:10:38 +00:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
device_id = DynamicModelMultipleChoiceField(
|
2020-02-06 23:10:38 +00:00
|
|
|
queryset=Device.objects.all(),
|
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
|
|
|
label=_('Device')
|
2019-12-05 16:10:49 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-12-02 14:19:02 -05:00
|
|
|
class InterfaceCommonForm(forms.Form):
|
2021-04-02 17:53:00 -04:00
|
|
|
mac_address = forms.CharField(
|
|
|
|
empty_value=None,
|
|
|
|
required=False,
|
|
|
|
label='MAC address'
|
|
|
|
)
|
2019-10-04 12:08:48 -04:00
|
|
|
|
2019-09-06 12:45:37 -05:00
|
|
|
def clean(self):
|
|
|
|
super().clean()
|
|
|
|
|
2020-12-02 14:19:02 -05:00
|
|
|
parent_field = 'device' if 'device' in self.cleaned_data else 'virtual_machine'
|
2019-09-06 12:45:37 -05:00
|
|
|
tagged_vlans = self.cleaned_data['tagged_vlans']
|
|
|
|
|
|
|
|
# Untagged interfaces cannot be assigned tagged VLANs
|
2019-11-21 22:39:15 -05:00
|
|
|
if self.cleaned_data['mode'] == InterfaceModeChoices.MODE_ACCESS and tagged_vlans:
|
2019-09-06 12:45:37 -05:00
|
|
|
raise forms.ValidationError({
|
|
|
|
'mode': "An access interface cannot have tagged VLANs assigned."
|
|
|
|
})
|
|
|
|
|
|
|
|
# Remove all tagged VLAN assignments from "tagged all" interfaces
|
2019-11-21 22:39:15 -05:00
|
|
|
elif self.cleaned_data['mode'] == InterfaceModeChoices.MODE_TAGGED_ALL:
|
2019-09-06 12:45:37 -05:00
|
|
|
self.cleaned_data['tagged_vlans'] = []
|
|
|
|
|
2020-01-01 12:09:51 +00:00
|
|
|
# Validate tagged VLANs; must be a global VLAN or in the same site
|
2020-01-15 14:54:46 -05:00
|
|
|
elif self.cleaned_data['mode'] == InterfaceModeChoices.MODE_TAGGED:
|
2020-12-02 14:19:02 -05:00
|
|
|
valid_sites = [None, self.cleaned_data[parent_field].site]
|
2020-01-01 19:53:13 +00:00
|
|
|
invalid_vlans = [str(v) for v in tagged_vlans if v.site not in valid_sites]
|
|
|
|
|
|
|
|
if invalid_vlans:
|
|
|
|
raise forms.ValidationError({
|
2020-12-02 14:19:02 -05:00
|
|
|
'tagged_vlans': f"The tagged VLANs ({', '.join(invalid_vlans)}) must belong to the same site as "
|
|
|
|
f"the interface's parent device/VM, or they must be global"
|
2020-01-01 19:53:13 +00:00
|
|
|
})
|
2019-12-31 20:47:13 +00:00
|
|
|
|
2019-09-06 12:45:37 -05:00
|
|
|
|
2021-03-01 13:37:53 -05:00
|
|
|
class ComponentForm(forms.Form):
|
2020-07-02 10:46:02 -04:00
|
|
|
"""
|
|
|
|
Subclass this form when facilitating the creation of one or more device component or component templates based on
|
|
|
|
a name pattern.
|
|
|
|
"""
|
2020-06-18 13:20:32 -04:00
|
|
|
name_pattern = ExpandableNameField(
|
|
|
|
label='Name'
|
|
|
|
)
|
|
|
|
label_pattern = ExpandableNameField(
|
|
|
|
label='Label',
|
2020-07-14 15:51:13 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Alphanumeric ranges are supported. (Must match the number of names being created.)'
|
2020-06-18 13:20:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
def clean(self):
|
2020-12-28 12:54:42 -05:00
|
|
|
super().clean()
|
2020-06-18 13:20:32 -04:00
|
|
|
|
|
|
|
# Validate that the number of components being created from both the name_pattern and label_pattern are equal
|
2020-06-30 16:30:54 -04:00
|
|
|
if self.cleaned_data['label_pattern']:
|
|
|
|
name_pattern_count = len(self.cleaned_data['name_pattern'])
|
|
|
|
label_pattern_count = len(self.cleaned_data['label_pattern'])
|
|
|
|
if name_pattern_count != label_pattern_count:
|
|
|
|
raise forms.ValidationError({
|
|
|
|
'label_pattern': f'The provided name pattern will create {name_pattern_count} components, however '
|
|
|
|
f'{label_pattern_count} labels will be generated. These counts must match.'
|
|
|
|
}, code='label_pattern_mismatch')
|
2020-06-18 13:20:32 -04:00
|
|
|
|
|
|
|
|
2019-07-18 21:21:56 -04:00
|
|
|
#
|
|
|
|
# Fields
|
|
|
|
#
|
|
|
|
|
|
|
|
class MACAddressField(forms.Field):
|
|
|
|
widget = forms.CharField
|
|
|
|
default_error_messages = {
|
|
|
|
'invalid': 'MAC address must be in EUI-48 format',
|
|
|
|
}
|
|
|
|
|
|
|
|
def to_python(self, value):
|
|
|
|
value = super().to_python(value)
|
|
|
|
|
|
|
|
# Validate MAC address format
|
|
|
|
try:
|
|
|
|
value = EUI(value.strip())
|
|
|
|
except AddrFormatError:
|
|
|
|
raise forms.ValidationError(self.error_messages['invalid'], code='invalid')
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2017-02-28 12:11:43 -05:00
|
|
|
#
|
|
|
|
# Regions
|
|
|
|
#
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class RegionForm(BootstrapMixin, CustomFieldModelForm):
|
2020-07-09 09:50:01 -04:00
|
|
|
parent = DynamicModelChoiceField(
|
2020-02-11 09:50:33 -05:00
|
|
|
queryset=Region.objects.all(),
|
2020-07-09 09:50:01 -04:00
|
|
|
required=False
|
2020-02-11 09:50:33 -05:00
|
|
|
)
|
2017-02-28 12:11:43 -05:00
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Region
|
2020-02-11 09:50:33 -05:00
|
|
|
fields = (
|
2020-03-13 16:24:37 -04:00
|
|
|
'parent', 'name', 'slug', 'description',
|
2020-02-11 09:50:33 -05:00
|
|
|
)
|
2017-02-28 12:11:43 -05:00
|
|
|
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class RegionCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
parent = CSVModelChoiceField(
|
2017-07-18 01:50:26 +03:00
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Name of parent region'
|
2017-07-18 01:50:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Region
|
2018-02-02 14:26:16 -05:00
|
|
|
fields = Region.csv_headers
|
2017-07-18 01:50:26 +03:00
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class RegionBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['parent', 'description']
|
|
|
|
|
|
|
|
|
2018-01-30 12:11:20 -05:00
|
|
|
class RegionFilterForm(BootstrapMixin, forms.Form):
|
|
|
|
model = Site
|
2018-11-27 11:57:29 -05:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2018-01-30 12:11:20 -05:00
|
|
|
|
|
|
|
|
2021-03-08 13:28:53 -05:00
|
|
|
#
|
|
|
|
# Site groups
|
|
|
|
#
|
|
|
|
|
|
|
|
class SiteGroupForm(BootstrapMixin, CustomFieldModelForm):
|
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SiteGroup
|
|
|
|
fields = (
|
|
|
|
'parent', 'name', 'slug', 'description',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class SiteGroupCSVForm(CustomFieldModelCSVForm):
|
|
|
|
parent = CSVModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
|
|
|
help_text='Name of parent site group'
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SiteGroup
|
|
|
|
fields = SiteGroup.csv_headers
|
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class SiteGroupBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['parent', 'description']
|
|
|
|
|
|
|
|
|
2021-03-08 13:28:53 -05:00
|
|
|
class SiteGroupFilterForm(BootstrapMixin, forms.Form):
|
|
|
|
model = Site
|
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
|
|
|
label=_('Search')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Sites
|
|
|
|
#
|
|
|
|
|
2020-01-29 10:49:02 -05:00
|
|
|
class SiteForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
2020-07-09 09:50:01 -04:00
|
|
|
region = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Region.objects.all(),
|
2020-07-09 09:50:01 -04:00
|
|
|
required=False
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2016-05-20 15:32:17 -04:00
|
|
|
slug = SlugField()
|
2016-03-01 11:23:03 -05:00
|
|
|
comments = CommentField()
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Site
|
2017-02-28 12:11:43 -05:00
|
|
|
fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'name', 'slug', 'status', 'region', 'group', 'tenant_group', 'tenant', 'facility', 'asn', 'time_zone',
|
|
|
|
'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name',
|
|
|
|
'contact_phone', 'contact_email', 'comments', 'tags',
|
2017-02-28 12:11:43 -05:00
|
|
|
]
|
2021-02-25 13:51:48 -05:00
|
|
|
fieldsets = (
|
2021-03-08 13:28:53 -05:00
|
|
|
('Site', (
|
|
|
|
'name', 'slug', 'status', 'region', 'group', 'facility', 'asn', 'time_zone', 'description', 'tags',
|
|
|
|
)),
|
2021-02-25 13:51:48 -05:00
|
|
|
('Tenancy', ('tenant_group', 'tenant')),
|
|
|
|
('Contact Info', (
|
|
|
|
'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone',
|
|
|
|
'contact_email',
|
|
|
|
)),
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
widgets = {
|
2018-11-27 11:57:29 -05:00
|
|
|
'physical_address': SmallTextarea(
|
|
|
|
attrs={
|
|
|
|
'rows': 3,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
'shipping_address': SmallTextarea(
|
|
|
|
attrs={
|
|
|
|
'rows': 3,
|
|
|
|
}
|
|
|
|
),
|
2019-01-03 23:02:05 -05:00
|
|
|
'status': StaticSelect2(),
|
|
|
|
'time_zone': StaticSelect2(),
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
|
|
|
help_texts = {
|
|
|
|
'name': "Full name of the site",
|
|
|
|
'facility': "Data center provider and facility (e.g. Equinix NY7)",
|
|
|
|
'asn': "BGP autonomous system number",
|
2018-03-29 13:49:50 -04:00
|
|
|
'time_zone': "Local time zone",
|
|
|
|
'description': "Short description (will appear in sites list)",
|
2016-03-01 11:23:03 -05:00
|
|
|
'physical_address': "Physical location of the building (e.g. for GPS)",
|
2018-06-21 14:55:10 -04:00
|
|
|
'shipping_address': "If different from the physical address",
|
|
|
|
'latitude': "Latitude in decimal format (xx.yyyyyy)",
|
|
|
|
'longitude': "Longitude in decimal format (xx.yyyyyy)"
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-29 13:53:26 -05:00
|
|
|
class SiteCSVForm(CustomFieldModelCSVForm):
|
2018-01-25 13:07:04 -05:00
|
|
|
status = CSVChoiceField(
|
2019-11-21 22:54:01 -05:00
|
|
|
choices=SiteStatusChoices,
|
2018-01-25 13:07:04 -05:00
|
|
|
required=False,
|
|
|
|
help_text='Operational status'
|
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
region = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned region'
|
2017-02-28 12:11:43 -05:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
group = CSVModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
|
|
|
help_text='Assigned group'
|
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
tenant = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Tenant.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned tenant'
|
2017-02-28 12:11:43 -05:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Site
|
2018-02-02 14:26:16 -05:00
|
|
|
fields = Site.csv_headers
|
2017-06-06 17:27:26 -04:00
|
|
|
help_texts = {
|
2020-05-01 15:40:34 -04:00
|
|
|
'time_zone': mark_safe(
|
|
|
|
'Time zone (<a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">available options</a>)'
|
|
|
|
)
|
2017-06-06 17:27:26 -04:00
|
|
|
}
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2018-07-10 10:00:21 -04:00
|
|
|
class SiteBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2018-06-07 14:51:27 -04:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
status = forms.ChoiceField(
|
2019-11-21 22:54:01 -05:00
|
|
|
choices=add_blank_choice(SiteStatusChoices),
|
2018-06-07 14:51:27 -04:00
|
|
|
required=False,
|
2019-01-08 15:35:34 -08:00
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
2018-06-07 14:51:27 -04:00
|
|
|
)
|
2020-07-09 09:50:01 -04:00
|
|
|
region = DynamicModelChoiceField(
|
2018-06-07 14:51:27 -04:00
|
|
|
queryset=Region.objects.all(),
|
2020-07-09 09:50:01 -04:00
|
|
|
required=False
|
2018-06-07 14:51:27 -04:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
tenant = DynamicModelChoiceField(
|
2018-06-07 14:51:27 -04:00
|
|
|
queryset=Tenant.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-06-07 14:51:27 -04:00
|
|
|
)
|
|
|
|
asn = forms.IntegerField(
|
2020-01-09 21:58:38 +00:00
|
|
|
min_value=BGP_ASN_MIN,
|
|
|
|
max_value=BGP_ASN_MAX,
|
2018-06-07 14:51:27 -04:00
|
|
|
required=False,
|
|
|
|
label='ASN'
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=100,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
time_zone = TimeZoneFormField(
|
|
|
|
choices=add_blank_choice(TimeZoneFormField().choices),
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2018-06-07 14:51:27 -04:00
|
|
|
)
|
2016-09-30 16:17:41 -04:00
|
|
|
|
|
|
|
class Meta:
|
2018-11-27 11:57:29 -05:00
|
|
|
nullable_fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'region', 'group', 'tenant', 'asn', 'description', 'time_zone',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-07-28 15:30:29 -04:00
|
|
|
|
|
|
|
|
2019-03-05 08:10:10 -06:00
|
|
|
class SiteFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
|
2016-08-23 12:05:28 -04:00
|
|
|
model = Site
|
2021-03-01 17:24:30 -05:00
|
|
|
field_order = ['q', 'status', 'region_id', 'tenant_group_id', 'tenant_id']
|
2018-11-27 11:57:29 -05:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2019-01-09 13:44:39 -05:00
|
|
|
status = forms.MultipleChoiceField(
|
2019-11-21 22:54:01 -05:00
|
|
|
choices=SiteStatusChoices,
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
2018-03-07 14:16:38 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2019-01-03 16:59:49 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2017-02-28 12:11:43 -05:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
group_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label=_('Group')
|
|
|
|
)
|
2020-01-14 08:22:27 +00:00
|
|
|
tag = TagFilterField(model)
|
2020-01-13 20:16:13 +00:00
|
|
|
|
2016-07-26 17:28:46 -04:00
|
|
|
|
2016-03-30 12:26:37 -04:00
|
|
|
#
|
2021-03-03 13:30:33 -05:00
|
|
|
# Locations
|
2016-03-30 12:26:37 -04:00
|
|
|
#
|
|
|
|
|
2021-03-03 13:30:33 -05:00
|
|
|
class LocationForm(BootstrapMixin, CustomFieldModelForm):
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
site = DynamicModelChoiceField(
|
2020-11-04 15:27:41 -05:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2020-03-11 14:40:29 -04:00
|
|
|
)
|
|
|
|
parent = DynamicModelChoiceField(
|
2021-03-03 13:30:33 -05:00
|
|
|
queryset=Location.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
2016-05-20 15:32:17 -04:00
|
|
|
slug = SlugField()
|
2016-05-11 13:30:39 -04:00
|
|
|
|
|
|
|
class Meta:
|
2021-03-03 13:30:33 -05:00
|
|
|
model = Location
|
2020-02-11 10:43:22 -05:00
|
|
|
fields = (
|
2021-03-08 13:28:53 -05:00
|
|
|
'region', 'site_group', 'site', 'parent', 'name', 'slug', 'description',
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
2016-05-11 13:30:39 -04:00
|
|
|
|
|
|
|
|
2021-03-03 13:30:33 -05:00
|
|
|
class LocationCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
site = CSVModelChoiceField(
|
2017-07-18 02:04:54 +03:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned site'
|
2017-07-18 02:04:54 +03:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
parent = CSVModelChoiceField(
|
2021-03-03 13:30:33 -05:00
|
|
|
queryset=Location.objects.all(),
|
2020-03-11 14:40:29 -04:00
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Parent rack group',
|
2020-03-11 14:40:29 -04:00
|
|
|
error_messages={
|
|
|
|
'invalid_choice': 'Rack group not found.',
|
|
|
|
}
|
|
|
|
)
|
2017-07-18 02:04:54 +03:00
|
|
|
|
|
|
|
class Meta:
|
2021-03-03 13:30:33 -05:00
|
|
|
model = Location
|
|
|
|
fields = Location.csv_headers
|
2017-07-18 02:04:54 +03:00
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class LocationBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
site = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['parent', 'description']
|
|
|
|
|
|
|
|
|
2021-03-03 13:30:33 -05:00
|
|
|
class LocationFilterForm(BootstrapMixin, forms.Form):
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-01-03 13:52:50 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-01-03 13:52:50 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=Site.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2020-03-11 14:40:29 -04:00
|
|
|
)
|
|
|
|
parent = DynamicModelMultipleChoiceField(
|
2021-03-03 13:30:33 -05:00
|
|
|
queryset=Location.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id',
|
|
|
|
'site_id': '$site_id',
|
|
|
|
},
|
|
|
|
label=_('Parent')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2016-03-30 12:26:37 -04:00
|
|
|
|
|
|
|
|
2016-08-10 11:52:27 -04:00
|
|
|
#
|
|
|
|
# Rack roles
|
|
|
|
#
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class RackRoleForm(BootstrapMixin, CustomFieldModelForm):
|
2016-08-10 11:52:27 -04:00
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RackRole
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2019-12-10 12:53:28 -05:00
|
|
|
'name', 'slug', 'color', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-08-10 11:52:27 -04:00
|
|
|
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class RackRoleCSVForm(CustomFieldModelCSVForm):
|
2017-10-09 15:28:46 -04:00
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RackRole
|
2018-02-02 14:26:16 -05:00
|
|
|
fields = RackRole.csv_headers
|
2017-10-09 15:28:46 -04:00
|
|
|
help_texts = {
|
2020-05-01 15:40:34 -04:00
|
|
|
'color': mark_safe('RGB color in hexadecimal (e.g. <code>00ff00</code>)'),
|
2017-10-09 15:28:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class RackRoleBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=RackRole.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
color = forms.CharField(
|
|
|
|
max_length=6, # RGB color code
|
|
|
|
required=False,
|
|
|
|
widget=ColorSelect()
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['color', 'description']
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Racks
|
|
|
|
#
|
|
|
|
|
2020-01-29 10:49:02 -05:00
|
|
|
class RackForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
2020-11-04 15:27:41 -05:00
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-11-04 15:27:41 -05:00
|
|
|
site = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2017-05-11 16:24:57 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-11-17 16:25:20 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
role = DynamicModelChoiceField(
|
|
|
|
queryset=RackRole.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
comments = CommentField()
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Rack
|
2017-05-11 16:24:57 -04:00
|
|
|
fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'region', 'site_group', 'site', 'location', 'name', 'facility_id', 'tenant_group', 'tenant', 'status',
|
|
|
|
'role', 'serial', 'asset_tag', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth',
|
|
|
|
'outer_unit', 'comments', 'tags',
|
2017-05-11 16:24:57 -04:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
help_texts = {
|
|
|
|
'site': "The site at which the rack exists",
|
|
|
|
'name': "Organizational rack name",
|
|
|
|
'facility_id': "The unique rack ID assigned by the facility",
|
|
|
|
'u_height': "Height in rack units",
|
|
|
|
}
|
|
|
|
widgets = {
|
2019-01-04 14:41:36 -05:00
|
|
|
'status': StaticSelect2(),
|
|
|
|
'type': StaticSelect2(),
|
|
|
|
'width': StaticSelect2(),
|
|
|
|
'outer_unit': StaticSelect2(),
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-29 13:53:26 -05:00
|
|
|
class RackCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
site = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Site.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = CSVModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-05-05 16:15:09 -04:00
|
|
|
required=False,
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
tenant = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Tenant.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Name of assigned tenant'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2018-11-01 16:03:42 -04:00
|
|
|
status = CSVChoiceField(
|
2019-11-15 22:03:41 -05:00
|
|
|
choices=RackStatusChoices,
|
2018-11-01 16:03:42 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Operational status'
|
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
role = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=RackRole.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Name of assigned role'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2017-06-07 13:22:06 -04:00
|
|
|
type = CSVChoiceField(
|
2019-11-15 21:28:34 -05:00
|
|
|
choices=RackTypeChoices,
|
2017-06-07 13:22:06 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Rack type'
|
|
|
|
)
|
|
|
|
width = forms.ChoiceField(
|
2019-11-15 21:33:56 -05:00
|
|
|
choices=RackWidthChoices,
|
2017-06-07 13:22:06 -04:00
|
|
|
help_text='Rail-to-rail width (in inches)'
|
|
|
|
)
|
2018-11-02 09:51:17 -04:00
|
|
|
outer_unit = CSVChoiceField(
|
2019-11-25 20:54:24 -05:00
|
|
|
choices=RackDimensionUnitChoices,
|
2018-11-02 09:51:17 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Unit for outer dimensions'
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Rack
|
2018-02-02 14:26:16 -05:00
|
|
|
fields = Rack.csv_headers
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
|
super().__init__(data, *args, **kwargs)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
if data:
|
2018-05-22 15:45:30 -04:00
|
|
|
|
2021-03-03 13:30:33 -05:00
|
|
|
# Limit location queryset by assigned site
|
2020-05-05 16:15:09 -04:00
|
|
|
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
2021-03-03 13:30:33 -05:00
|
|
|
self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
|
2018-05-22 15:45:30 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2018-07-10 10:00:21 -04:00
|
|
|
class RackBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2018-11-01 16:03:42 -04:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
site = DynamicModelChoiceField(
|
2018-11-01 16:03:42 -04:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
tenant = DynamicModelChoiceField(
|
2018-11-01 16:03:42 -04:00
|
|
|
queryset=Tenant.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
|
|
|
status = forms.ChoiceField(
|
2019-11-15 22:03:41 -05:00
|
|
|
choices=add_blank_choice(RackStatusChoices),
|
2018-11-01 16:03:42 -04:00
|
|
|
required=False,
|
2019-01-08 15:35:34 -08:00
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
role = DynamicModelChoiceField(
|
2018-11-01 16:03:42 -04:00
|
|
|
queryset=RackRole.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
|
|
|
serial = forms.CharField(
|
|
|
|
max_length=50,
|
|
|
|
required=False,
|
|
|
|
label='Serial Number'
|
|
|
|
)
|
2018-11-02 09:17:51 -04:00
|
|
|
asset_tag = forms.CharField(
|
|
|
|
max_length=50,
|
|
|
|
required=False
|
|
|
|
)
|
2018-11-01 16:03:42 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:28:34 -05:00
|
|
|
choices=add_blank_choice(RackTypeChoices),
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
|
|
|
width = forms.ChoiceField(
|
2019-11-15 21:33:56 -05:00
|
|
|
choices=add_blank_choice(RackWidthChoices),
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
|
|
|
u_height = forms.IntegerField(
|
|
|
|
required=False,
|
|
|
|
label='Height (U)'
|
|
|
|
)
|
|
|
|
desc_units = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect,
|
|
|
|
label='Descending units'
|
|
|
|
)
|
2018-11-02 09:51:17 -04:00
|
|
|
outer_width = forms.IntegerField(
|
|
|
|
required=False,
|
|
|
|
min_value=1
|
|
|
|
)
|
|
|
|
outer_depth = forms.IntegerField(
|
|
|
|
required=False,
|
|
|
|
min_value=1
|
|
|
|
)
|
|
|
|
outer_unit = forms.ChoiceField(
|
2019-11-25 20:54:24 -05:00
|
|
|
choices=add_blank_choice(RackDimensionUnitChoices),
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2018-11-02 09:51:17 -04:00
|
|
|
)
|
2018-11-01 16:03:42 -04:00
|
|
|
comments = CommentField(
|
2020-01-28 16:09:10 -05:00
|
|
|
widget=SmallTextarea,
|
|
|
|
label='Comments'
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-09-30 16:17:41 -04:00
|
|
|
class Meta:
|
2018-11-02 09:51:17 -04:00
|
|
|
nullable_fields = [
|
2021-03-03 13:30:33 -05:00
|
|
|
'location', 'tenant', 'role', 'serial', 'asset_tag', 'outer_width', 'outer_depth', 'outer_unit', 'comments',
|
2018-11-02 09:51:17 -04:00
|
|
|
]
|
2016-09-30 16:17:41 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2019-03-05 08:10:10 -06:00
|
|
|
class RackFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
|
2016-08-23 12:05:28 -04:00
|
|
|
model = Rack
|
2021-03-03 13:30:33 -05:00
|
|
|
field_order = ['q', 'region_id', 'site_id', 'location_id', 'status', 'role_id', 'tenant_group_id', 'tenant_id']
|
2018-11-27 11:57:29 -05:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-01-03 13:52:50 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-01-03 13:52:50 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=Site.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2017-03-01 13:09:19 -05:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
null_option='None',
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
2021-03-03 13:30:33 -05:00
|
|
|
label=_('Location')
|
2017-03-01 13:09:19 -05:00
|
|
|
)
|
2019-01-09 23:33:08 -05:00
|
|
|
status = forms.MultipleChoiceField(
|
2019-11-15 22:03:41 -05:00
|
|
|
choices=RackStatusChoices,
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
2018-11-01 16:03:42 -04:00
|
|
|
)
|
2020-12-17 15:55:22 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=RackTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
|
|
|
width = forms.MultipleChoiceField(
|
|
|
|
choices=RackWidthChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
role_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=RackRole.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
null_option='None',
|
|
|
|
label=_('Role')
|
2017-03-01 13:09:19 -05:00
|
|
|
)
|
2021-03-24 15:05:19 -04:00
|
|
|
asset_tag = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-01-14 08:22:27 +00:00
|
|
|
tag = TagFilterField(model)
|
2020-01-13 20:16:13 +00:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-01-04 13:30:31 +00:00
|
|
|
#
|
|
|
|
# Rack elevations
|
|
|
|
#
|
|
|
|
|
|
|
|
class RackElevationFilterForm(RackFilterForm):
|
2021-03-03 13:30:33 -05:00
|
|
|
field_order = [
|
|
|
|
'q', 'region_id', 'site_id', 'location_id', 'id', 'status', 'role_id', 'tenant_group_id', 'tenant_id',
|
|
|
|
]
|
2020-02-11 09:26:39 -05:00
|
|
|
id = DynamicModelMultipleChoiceField(
|
2020-01-04 13:30:31 +00:00
|
|
|
queryset=Rack.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Rack'),
|
2020-01-04 13:30:31 +00:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id',
|
2021-03-03 13:30:33 -05:00
|
|
|
'location_id': '$location_id',
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2020-01-04 13:30:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-02-16 13:46:58 -05:00
|
|
|
#
|
|
|
|
# Rack reservations
|
|
|
|
#
|
|
|
|
|
2020-09-17 14:22:14 -04:00
|
|
|
class RackReservationForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-06-12 15:11:27 -04:00
|
|
|
site = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2020-03-12 17:43:11 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-06-12 15:11:27 -04:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-06-12 15:11:27 -04:00
|
|
|
rack = DynamicModelChoiceField(
|
2020-08-12 12:36:53 -04:00
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site',
|
2021-03-29 16:23:26 -04:00
|
|
|
'location_id': '$location',
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2020-06-12 15:11:27 -04:00
|
|
|
)
|
|
|
|
units = NumericArrayField(
|
|
|
|
base_field=forms.IntegerField(),
|
|
|
|
help_text="Comma-separated list of numeric unit IDs. A range may be specified using a hyphen."
|
|
|
|
)
|
2018-11-27 11:57:29 -05:00
|
|
|
user = forms.ModelChoiceField(
|
|
|
|
queryset=User.objects.order_by(
|
|
|
|
'username'
|
2019-01-08 15:35:34 -08:00
|
|
|
),
|
|
|
|
widget=StaticSelect2()
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2020-06-10 14:55:46 -04:00
|
|
|
required=False
|
|
|
|
)
|
2017-02-16 13:46:58 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RackReservation
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'region', 'site_group', 'site', 'location', 'rack', 'units', 'user', 'tenant_group', 'tenant',
|
|
|
|
'description', 'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2021-02-25 13:51:48 -05:00
|
|
|
fieldsets = (
|
2021-03-03 13:30:33 -05:00
|
|
|
('Reservation', ('region', 'site', 'location', 'rack', 'units', 'user', 'description', 'tags')),
|
2021-02-25 13:51:48 -05:00
|
|
|
('Tenancy', ('tenant_group', 'tenant')),
|
|
|
|
)
|
2017-02-16 13:46:58 -05:00
|
|
|
|
|
|
|
|
2020-12-29 12:43:52 -05:00
|
|
|
class RackReservationCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
site = CSVModelChoiceField(
|
2020-03-06 17:14:26 -05:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Parent site'
|
2020-03-06 17:14:26 -05:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = CSVModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-05-05 16:15:09 -04:00
|
|
|
to_field_name='name',
|
2020-03-06 17:14:26 -05:00
|
|
|
required=False,
|
2021-03-03 13:30:33 -05:00
|
|
|
help_text="Rack's location (if any)"
|
2020-03-06 17:14:26 -05:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
rack = CSVModelChoiceField(
|
2020-05-05 16:15:09 -04:00
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Rack'
|
2020-03-06 17:14:26 -05:00
|
|
|
)
|
2020-03-09 12:46:12 -04:00
|
|
|
units = SimpleArrayField(
|
|
|
|
base_field=forms.IntegerField(),
|
2020-03-06 17:14:26 -05:00
|
|
|
required=True,
|
2020-03-09 12:46:12 -04:00
|
|
|
help_text='Comma-separated list of individual unit numbers'
|
2020-03-06 17:14:26 -05:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
tenant = CSVModelChoiceField(
|
2020-03-06 17:14:26 -05:00
|
|
|
queryset=Tenant.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned tenant'
|
2020-03-06 17:14:26 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RackReservation
|
2021-03-03 13:30:33 -05:00
|
|
|
fields = ('site', 'location', 'rack', 'units', 'tenant', 'description')
|
2020-03-06 17:14:26 -05:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
|
super().__init__(data, *args, **kwargs)
|
2020-03-06 17:14:26 -05:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
if data:
|
2020-03-06 17:14:26 -05:00
|
|
|
|
2021-03-03 13:30:33 -05:00
|
|
|
# Limit location queryset by assigned site
|
2020-05-05 16:15:09 -04:00
|
|
|
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
2021-03-03 13:30:33 -05:00
|
|
|
self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
|
2020-03-06 17:14:26 -05:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
# Limit rack queryset by assigned site and group
|
|
|
|
params = {
|
|
|
|
f"site__{self.fields['site'].to_field_name}": data.get('site'),
|
2021-03-03 13:30:33 -05:00
|
|
|
f"location__{self.fields['location'].to_field_name}": data.get('location'),
|
2020-05-05 16:15:09 -04:00
|
|
|
}
|
|
|
|
self.fields['rack'].queryset = self.fields['rack'].queryset.filter(**params)
|
2020-03-06 17:14:26 -05:00
|
|
|
|
|
|
|
|
2020-12-29 11:55:31 -05:00
|
|
|
class RackReservationBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2018-11-27 11:57:29 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=RackReservation.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
|
|
|
user = forms.ModelChoiceField(
|
|
|
|
queryset=User.objects.order_by(
|
|
|
|
'username'
|
|
|
|
),
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
tenant = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Tenant.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=100,
|
|
|
|
required=False
|
|
|
|
)
|
2017-10-31 13:52:35 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = []
|
|
|
|
|
|
|
|
|
2021-03-31 17:02:21 -04:00
|
|
|
class RackReservationFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
|
2020-06-10 14:55:46 -04:00
|
|
|
model = RackReservation
|
2021-03-03 13:30:33 -05:00
|
|
|
field_order = ['q', 'region_id', 'site_id', 'location_id', 'user_id', 'tenant_group_id', 'tenant_id']
|
2019-05-09 14:32:49 -04:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2019-05-09 14:32:49 -04:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-11-04 15:27:41 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-11-04 15:27:41 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-05-09 14:32:49 -04:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Region')
|
2019-05-09 14:32:49 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Location.objects.prefetch_related('site'),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2021-03-03 13:30:33 -05:00
|
|
|
label='Location',
|
2020-08-12 09:47:13 -04:00
|
|
|
null_option='None'
|
2019-05-09 14:32:49 -04:00
|
|
|
)
|
2020-12-18 12:09:41 -05:00
|
|
|
user_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=User.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label='User',
|
|
|
|
widget=APISelectMultiple(
|
|
|
|
api_url='/api/users/users/',
|
|
|
|
)
|
|
|
|
)
|
2020-06-10 14:55:46 -04:00
|
|
|
tag = TagFilterField(model)
|
2019-05-09 14:32:49 -04:00
|
|
|
|
|
|
|
|
2016-05-13 15:22:31 -04:00
|
|
|
#
|
|
|
|
# Manufacturers
|
|
|
|
#
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class ManufacturerForm(BootstrapMixin, CustomFieldModelForm):
|
2016-05-20 15:32:17 -04:00
|
|
|
slug = SlugField()
|
2016-05-13 15:22:31 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Manufacturer
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-03-13 16:24:37 -04:00
|
|
|
'name', 'slug', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-05-13 15:22:31 -04:00
|
|
|
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class ManufacturerCSVForm(CustomFieldModelCSVForm):
|
2018-11-27 11:57:29 -05:00
|
|
|
|
2017-07-18 02:37:28 +03:00
|
|
|
class Meta:
|
|
|
|
model = Manufacturer
|
2018-02-02 14:26:16 -05:00
|
|
|
fields = Manufacturer.csv_headers
|
2017-07-18 02:37:28 +03:00
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class ManufacturerBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['description']
|
|
|
|
|
|
|
|
|
2016-03-04 14:39:39 -05:00
|
|
|
#
|
|
|
|
# Device types
|
|
|
|
#
|
|
|
|
|
2020-01-29 10:49:02 -05:00
|
|
|
class DeviceTypeForm(BootstrapMixin, CustomFieldModelForm):
|
2020-02-11 10:43:22 -05:00
|
|
|
manufacturer = DynamicModelChoiceField(
|
2020-03-16 14:08:48 -04:00
|
|
|
queryset=Manufacturer.objects.all()
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
2018-11-27 11:57:29 -05:00
|
|
|
slug = SlugField(
|
|
|
|
slug_source='model'
|
|
|
|
)
|
2019-09-18 15:39:26 -04:00
|
|
|
comments = CommentField()
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-04 14:39:39 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceType
|
2018-05-08 16:28:26 -04:00
|
|
|
fields = [
|
2020-02-20 12:11:59 -05:00
|
|
|
'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role',
|
|
|
|
'front_image', 'rear_image', 'comments', 'tags',
|
2018-05-08 16:28:26 -04:00
|
|
|
]
|
2021-02-25 13:51:48 -05:00
|
|
|
fieldsets = (
|
|
|
|
('Device Type', (
|
2021-02-25 14:03:14 -05:00
|
|
|
'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'tags',
|
2021-02-25 13:51:48 -05:00
|
|
|
)),
|
|
|
|
('Images', ('front_image', 'rear_image')),
|
|
|
|
)
|
2019-01-04 14:41:36 -05:00
|
|
|
widgets = {
|
2020-12-11 09:27:00 -05:00
|
|
|
'subdevice_role': StaticSelect2(),
|
|
|
|
# Exclude SVG images (unsupported by PIL)
|
2021-03-10 17:00:35 -05:00
|
|
|
'front_image': forms.ClearableFileInput(attrs={
|
2020-12-11 09:27:00 -05:00
|
|
|
'accept': 'image/bmp,image/gif,image/jpeg,image/png,image/tiff'
|
|
|
|
}),
|
2021-03-10 17:00:35 -05:00
|
|
|
'rear_image': forms.ClearableFileInput(attrs={
|
2020-12-11 09:27:00 -05:00
|
|
|
'accept': 'image/bmp,image/gif,image/jpeg,image/png,image/tiff'
|
|
|
|
})
|
2019-01-04 14:41:36 -05:00
|
|
|
}
|
2017-07-18 04:50:24 +03:00
|
|
|
|
|
|
|
|
2019-09-24 15:58:23 -04:00
|
|
|
class DeviceTypeImportForm(BootstrapMixin, forms.ModelForm):
|
2017-07-18 04:50:24 +03:00
|
|
|
manufacturer = forms.ModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
2019-09-05 17:23:56 -04:00
|
|
|
to_field_name='name'
|
2017-07-18 04:50:24 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceType
|
2019-09-05 17:23:56 -04:00
|
|
|
fields = [
|
|
|
|
'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role',
|
2020-05-26 01:17:10 -04:00
|
|
|
'comments',
|
2019-09-05 17:23:56 -04:00
|
|
|
]
|
2016-03-04 14:39:39 -05:00
|
|
|
|
|
|
|
|
2018-07-10 10:00:21 -04:00
|
|
|
class DeviceTypeBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2018-11-27 11:57:29 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=DeviceType.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
manufacturer = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Manufacturer.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
u_height = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False
|
2017-07-11 14:36:59 -04:00
|
|
|
)
|
2018-11-27 11:57:29 -05:00
|
|
|
is_full_depth = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect(),
|
|
|
|
label='Is full depth'
|
2017-04-28 12:32:27 -04:00
|
|
|
)
|
2016-03-04 14:39:39 -05:00
|
|
|
|
2016-11-10 15:15:55 -05:00
|
|
|
class Meta:
|
|
|
|
nullable_fields = []
|
|
|
|
|
2016-03-04 14:39:39 -05:00
|
|
|
|
2016-12-16 10:54:45 -05:00
|
|
|
class DeviceTypeFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|
|
|
model = DeviceType
|
2018-11-27 11:57:29 -05:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
manufacturer_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=Manufacturer.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Manufacturer')
|
2017-03-01 13:09:19 -05:00
|
|
|
)
|
2019-11-18 22:03:25 -05:00
|
|
|
subdevice_role = forms.MultipleChoiceField(
|
|
|
|
choices=add_blank_choice(SubdeviceRoleChoices),
|
2018-11-02 10:45:31 -04:00
|
|
|
required=False,
|
2019-11-18 22:03:25 -05:00
|
|
|
widget=StaticSelect2Multiple()
|
2017-03-22 17:29:47 -04:00
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
console_ports = forms.NullBooleanField(
|
2018-11-02 10:45:31 -04:00
|
|
|
required=False,
|
2018-11-15 00:42:01 -05:00
|
|
|
label='Has console ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2017-03-22 17:29:47 -04:00
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
console_server_ports = forms.NullBooleanField(
|
2018-11-02 10:45:31 -04:00
|
|
|
required=False,
|
2018-11-15 00:42:01 -05:00
|
|
|
label='Has console server ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-02 10:45:31 -04:00
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
power_ports = forms.NullBooleanField(
|
2018-11-02 10:45:31 -04:00
|
|
|
required=False,
|
2018-11-15 00:42:01 -05:00
|
|
|
label='Has power ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-02 10:45:31 -04:00
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
power_outlets = forms.NullBooleanField(
|
2018-11-02 10:45:31 -04:00
|
|
|
required=False,
|
2018-11-15 00:42:01 -05:00
|
|
|
label='Has power outlets',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-02 10:45:31 -04:00
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
interfaces = forms.NullBooleanField(
|
2018-11-02 10:45:31 -04:00
|
|
|
required=False,
|
2018-11-15 00:42:01 -05:00
|
|
|
label='Has interfaces',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-02 10:45:31 -04:00
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
pass_through_ports = forms.NullBooleanField(
|
2018-11-02 10:45:31 -04:00
|
|
|
required=False,
|
2018-11-15 00:42:01 -05:00
|
|
|
label='Has pass-through ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2017-03-22 17:29:47 -04:00
|
|
|
)
|
2020-01-14 08:22:27 +00:00
|
|
|
tag = TagFilterField(model)
|
2020-01-13 20:16:13 +00:00
|
|
|
|
2016-03-04 14:39:39 -05:00
|
|
|
|
2016-03-04 16:41:24 -05:00
|
|
|
#
|
|
|
|
# Device component templates
|
|
|
|
#
|
|
|
|
|
2021-03-01 13:37:53 -05:00
|
|
|
class ComponentTemplateCreateForm(BootstrapMixin, ComponentForm):
|
2020-06-18 11:59:24 -04:00
|
|
|
"""
|
2020-07-14 15:51:13 -04:00
|
|
|
Base form for the creation of device component templates (subclassed from ComponentTemplateModel).
|
2020-06-18 11:59:24 -04:00
|
|
|
"""
|
|
|
|
manufacturer = DynamicModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
2020-11-17 16:30:58 -05:00
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'device_types': 'device_type'
|
|
|
|
}
|
2020-06-18 11:59:24 -04:00
|
|
|
)
|
|
|
|
device_type = DynamicModelChoiceField(
|
|
|
|
queryset=DeviceType.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'manufacturer_id': '$manufacturer'
|
|
|
|
}
|
2020-06-18 11:59:24 -04:00
|
|
|
)
|
2020-06-30 15:12:53 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-06-18 11:59:24 -04:00
|
|
|
|
|
|
|
|
2016-12-21 14:15:18 -05:00
|
|
|
class ConsolePortTemplateForm(BootstrapMixin, forms.ModelForm):
|
2016-03-04 16:41:24 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsolePortTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-30 15:12:53 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-12-21 17:20:27 -05:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
|
|
|
}
|
2016-03-04 16:41:24 -05:00
|
|
|
|
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class ConsolePortTemplateCreateForm(ComponentTemplateCreateForm):
|
2019-10-30 14:25:55 -04:00
|
|
|
type = forms.ChoiceField(
|
2020-02-06 13:13:40 -05:00
|
|
|
choices=add_blank_choice(ConsolePortTypeChoices),
|
2019-10-30 14:25:55 -04:00
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'description')
|
2016-03-04 16:41:24 -05:00
|
|
|
|
2016-12-21 17:20:27 -05:00
|
|
|
|
2020-02-06 15:29:10 -05:00
|
|
|
class ConsolePortTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=ConsolePortTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-06-30 16:15:17 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
type = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(ConsolePortTypeChoices),
|
2020-02-06 15:51:51 -05:00
|
|
|
required=False,
|
2020-02-06 15:29:10 -05:00
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 16:15:17 -04:00
|
|
|
nullable_fields = ('label', 'type', 'description')
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
|
2016-12-21 17:20:27 -05:00
|
|
|
class ConsoleServerPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
|
|
|
|
2016-03-04 16:41:24 -05:00
|
|
|
class Meta:
|
|
|
|
model = ConsoleServerPortTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-30 15:12:53 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-12-21 17:20:27 -05:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
|
|
|
}
|
2016-03-04 16:41:24 -05:00
|
|
|
|
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class ConsoleServerPortTemplateCreateForm(ComponentTemplateCreateForm):
|
2019-10-30 14:25:55 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=add_blank_choice(ConsolePortTypeChoices),
|
2019-10-30 14:25:55 -04:00
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'description')
|
2016-03-04 16:41:24 -05:00
|
|
|
|
2016-12-21 17:20:27 -05:00
|
|
|
|
2020-02-06 15:29:10 -05:00
|
|
|
class ConsoleServerPortTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=ConsoleServerPortTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-06-30 16:15:17 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
type = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(ConsolePortTypeChoices),
|
2020-02-06 15:51:51 -05:00
|
|
|
required=False,
|
2020-02-06 15:29:10 -05:00
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2020-06-30 15:12:53 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 16:15:17 -04:00
|
|
|
nullable_fields = ('label', 'type', 'description')
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
|
2016-12-21 17:20:27 -05:00
|
|
|
class PowerPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
|
|
|
|
2016-03-04 16:41:24 -05:00
|
|
|
class Meta:
|
|
|
|
model = PowerPortTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-30 15:12:53 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-12-21 17:20:27 -05:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
|
|
|
}
|
2016-03-04 16:41:24 -05:00
|
|
|
|
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class PowerPortTemplateCreateForm(ComponentTemplateCreateForm):
|
2019-11-06 15:30:54 -05:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=add_blank_choice(PowerPortTypeChoices),
|
2019-11-06 15:30:54 -05:00
|
|
|
required=False
|
|
|
|
)
|
2019-08-02 09:56:02 -04:00
|
|
|
maximum_draw = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False,
|
2019-12-11 21:12:18 -05:00
|
|
|
help_text="Maximum power draw (watts)"
|
2019-08-02 09:56:02 -04:00
|
|
|
)
|
|
|
|
allocated_draw = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False,
|
2019-12-11 21:12:18 -05:00
|
|
|
help_text="Allocated power draw (watts)"
|
2019-08-02 09:56:02 -04:00
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = (
|
|
|
|
'manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'maximum_draw', 'allocated_draw',
|
|
|
|
'description',
|
|
|
|
)
|
2016-03-04 16:41:24 -05:00
|
|
|
|
2016-12-21 17:20:27 -05:00
|
|
|
|
2020-02-06 15:29:10 -05:00
|
|
|
class PowerPortTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=PowerPortTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-06-30 16:15:17 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
type = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(PowerPortTypeChoices),
|
2020-02-06 15:51:51 -05:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2020-02-06 15:29:10 -05:00
|
|
|
)
|
|
|
|
maximum_draw = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False,
|
|
|
|
help_text="Maximum power draw (watts)"
|
|
|
|
)
|
|
|
|
allocated_draw = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False,
|
|
|
|
help_text="Allocated power draw (watts)"
|
|
|
|
)
|
2020-06-30 15:12:53 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 16:15:17 -04:00
|
|
|
nullable_fields = ('label', 'type', 'maximum_draw', 'allocated_draw', 'description')
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
|
2016-12-21 17:20:27 -05:00
|
|
|
class PowerOutletTemplateForm(BootstrapMixin, forms.ModelForm):
|
|
|
|
|
2016-03-04 16:41:24 -05:00
|
|
|
class Meta:
|
|
|
|
model = PowerOutletTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-30 15:12:53 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-12-21 17:20:27 -05:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
|
|
|
}
|
2016-03-04 16:41:24 -05:00
|
|
|
|
2019-10-07 17:08:51 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit power_port choices to current DeviceType
|
|
|
|
if hasattr(self.instance, 'device_type'):
|
|
|
|
self.fields['power_port'].queryset = PowerPortTemplate.objects.filter(
|
|
|
|
device_type=self.instance.device_type
|
|
|
|
)
|
|
|
|
|
2019-06-21 16:24:12 -04:00
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class PowerOutletTemplateCreateForm(ComponentTemplateCreateForm):
|
2019-11-06 15:30:54 -05:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=add_blank_choice(PowerOutletTypeChoices),
|
2019-11-06 15:30:54 -05:00
|
|
|
required=False
|
|
|
|
)
|
2019-06-21 16:24:12 -04:00
|
|
|
power_port = forms.ModelChoiceField(
|
|
|
|
queryset=PowerPortTemplate.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
feed_leg = forms.ChoiceField(
|
2019-11-27 21:29:58 -05:00
|
|
|
choices=add_blank_choice(PowerOutletFeedLegChoices),
|
2019-06-21 16:24:12 -04:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = (
|
|
|
|
'manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'power_port', 'feed_leg',
|
|
|
|
'description',
|
|
|
|
)
|
2019-06-21 16:24:12 -04:00
|
|
|
|
2019-04-10 14:16:16 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit power_port choices to current DeviceType
|
2020-02-06 14:39:36 -05:00
|
|
|
device_type = DeviceType.objects.get(
|
|
|
|
pk=self.initial.get('device_type') or self.data.get('device_type')
|
|
|
|
)
|
2019-04-10 14:16:16 -04:00
|
|
|
self.fields['power_port'].queryset = PowerPortTemplate.objects.filter(
|
2020-02-06 14:39:36 -05:00
|
|
|
device_type=device_type
|
2019-04-10 14:16:16 -04:00
|
|
|
)
|
|
|
|
|
2016-03-04 16:41:24 -05:00
|
|
|
|
2020-02-06 15:29:10 -05:00
|
|
|
class PowerOutletTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=PowerOutletTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-06-15 13:18:26 -04:00
|
|
|
device_type = forms.ModelChoiceField(
|
|
|
|
queryset=DeviceType.objects.all(),
|
|
|
|
required=False,
|
|
|
|
disabled=True,
|
|
|
|
widget=forms.HiddenInput()
|
|
|
|
)
|
2020-06-30 16:15:17 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
type = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(PowerOutletTypeChoices),
|
2020-02-06 15:51:51 -05:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2020-02-06 15:29:10 -05:00
|
|
|
)
|
2020-06-15 13:18:26 -04:00
|
|
|
power_port = forms.ModelChoiceField(
|
|
|
|
queryset=PowerPortTemplate.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
feed_leg = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(PowerOutletFeedLegChoices),
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2020-06-30 15:12:53 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 16:15:17 -04:00
|
|
|
nullable_fields = ('label', 'type', 'power_port', 'feed_leg', 'description')
|
2020-06-15 13:18:26 -04:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit power_port queryset to PowerPortTemplates which belong to the parent DeviceType
|
|
|
|
if 'device_type' in self.initial:
|
|
|
|
device_type = DeviceType.objects.filter(pk=self.initial['device_type']).first()
|
|
|
|
self.fields['power_port'].queryset = PowerPortTemplate.objects.filter(device_type=device_type)
|
|
|
|
else:
|
|
|
|
self.fields['power_port'].choices = ()
|
|
|
|
self.fields['power_port'].widget.attrs['disabled'] = True
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
|
2016-12-21 17:20:27 -05:00
|
|
|
class InterfaceTemplateForm(BootstrapMixin, forms.ModelForm):
|
|
|
|
|
2016-03-04 16:41:24 -05:00
|
|
|
class Meta:
|
|
|
|
model = InterfaceTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-30 15:12:53 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'mgmt_only', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-12-21 17:20:27 -05:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
2019-04-12 13:42:56 -04:00
|
|
|
'type': StaticSelect2(),
|
2016-12-21 17:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class InterfaceTemplateCreateForm(ComponentTemplateCreateForm):
|
2019-04-12 13:42:56 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-21 22:11:02 -05:00
|
|
|
choices=InterfaceTypeChoices,
|
2019-01-04 14:41:36 -05:00
|
|
|
widget=StaticSelect2()
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
mgmt_only = forms.BooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Management only'
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'mgmt_only', 'description')
|
2016-03-04 16:41:24 -05:00
|
|
|
|
|
|
|
|
2016-10-19 12:15:54 -04:00
|
|
|
class InterfaceTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
2018-11-27 11:57:29 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=InterfaceTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-06-30 16:15:17 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2019-04-12 13:42:56 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-21 22:11:02 -05:00
|
|
|
choices=add_blank_choice(InterfaceTypeChoices),
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
mgmt_only = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect,
|
|
|
|
label='Management only'
|
|
|
|
)
|
2020-06-30 15:12:53 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2016-10-19 12:15:54 -04:00
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 16:15:17 -04:00
|
|
|
nullable_fields = ('label', 'description')
|
2016-10-19 12:15:54 -04:00
|
|
|
|
|
|
|
|
2018-10-25 12:08:13 -04:00
|
|
|
class FrontPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
class Meta:
|
2018-10-25 12:08:13 -04:00
|
|
|
model = FrontPortTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-07-02 10:46:02 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2018-10-03 14:04:16 -04:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
2019-01-04 14:41:36 -05:00
|
|
|
'rear_port': StaticSelect2(),
|
2018-10-03 14:04:16 -04:00
|
|
|
}
|
|
|
|
|
2019-10-07 17:08:51 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit rear_port choices to current DeviceType
|
|
|
|
if hasattr(self.instance, 'device_type'):
|
|
|
|
self.fields['rear_port'].queryset = RearPortTemplate.objects.filter(
|
|
|
|
device_type=self.instance.device_type
|
|
|
|
)
|
|
|
|
|
2018-10-03 14:04:16 -04:00
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class FrontPortTemplateCreateForm(ComponentTemplateCreateForm):
|
2018-10-03 14:04:16 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-25 19:39:25 -05:00
|
|
|
choices=PortTypeChoices,
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2()
|
2018-10-03 14:04:16 -04:00
|
|
|
)
|
|
|
|
rear_port_set = forms.MultipleChoiceField(
|
|
|
|
choices=[],
|
|
|
|
label='Rear ports',
|
2019-01-04 14:41:36 -05:00
|
|
|
help_text='Select one rear port assignment for each front port being created.',
|
2018-10-03 14:04:16 -04:00
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = (
|
|
|
|
'manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'rear_port_set', 'description',
|
|
|
|
)
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2018-10-03 14:04:16 -04:00
|
|
|
|
2020-02-06 14:39:36 -05:00
|
|
|
device_type = DeviceType.objects.get(
|
|
|
|
pk=self.initial.get('device_type') or self.data.get('device_type')
|
|
|
|
)
|
2020-02-06 13:13:40 -05:00
|
|
|
|
2018-10-03 14:04:16 -04:00
|
|
|
# Determine which rear port positions are occupied. These will be excluded from the list of available mappings.
|
|
|
|
occupied_port_positions = [
|
|
|
|
(front_port.rear_port_id, front_port.rear_port_position)
|
2020-07-02 13:07:32 -04:00
|
|
|
for front_port in device_type.frontporttemplates.all()
|
2018-10-03 14:04:16 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
# Populate rear port choices
|
|
|
|
choices = []
|
2020-02-06 13:13:40 -05:00
|
|
|
rear_ports = RearPortTemplate.objects.filter(device_type=device_type)
|
2018-10-03 14:04:16 -04:00
|
|
|
for rear_port in rear_ports:
|
|
|
|
for i in range(1, rear_port.positions + 1):
|
|
|
|
if (rear_port.pk, i) not in occupied_port_positions:
|
|
|
|
choices.append(
|
|
|
|
('{}:{}'.format(rear_port.pk, i), '{}:{}'.format(rear_port.name, i))
|
|
|
|
)
|
|
|
|
self.fields['rear_port_set'].choices = choices
|
|
|
|
|
|
|
|
def clean(self):
|
2020-12-28 12:54:42 -05:00
|
|
|
super().clean()
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
# Validate that the number of ports being created equals the number of selected (rear port, position) tuples
|
|
|
|
front_port_count = len(self.cleaned_data['name_pattern'])
|
|
|
|
rear_port_count = len(self.cleaned_data['rear_port_set'])
|
|
|
|
if front_port_count != rear_port_count:
|
|
|
|
raise forms.ValidationError({
|
|
|
|
'rear_port_set': 'The provided name pattern will create {} ports, however {} rear port assignments '
|
|
|
|
'were selected. These counts must match.'.format(front_port_count, rear_port_count)
|
|
|
|
})
|
|
|
|
|
|
|
|
def get_iterative_data(self, iteration):
|
|
|
|
|
|
|
|
# Assign rear port and position from selected set
|
|
|
|
rear_port, position = self.cleaned_data['rear_port_set'][iteration].split(':')
|
|
|
|
|
|
|
|
return {
|
|
|
|
'rear_port': int(rear_port),
|
|
|
|
'rear_port_position': int(position),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-06 15:29:10 -05:00
|
|
|
class FrontPortTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=FrontPortTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-07-02 10:46:02 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
type = forms.ChoiceField(
|
2020-02-06 15:51:51 -05:00
|
|
|
choices=add_blank_choice(PortTypeChoices),
|
|
|
|
required=False,
|
2020-02-06 15:29:10 -05:00
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2020-06-30 15:12:53 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 15:12:53 -04:00
|
|
|
nullable_fields = ('description',)
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
|
2018-10-25 12:08:13 -04:00
|
|
|
class RearPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
class Meta:
|
2018-10-25 12:08:13 -04:00
|
|
|
model = RearPortTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-07-02 10:46:02 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'positions', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2018-10-03 14:04:16 -04:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
2019-01-04 14:41:36 -05:00
|
|
|
'type': StaticSelect2(),
|
2018-10-03 14:04:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class RearPortTemplateCreateForm(ComponentTemplateCreateForm):
|
2018-10-03 14:04:16 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-25 19:39:25 -05:00
|
|
|
choices=PortTypeChoices,
|
2019-01-04 14:41:36 -05:00
|
|
|
widget=StaticSelect2(),
|
2018-10-03 14:04:16 -04:00
|
|
|
)
|
|
|
|
positions = forms.IntegerField(
|
2020-01-24 14:21:59 -05:00
|
|
|
min_value=REARPORT_POSITIONS_MIN,
|
|
|
|
max_value=REARPORT_POSITIONS_MAX,
|
2018-10-03 14:04:16 -04:00
|
|
|
initial=1,
|
|
|
|
help_text='The number of front ports which may be mapped to each rear port'
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'positions', 'description')
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
|
2020-02-06 15:29:10 -05:00
|
|
|
class RearPortTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=RearPortTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-07-02 10:46:02 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
type = forms.ChoiceField(
|
2020-02-06 15:51:51 -05:00
|
|
|
choices=add_blank_choice(PortTypeChoices),
|
|
|
|
required=False,
|
2020-02-06 15:29:10 -05:00
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2020-06-30 15:12:53 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 15:12:53 -04:00
|
|
|
nullable_fields = ('description',)
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
|
2016-12-21 14:15:18 -05:00
|
|
|
class DeviceBayTemplateForm(BootstrapMixin, forms.ModelForm):
|
2016-07-01 17:12:43 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceBayTemplate
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-30 15:12:53 -04:00
|
|
|
'device_type', 'name', 'label', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-12-21 17:20:27 -05:00
|
|
|
widgets = {
|
|
|
|
'device_type': forms.HiddenInput(),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 11:59:24 -04:00
|
|
|
class DeviceBayTemplateCreateForm(ComponentTemplateCreateForm):
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'description')
|
2016-07-01 17:12:43 -04:00
|
|
|
|
|
|
|
|
2020-06-30 15:22:30 -04:00
|
|
|
class DeviceBayTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=DeviceBayTemplate.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-06-30 16:15:17 -04:00
|
|
|
label = forms.CharField(
|
|
|
|
max_length=64,
|
|
|
|
required=False
|
|
|
|
)
|
2020-06-30 15:22:30 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2020-06-30 16:15:17 -04:00
|
|
|
nullable_fields = ('label', 'description')
|
2020-02-06 15:29:10 -05:00
|
|
|
|
|
|
|
|
2019-09-27 16:51:12 -04:00
|
|
|
#
|
|
|
|
# Component template import forms
|
|
|
|
#
|
|
|
|
|
|
|
|
class ComponentTemplateImportForm(BootstrapMixin, forms.ModelForm):
|
|
|
|
|
|
|
|
def __init__(self, device_type, data=None, *args, **kwargs):
|
|
|
|
|
|
|
|
# Must pass the parent DeviceType on form initialization
|
|
|
|
data.update({
|
|
|
|
'device_type': device_type.pk,
|
|
|
|
})
|
|
|
|
|
|
|
|
super().__init__(data, *args, **kwargs)
|
|
|
|
|
|
|
|
def clean_device_type(self):
|
|
|
|
|
|
|
|
data = self.cleaned_data['device_type']
|
|
|
|
|
|
|
|
# Limit fields referencing other components to the parent DeviceType
|
|
|
|
for field_name, field in self.fields.items():
|
|
|
|
if isinstance(field, forms.ModelChoiceField) and field_name != 'device_type':
|
|
|
|
field.queryset = field.queryset.filter(device_type=data)
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
class ConsolePortTemplateImportForm(ComponentTemplateImportForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsolePortTemplate
|
|
|
|
fields = [
|
2020-06-05 13:59:59 -04:00
|
|
|
'device_type', 'name', 'label', 'type',
|
2019-09-27 16:51:12 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class ConsoleServerPortTemplateImportForm(ComponentTemplateImportForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsoleServerPortTemplate
|
|
|
|
fields = [
|
2020-06-05 13:59:59 -04:00
|
|
|
'device_type', 'name', 'label', 'type',
|
2019-09-27 16:51:12 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class PowerPortTemplateImportForm(ComponentTemplateImportForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerPortTemplate
|
|
|
|
fields = [
|
2020-06-05 13:59:59 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw',
|
2019-09-27 16:51:12 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class PowerOutletTemplateImportForm(ComponentTemplateImportForm):
|
|
|
|
power_port = forms.ModelChoiceField(
|
|
|
|
queryset=PowerPortTemplate.objects.all(),
|
|
|
|
to_field_name='name',
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerOutletTemplate
|
|
|
|
fields = [
|
2020-06-05 13:59:59 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'power_port', 'feed_leg',
|
2019-09-27 16:51:12 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class InterfaceTemplateImportForm(ComponentTemplateImportForm):
|
2019-10-10 23:24:44 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=InterfaceTypeChoices.CHOICES
|
2019-10-10 23:24:44 -04:00
|
|
|
)
|
2019-09-27 16:51:12 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = InterfaceTemplate
|
|
|
|
fields = [
|
2020-06-05 13:59:59 -04:00
|
|
|
'device_type', 'name', 'label', 'type', 'mgmt_only',
|
2019-09-27 16:51:12 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class FrontPortTemplateImportForm(ComponentTemplateImportForm):
|
2019-10-10 23:24:44 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=PortTypeChoices.CHOICES
|
2019-10-10 23:24:44 -04:00
|
|
|
)
|
2019-10-01 16:36:31 -04:00
|
|
|
rear_port = forms.ModelChoiceField(
|
2019-09-27 16:51:12 -04:00
|
|
|
queryset=RearPortTemplate.objects.all(),
|
|
|
|
to_field_name='name',
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = FrontPortTemplate
|
|
|
|
fields = [
|
|
|
|
'device_type', 'name', 'type', 'rear_port', 'rear_port_position',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class RearPortTemplateImportForm(ComponentTemplateImportForm):
|
2019-10-10 23:24:44 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=PortTypeChoices.CHOICES
|
2019-10-10 23:24:44 -04:00
|
|
|
)
|
2019-09-27 16:51:12 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RearPortTemplate
|
|
|
|
fields = [
|
|
|
|
'device_type', 'name', 'type', 'positions',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceBayTemplateImportForm(ComponentTemplateImportForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceBayTemplate
|
|
|
|
fields = [
|
|
|
|
'device_type', 'name',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-05-12 14:38:34 -04:00
|
|
|
#
|
|
|
|
# Device roles
|
|
|
|
#
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class DeviceRoleForm(BootstrapMixin, CustomFieldModelForm):
|
2016-05-20 15:32:17 -04:00
|
|
|
slug = SlugField()
|
2016-05-12 14:38:34 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceRole
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2019-12-10 12:53:28 -05:00
|
|
|
'name', 'slug', 'color', 'vm_role', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-05-12 14:38:34 -04:00
|
|
|
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class DeviceRoleCSVForm(CustomFieldModelCSVForm):
|
2017-10-09 15:28:46 -04:00
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceRole
|
2018-02-02 14:26:16 -05:00
|
|
|
fields = DeviceRole.csv_headers
|
2017-10-09 15:28:46 -04:00
|
|
|
help_texts = {
|
2020-05-01 15:40:34 -04:00
|
|
|
'color': mark_safe('RGB color in hexadecimal (e.g. <code>00ff00</code>)'),
|
2017-10-09 15:28:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class DeviceRoleBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=DeviceRole.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
color = forms.CharField(
|
|
|
|
max_length=6, # RGB color code
|
|
|
|
required=False,
|
|
|
|
widget=ColorSelect()
|
|
|
|
)
|
|
|
|
vm_role = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect,
|
|
|
|
label='VM role'
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['color', 'description']
|
|
|
|
|
|
|
|
|
2016-05-16 11:54:17 -04:00
|
|
|
#
|
|
|
|
# Platforms
|
|
|
|
#
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class PlatformForm(BootstrapMixin, CustomFieldModelForm):
|
2020-02-11 10:43:22 -05:00
|
|
|
manufacturer = DynamicModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
2019-09-06 13:01:27 -05:00
|
|
|
slug = SlugField(
|
|
|
|
max_length=64
|
|
|
|
)
|
2016-05-16 11:54:17 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Platform
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-03-13 16:24:37 -04:00
|
|
|
'name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'description',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2018-06-29 11:21:00 -04:00
|
|
|
widgets = {
|
|
|
|
'napalm_args': SmallTextarea(),
|
|
|
|
}
|
2016-05-16 11:54:17 -04:00
|
|
|
|
|
|
|
|
2021-02-26 11:25:23 -05:00
|
|
|
class PlatformCSVForm(CustomFieldModelCSVForm):
|
2017-10-09 15:28:46 -04:00
|
|
|
slug = SlugField()
|
2020-05-06 09:43:10 -04:00
|
|
|
manufacturer = CSVModelChoiceField(
|
2018-03-06 12:10:02 -05:00
|
|
|
queryset=Manufacturer.objects.all(),
|
2018-04-12 12:45:25 -04:00
|
|
|
required=False,
|
2018-03-06 12:10:02 -05:00
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Limit platform assignments to this manufacturer'
|
2018-03-06 12:10:02 -05:00
|
|
|
)
|
2017-10-09 15:28:46 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Platform
|
2018-02-02 14:26:16 -05:00
|
|
|
fields = Platform.csv_headers
|
2017-10-09 15:28:46 -04:00
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class PlatformBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Platform.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
manufacturer = DynamicModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
napalm_driver = forms.CharField(
|
|
|
|
max_length=50,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
# TODO: Bulk edit support for napalm_args
|
|
|
|
description = forms.CharField(
|
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['manufacturer', 'napalm_driver', 'description']
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Devices
|
|
|
|
#
|
|
|
|
|
2020-01-29 10:49:02 -05:00
|
|
|
class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
2020-08-13 10:45:01 -04:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
2020-11-04 10:15:15 -05:00
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
2020-08-13 10:45:01 -04:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
site = DynamicModelChoiceField(
|
2020-08-13 10:45:01 -04:00
|
|
|
queryset=Site.objects.all(),
|
2021-03-08 13:28:53 -05:00
|
|
|
required=False,
|
2020-08-13 10:45:01 -04:00
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-08-13 10:45:01 -04:00
|
|
|
}
|
2017-05-11 16:24:57 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-09-21 15:26:32 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
2020-11-04 10:15:15 -05:00
|
|
|
},
|
|
|
|
initial_params={
|
|
|
|
'racks': '$rack'
|
2020-09-21 15:26:32 -04:00
|
|
|
}
|
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
rack = DynamicModelChoiceField(
|
2017-05-11 16:24:57 -04:00
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2020-09-21 15:26:32 -04:00
|
|
|
'site_id': '$site',
|
2021-03-03 13:30:33 -05:00
|
|
|
'location_id': 'location',
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2017-05-08 13:55:19 -04:00
|
|
|
)
|
2020-12-23 16:21:26 -05:00
|
|
|
position = forms.IntegerField(
|
2017-05-11 16:24:57 -04:00
|
|
|
required=False,
|
|
|
|
help_text="The lowest-numbered unit occupied by the device",
|
|
|
|
widget=APISelect(
|
2019-12-11 09:45:08 -05:00
|
|
|
api_url='/api/dcim/racks/{{rack}}/elevation/',
|
2020-08-12 13:57:34 -04:00
|
|
|
attrs={
|
|
|
|
'disabled-indicator': 'device',
|
2020-08-12 14:03:58 -04:00
|
|
|
'data-query-param-face': "[\"$face\"]",
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2017-05-11 16:24:57 -04:00
|
|
|
)
|
2017-05-08 13:55:19 -04:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
manufacturer = DynamicModelChoiceField(
|
2017-05-11 16:24:57 -04:00
|
|
|
queryset=Manufacturer.objects.all(),
|
2020-11-04 10:15:15 -05:00
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'device_types': '$device_type'
|
|
|
|
}
|
2017-05-08 13:55:19 -04:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
device_type = DynamicModelChoiceField(
|
2017-05-11 16:24:57 -04:00
|
|
|
queryset=DeviceType.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'manufacturer_id': '$manufacturer'
|
|
|
|
}
|
2017-05-08 13:55:19 -04:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
device_role = DynamicModelChoiceField(
|
2020-03-16 14:08:48 -04:00
|
|
|
queryset=DeviceRole.objects.all()
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
|
|
|
platform = DynamicModelChoiceField(
|
|
|
|
queryset=Platform.objects.all(),
|
|
|
|
required=False,
|
2020-08-12 09:28:24 -04:00
|
|
|
query_params={
|
2020-08-12 12:36:53 -04:00
|
|
|
'manufacturer_id': ['$manufacturer', 'null']
|
2020-08-12 09:28:24 -04:00
|
|
|
}
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
|
|
|
cluster_group = DynamicModelChoiceField(
|
2018-12-07 09:57:55 -05:00
|
|
|
queryset=ClusterGroup.objects.all(),
|
|
|
|
required=False,
|
2020-11-04 10:15:15 -05:00
|
|
|
null_option='None',
|
|
|
|
initial_params={
|
|
|
|
'clusters': '$cluster'
|
|
|
|
}
|
2018-12-07 09:57:55 -05:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
cluster = DynamicModelChoiceField(
|
2018-12-07 09:57:55 -05:00
|
|
|
queryset=Cluster.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'group_id': '$cluster_group'
|
|
|
|
}
|
2018-12-07 09:57:55 -05:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
comments = CommentField()
|
2019-09-18 15:39:26 -04:00
|
|
|
local_context_data = JSONField(
|
|
|
|
required=False,
|
|
|
|
label=''
|
|
|
|
)
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Device
|
2017-05-08 13:55:19 -04:00
|
|
|
fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'name', 'device_role', 'device_type', 'serial', 'asset_tag', 'region', 'site_group', 'site', 'rack',
|
2021-03-29 10:59:06 -04:00
|
|
|
'location', 'position', 'face', 'status', 'platform', 'primary_ip4', 'primary_ip6', 'cluster_group',
|
|
|
|
'cluster', 'tenant_group', 'tenant', 'comments', 'tags', 'local_context_data'
|
2017-05-08 13:55:19 -04:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
help_texts = {
|
|
|
|
'device_role': "The function this device serves",
|
|
|
|
'serial': "Chassis serial number",
|
2018-11-27 11:57:29 -05:00
|
|
|
'local_context_data': "Local config context data overwrites all source contexts in the final rendered "
|
|
|
|
"config context",
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
|
|
|
widgets = {
|
2020-12-23 16:21:26 -05:00
|
|
|
'face': StaticSelect2(),
|
2019-01-04 14:41:36 -05:00
|
|
|
'status': StaticSelect2(),
|
|
|
|
'primary_ip4': StaticSelect2(),
|
|
|
|
'primary_ip6': StaticSelect2(),
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
|
|
|
|
2017-05-11 17:52:23 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2017-05-11 16:24:57 -04:00
|
|
|
if self.instance.pk:
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-07-11 16:24:46 -04:00
|
|
|
# Compile list of choices for primary IPv4 and IPv6 addresses
|
|
|
|
for family in [4, 6]:
|
2017-09-01 13:00:44 -04:00
|
|
|
ip_choices = [(None, '---------')]
|
2017-12-18 16:08:46 -05:00
|
|
|
|
|
|
|
# Gather PKs of all interfaces belonging to this Device or a peer VirtualChassis member
|
2020-06-22 15:12:35 -04:00
|
|
|
interface_ids = self.instance.vc_interfaces.values_list('pk', flat=True)
|
2017-12-18 16:08:46 -05:00
|
|
|
|
2017-09-01 13:00:44 -04:00
|
|
|
# Collect interface IPs
|
2020-07-01 14:23:21 -04:00
|
|
|
interface_ips = IPAddress.objects.filter(
|
2020-06-22 15:12:35 -04:00
|
|
|
address__family=family,
|
2020-07-01 14:23:21 -04:00
|
|
|
assigned_object_type=ContentType.objects.get_for_model(Interface),
|
|
|
|
assigned_object_id__in=interface_ids
|
|
|
|
).prefetch_related('assigned_object')
|
2017-09-01 13:00:44 -04:00
|
|
|
if interface_ips:
|
2020-07-01 14:23:21 -04:00
|
|
|
ip_list = [(ip.id, f'{ip.address} ({ip.assigned_object})') for ip in interface_ips]
|
2017-12-18 16:08:46 -05:00
|
|
|
ip_choices.append(('Interface IPs', ip_list))
|
2017-09-01 13:00:44 -04:00
|
|
|
# Collect NAT IPs
|
2019-08-19 01:53:39 -04:00
|
|
|
nat_ips = IPAddress.objects.prefetch_related('nat_inside').filter(
|
2020-06-22 15:12:35 -04:00
|
|
|
address__family=family,
|
2020-07-01 14:23:21 -04:00
|
|
|
nat_inside__assigned_object_type=ContentType.objects.get_for_model(Interface),
|
|
|
|
nat_inside__assigned_object_id__in=interface_ids
|
|
|
|
).prefetch_related('assigned_object')
|
2017-09-01 13:00:44 -04:00
|
|
|
if nat_ips:
|
2020-09-04 16:09:05 -04:00
|
|
|
ip_list = [(ip.id, f'{ip.address} (NAT)') for ip in nat_ips]
|
2017-12-18 16:08:46 -05:00
|
|
|
ip_choices.append(('NAT IPs', ip_list))
|
2017-09-01 13:00:44 -04:00
|
|
|
self.fields['primary_ip{}'.format(family)].choices = ip_choices
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-12-21 11:06:42 -05:00
|
|
|
# If editing an existing device, exclude it from the list of occupied rack units. This ensures that a device
|
|
|
|
# can be flipped from one face to another.
|
2020-08-12 13:59:11 -04:00
|
|
|
self.fields['position'].widget.add_query_param('exclude', self.instance.pk)
|
2016-12-21 11:06:42 -05:00
|
|
|
|
2017-12-19 16:15:26 -05:00
|
|
|
# Limit platform by manufacturer
|
|
|
|
self.fields['platform'].queryset = Platform.objects.filter(
|
|
|
|
Q(manufacturer__isnull=True) | Q(manufacturer=self.instance.device_type.manufacturer)
|
|
|
|
)
|
|
|
|
|
2020-12-23 16:21:26 -05:00
|
|
|
# Disable rack assignment if this is a child device installed in a parent device
|
|
|
|
if self.instance.device_type.is_child_device and hasattr(self.instance, 'parent_bay'):
|
|
|
|
self.fields['site'].disabled = True
|
|
|
|
self.fields['rack'].disabled = True
|
|
|
|
self.initial['site'] = self.instance.parent_bay.device.site_id
|
|
|
|
self.initial['rack'] = self.instance.parent_bay.device.rack_id
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
else:
|
|
|
|
|
|
|
|
# An object that doesn't exist yet can't have any IPs assigned to it
|
2016-07-11 16:24:46 -04:00
|
|
|
self.fields['primary_ip4'].choices = []
|
|
|
|
self.fields['primary_ip4'].widget.attrs['readonly'] = True
|
|
|
|
self.fields['primary_ip6'].choices = []
|
|
|
|
self.fields['primary_ip6'].widget.attrs['readonly'] = True
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
# Rack position
|
2020-12-23 16:21:26 -05:00
|
|
|
position = self.data.get('position') or self.initial.get('position')
|
|
|
|
if position:
|
|
|
|
self.fields['position'].widget.choices = [(position, f'U{position}')]
|
2016-07-19 13:09:15 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-01-29 13:53:26 -05:00
|
|
|
class BaseDeviceCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device_role = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=DeviceRole.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned role'
|
2017-05-09 10:25:30 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
tenant = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Tenant.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned tenant'
|
2017-05-09 10:25:30 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
manufacturer = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Device type manufacturer'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
device_type = CSVModelChoiceField(
|
2020-05-05 16:15:09 -04:00
|
|
|
queryset=DeviceType.objects.all(),
|
|
|
|
to_field_name='model',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Device type model'
|
2017-05-09 10:25:30 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
platform = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Platform.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned platform'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2017-06-07 13:22:06 -04:00
|
|
|
status = CSVChoiceField(
|
2019-11-25 19:23:43 -05:00
|
|
|
choices=DeviceStatusChoices,
|
2018-01-25 13:07:04 -05:00
|
|
|
help_text='Operational status'
|
2017-05-09 10:25:30 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
cluster = CSVModelChoiceField(
|
2020-05-01 15:40:34 -04:00
|
|
|
queryset=Cluster.objects.all(),
|
|
|
|
to_field_name='name',
|
|
|
|
required=False,
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Virtualization cluster'
|
2020-05-01 15:40:34 -04:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
2016-07-14 17:35:52 -04:00
|
|
|
fields = []
|
2016-03-01 11:23:03 -05:00
|
|
|
model = Device
|
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
|
super().__init__(data, *args, **kwargs)
|
2017-06-07 14:19:08 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
if data:
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
# Limit device type queryset by manufacturer
|
|
|
|
params = {f"manufacturer__{self.fields['manufacturer'].to_field_name}": data.get('manufacturer')}
|
|
|
|
self.fields['device_type'].queryset = self.fields['device_type'].queryset.filter(**params)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2017-06-02 14:49:25 -04:00
|
|
|
class DeviceCSVForm(BaseDeviceCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
site = CSVModelChoiceField(
|
2017-06-02 14:49:25 -04:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned site'
|
2017-05-09 10:25:30 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = CSVModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-05-05 16:15:09 -04:00
|
|
|
to_field_name='name',
|
2017-06-07 14:19:08 -04:00
|
|
|
required=False,
|
2021-03-03 14:28:07 -05:00
|
|
|
help_text="Assigned location (if any)"
|
2017-06-07 14:19:08 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
rack = CSVModelChoiceField(
|
2020-05-05 16:15:09 -04:00
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
to_field_name='name',
|
2017-06-02 14:49:25 -04:00
|
|
|
required=False,
|
2021-03-03 14:28:07 -05:00
|
|
|
help_text="Assigned rack (if any)"
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2017-06-07 13:22:06 -04:00
|
|
|
face = CSVChoiceField(
|
2019-11-16 21:46:07 -05:00
|
|
|
choices=DeviceFaceChoices,
|
2017-06-02 14:49:25 -04:00
|
|
|
required=False,
|
2017-06-07 13:22:06 -04:00
|
|
|
help_text='Mounted rack face'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2017-06-02 14:49:25 -04:00
|
|
|
class Meta(BaseDeviceCSVForm.Meta):
|
2017-05-09 10:25:30 -04:00
|
|
|
fields = [
|
2020-05-05 16:15:09 -04:00
|
|
|
'name', 'device_role', 'tenant', 'manufacturer', 'device_type', 'platform', 'serial', 'asset_tag', 'status',
|
2021-03-03 13:30:33 -05:00
|
|
|
'site', 'location', 'rack', 'position', 'face', 'cluster', 'comments',
|
2017-05-09 10:25:30 -04:00
|
|
|
]
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
|
super().__init__(data, *args, **kwargs)
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
if data:
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2021-03-03 13:30:33 -05:00
|
|
|
# Limit location queryset by assigned site
|
2020-05-05 16:15:09 -04:00
|
|
|
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
2021-03-03 13:30:33 -05:00
|
|
|
self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
# Limit rack queryset by assigned site and group
|
|
|
|
params = {
|
|
|
|
f"site__{self.fields['site'].to_field_name}": data.get('site'),
|
2021-03-03 13:30:33 -05:00
|
|
|
f"location__{self.fields['location'].to_field_name}": data.get('location'),
|
2020-05-05 16:15:09 -04:00
|
|
|
}
|
|
|
|
self.fields['rack'].queryset = self.fields['rack'].queryset.filter(**params)
|
2016-07-14 17:35:52 -04:00
|
|
|
|
|
|
|
|
2017-06-02 14:49:25 -04:00
|
|
|
class ChildDeviceCSVForm(BaseDeviceCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
parent = CSVModelChoiceField(
|
2017-03-13 11:18:33 -04:00
|
|
|
queryset=Device.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Parent device'
|
2017-03-13 11:18:33 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
device_bay = CSVModelChoiceField(
|
2020-05-15 09:36:16 -04:00
|
|
|
queryset=DeviceBay.objects.all(),
|
2020-05-05 16:15:09 -04:00
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Device bay in which this device is installed'
|
2017-06-02 14:49:25 -04:00
|
|
|
)
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2017-06-02 14:49:25 -04:00
|
|
|
class Meta(BaseDeviceCSVForm.Meta):
|
2017-03-13 11:18:33 -04:00
|
|
|
fields = [
|
2020-05-05 16:15:09 -04:00
|
|
|
'name', 'device_role', 'tenant', 'manufacturer', 'device_type', 'platform', 'serial', 'asset_tag', 'status',
|
|
|
|
'parent', 'device_bay', 'cluster', 'comments',
|
2017-03-13 11:18:33 -04:00
|
|
|
]
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
|
super().__init__(data, *args, **kwargs)
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
if data:
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
# Limit device bay queryset by parent device
|
|
|
|
params = {f"device__{self.fields['parent'].to_field_name}": data.get('parent')}
|
|
|
|
self.fields['device_bay'].queryset = self.fields['device_bay'].queryset.filter(**params)
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2020-05-15 09:36:16 -04:00
|
|
|
def clean(self):
|
|
|
|
super().clean()
|
|
|
|
|
|
|
|
# Set parent_bay reverse relationship
|
|
|
|
device_bay = self.cleaned_data.get('device_bay')
|
|
|
|
if device_bay:
|
|
|
|
self.instance.parent_bay = device_bay
|
|
|
|
|
|
|
|
# Inherit site and rack from parent device
|
|
|
|
parent = self.cleaned_data.get('parent')
|
|
|
|
if parent:
|
|
|
|
self.instance.site = parent.site
|
|
|
|
self.instance.rack = parent.rack
|
|
|
|
|
2016-07-14 17:35:52 -04:00
|
|
|
|
2018-07-10 10:00:21 -04:00
|
|
|
class DeviceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2018-11-27 11:57:29 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
2018-11-06 10:31:56 -05:00
|
|
|
)
|
2020-08-13 09:27:21 -04:00
|
|
|
manufacturer = DynamicModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
device_type = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=DeviceType.objects.all(),
|
2020-04-13 10:34:44 -04:00
|
|
|
required=False,
|
2020-08-13 09:27:21 -04:00
|
|
|
query_params={
|
|
|
|
'manufacturer_id': '$manufacturer'
|
|
|
|
}
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
device_role = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=DeviceRole.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-22 11:15:17 +01:00
|
|
|
site = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2021-03-29 10:59:06 -04:00
|
|
|
location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
tenant = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Tenant.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
platform = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Platform.objects.all(),
|
2020-03-16 14:08:48 -04:00
|
|
|
required=False
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
status = forms.ChoiceField(
|
2019-11-25 19:23:43 -05:00
|
|
|
choices=add_blank_choice(DeviceStatusChoices),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False,
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2()
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
serial = forms.CharField(
|
|
|
|
max_length=50,
|
|
|
|
required=False,
|
|
|
|
label='Serial Number'
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-09-30 16:17:41 -04:00
|
|
|
class Meta:
|
2018-11-27 11:57:29 -05:00
|
|
|
nullable_fields = [
|
|
|
|
'tenant', 'platform', 'serial',
|
|
|
|
]
|
2016-09-30 16:17:41 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2019-09-06 11:42:56 -05:00
|
|
|
class DeviceFilterForm(BootstrapMixin, LocalConfigContextFilterForm, TenancyFilterForm, CustomFieldFilterForm):
|
2016-08-23 12:05:28 -04:00
|
|
|
model = Device
|
2019-05-09 14:32:49 -04:00
|
|
|
field_order = [
|
2021-03-03 13:30:33 -05:00
|
|
|
'q', 'region_id', 'site_id', 'location_id', 'rack_id', 'status', 'role_id', 'tenant_group_id', 'tenant_id',
|
2021-03-24 15:05:19 -04:00
|
|
|
'manufacturer_id', 'device_type_id', 'asset_tag', 'mac_address', 'has_primary_ip',
|
2019-05-09 14:32:49 -04:00
|
|
|
]
|
2018-11-27 11:57:29 -05:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2018-11-06 10:31:56 -05:00
|
|
|
queryset=Region.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False
|
2018-11-06 10:31:56 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=Site.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2017-01-24 10:53:59 -05:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2021-03-03 13:30:33 -05:00
|
|
|
label=_('Location'),
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2017-01-24 10:53:59 -05:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
rack_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=Rack.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
null_option='None',
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id',
|
2021-03-03 13:30:33 -05:00
|
|
|
'location_id': '$location_id',
|
2021-03-01 17:24:30 -05:00
|
|
|
},
|
|
|
|
label=_('Rack')
|
2017-05-12 22:41:27 -04:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
role_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=DeviceRole.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Role')
|
2017-01-24 10:53:59 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
manufacturer_id = DynamicModelMultipleChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Manufacturer.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Manufacturer')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
device_type_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=DeviceType.objects.all(),
|
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'manufacturer_id': '$manufacturer_id'
|
|
|
|
},
|
|
|
|
label=_('Model')
|
2017-01-24 10:53:59 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
platform_id = DynamicModelMultipleChoiceField(
|
2019-01-09 13:44:39 -05:00
|
|
|
queryset=Platform.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
null_option='None',
|
|
|
|
label=_('Platform')
|
2017-01-24 10:53:59 -05:00
|
|
|
)
|
2019-01-09 23:33:08 -05:00
|
|
|
status = forms.MultipleChoiceField(
|
2019-11-25 19:23:43 -05:00
|
|
|
choices=DeviceStatusChoices,
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
2018-03-07 14:16:38 -05:00
|
|
|
)
|
2021-03-24 15:05:19 -04:00
|
|
|
asset_tag = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2018-11-27 11:57:29 -05:00
|
|
|
mac_address = forms.CharField(
|
|
|
|
required=False,
|
|
|
|
label='MAC address'
|
|
|
|
)
|
2018-02-21 10:55:49 -05:00
|
|
|
has_primary_ip = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Has a primary IP',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
)
|
2019-06-24 16:31:21 -04:00
|
|
|
virtual_chassis_member = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Virtual chassis member',
|
|
|
|
widget=StaticSelect2(
|
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
console_ports = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Has console ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
)
|
|
|
|
console_server_ports = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Has console server ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
)
|
|
|
|
power_ports = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Has power ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
)
|
|
|
|
power_outlets = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Has power outlets',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
)
|
|
|
|
interfaces = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Has interfaces',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-11-15 00:42:01 -05:00
|
|
|
)
|
|
|
|
pass_through_ports = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
label='Has pass-through ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
widget=StaticSelect2(
|
2018-11-27 11:57:29 -05:00
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
2018-02-21 10:55:49 -05:00
|
|
|
)
|
2020-01-14 08:22:27 +00:00
|
|
|
tag = TagFilterField(model)
|
2020-01-13 20:16:13 +00:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-12-16 16:29:32 -05:00
|
|
|
#
|
2020-06-18 12:09:28 -04:00
|
|
|
# Device components
|
2016-12-16 16:29:32 -05:00
|
|
|
#
|
|
|
|
|
2021-03-01 13:37:53 -05:00
|
|
|
class ComponentCreateForm(BootstrapMixin, CustomFieldForm, ComponentForm):
|
2020-06-18 12:09:28 -04:00
|
|
|
"""
|
2020-07-14 15:51:13 -04:00
|
|
|
Base form for the creation of device components (models subclassed from ComponentModel).
|
2020-06-18 12:09:28 -04:00
|
|
|
"""
|
|
|
|
device = DynamicModelChoiceField(
|
2021-03-16 10:29:15 -04:00
|
|
|
queryset=Device.objects.all()
|
2020-06-18 12:09:28 -04:00
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
max_length=100,
|
|
|
|
required=False
|
|
|
|
)
|
2020-06-18 13:20:32 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
2020-06-18 12:09:28 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-03-01 13:42:31 -05:00
|
|
|
class DeviceBulkAddComponentForm(BootstrapMixin, CustomFieldForm, ComponentForm):
|
2018-11-27 11:57:29 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
description = forms.CharField(
|
|
|
|
max_length=100,
|
|
|
|
required=False
|
|
|
|
)
|
2020-06-17 13:29:27 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2020-04-22 14:05:27 -04:00
|
|
|
|
2016-12-16 16:29:32 -05:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Console ports
|
|
|
|
#
|
|
|
|
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
class ConsolePortFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = ConsolePort
|
2020-02-26 17:17:00 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=ConsolePortTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2021-03-03 10:20:08 -05:00
|
|
|
speed = forms.MultipleChoiceField(
|
|
|
|
choices=ConsolePortSpeedChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2020-01-30 17:45:03 +00:00
|
|
|
tag = TagFilterField(model)
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class ConsolePortForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsolePort
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2021-03-03 10:20:08 -05:00
|
|
|
'device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description', 'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 12:09:28 -04:00
|
|
|
class ConsolePortCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = ConsolePort
|
2019-10-30 14:25:55 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=add_blank_choice(ConsolePortTypeChoices),
|
2019-11-06 16:56:46 -05:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2019-10-30 14:25:55 -04:00
|
|
|
)
|
2021-03-03 10:20:08 -05:00
|
|
|
speed = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(ConsolePortSpeedChoices),
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
|
|
|
field_order = ('device', 'name_pattern', 'label_pattern', 'type', 'speed', 'mark_connected', 'description', 'tags')
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2020-04-22 11:15:39 -04:00
|
|
|
class ConsolePortBulkCreateForm(
|
2021-03-03 10:20:08 -05:00
|
|
|
form_from_model(ConsolePort, ['type', 'speed', 'mark_connected']),
|
2020-04-22 11:15:39 -04:00
|
|
|
DeviceBulkAddComponentForm
|
|
|
|
):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = ConsolePort
|
2021-03-01 21:34:42 -05:00
|
|
|
field_order = ('name_pattern', 'label_pattern', 'type', 'mark_connected', 'description', 'tags')
|
2020-04-22 11:15:39 -04:00
|
|
|
|
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
class ConsolePortBulkEditForm(
|
2021-03-03 10:20:08 -05:00
|
|
|
form_from_model(ConsolePort, ['label', 'type', 'speed', 'mark_connected', 'description']),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
2020-02-06 20:58:14 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=ConsolePort.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
mark_connected = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect
|
|
|
|
)
|
2020-02-06 20:58:14 -05:00
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'description']
|
2020-02-06 20:58:14 -05:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class ConsolePortCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2019-12-05 21:36:11 +01:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
2021-01-26 10:17:58 -05:00
|
|
|
type = CSVChoiceField(
|
|
|
|
choices=ConsolePortTypeChoices,
|
2021-01-26 10:35:03 -05:00
|
|
|
required=False,
|
2021-01-26 10:17:58 -05:00
|
|
|
help_text='Port type'
|
|
|
|
)
|
2021-03-03 10:20:08 -05:00
|
|
|
speed = CSVTypedChoiceField(
|
|
|
|
choices=ConsolePortSpeedChoices,
|
|
|
|
coerce=int,
|
|
|
|
empty_value=None,
|
|
|
|
required=False,
|
|
|
|
help_text='Port speed in bps'
|
|
|
|
)
|
2019-12-05 21:36:11 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsolePort
|
|
|
|
fields = ConsolePort.csv_headers
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Console server ports
|
|
|
|
#
|
|
|
|
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
class ConsoleServerPortFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = ConsoleServerPort
|
2020-02-26 17:17:00 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=ConsolePortTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2021-03-03 10:20:08 -05:00
|
|
|
speed = forms.MultipleChoiceField(
|
|
|
|
choices=ConsolePortSpeedChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2020-01-30 17:45:03 +00:00
|
|
|
tag = TagFilterField(model)
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class ConsoleServerPortForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsoleServerPort
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2021-03-03 10:20:35 -05:00
|
|
|
'device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description', 'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 12:09:28 -04:00
|
|
|
class ConsoleServerPortCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = ConsoleServerPort
|
2019-10-30 14:25:55 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=add_blank_choice(ConsolePortTypeChoices),
|
2019-11-06 16:56:46 -05:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2019-10-30 14:25:55 -04:00
|
|
|
)
|
2021-03-03 10:20:08 -05:00
|
|
|
speed = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(ConsolePortSpeedChoices),
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
field_order = ('device', 'name_pattern', 'label_pattern', 'type', 'speed', 'mark_connected', 'description', 'tags')
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2020-04-22 11:15:39 -04:00
|
|
|
class ConsoleServerPortBulkCreateForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(ConsoleServerPort, ['type', 'speed', 'mark_connected']),
|
2020-04-22 11:15:39 -04:00
|
|
|
DeviceBulkAddComponentForm
|
|
|
|
):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = ConsoleServerPort
|
2021-03-03 10:20:08 -05:00
|
|
|
field_order = ('name_pattern', 'label_pattern', 'type', 'speed', 'description', 'tags')
|
2020-04-22 11:15:39 -04:00
|
|
|
|
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
class ConsoleServerPortBulkEditForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(ConsoleServerPort, ['label', 'type', 'speed', 'mark_connected', 'description']),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
2019-02-20 14:34:05 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=ConsoleServerPort.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
mark_connected = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect
|
|
|
|
)
|
2019-02-20 14:34:05 -05:00
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'description']
|
2019-02-20 14:34:05 -05:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class ConsoleServerPortCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2019-12-05 21:36:11 +01:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
2021-01-26 10:17:58 -05:00
|
|
|
type = CSVChoiceField(
|
|
|
|
choices=ConsolePortTypeChoices,
|
2021-01-26 10:35:03 -05:00
|
|
|
required=False,
|
2021-01-26 10:17:58 -05:00
|
|
|
help_text='Port type'
|
|
|
|
)
|
2021-03-03 10:20:08 -05:00
|
|
|
speed = CSVTypedChoiceField(
|
|
|
|
choices=ConsolePortSpeedChoices,
|
|
|
|
coerce=int,
|
|
|
|
empty_value=None,
|
|
|
|
required=False,
|
|
|
|
help_text='Port speed in bps'
|
|
|
|
)
|
2019-12-05 21:36:11 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsoleServerPort
|
|
|
|
fields = ConsoleServerPort.csv_headers
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Power ports
|
|
|
|
#
|
|
|
|
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
class PowerPortFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = PowerPort
|
2020-02-26 17:17:00 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=PowerPortTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2020-01-30 17:45:03 +00:00
|
|
|
tag = TagFilterField(model)
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class PowerPortForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerPort
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2021-03-03 10:20:35 -05:00
|
|
|
'device', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'mark_connected', 'description',
|
|
|
|
'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 12:09:28 -04:00
|
|
|
class PowerPortCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = PowerPort
|
2019-11-06 15:30:54 -05:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=add_blank_choice(PowerPortTypeChoices),
|
2019-11-06 16:56:46 -05:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2019-11-06 15:30:54 -05:00
|
|
|
)
|
2019-05-02 10:02:02 -04:00
|
|
|
maximum_draw = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False,
|
|
|
|
help_text="Maximum draw in watts"
|
|
|
|
)
|
|
|
|
allocated_draw = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False,
|
|
|
|
help_text="Allocated draw in watts"
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = (
|
2021-03-03 10:20:35 -05:00
|
|
|
'device', 'name_pattern', 'label_pattern', 'type', 'maximum_draw', 'allocated_draw', 'mark_connected',
|
|
|
|
'description', 'tags',
|
2016-03-01 11:23:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-22 11:15:39 -04:00
|
|
|
class PowerPortBulkCreateForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(PowerPort, ['type', 'maximum_draw', 'allocated_draw', 'mark_connected']),
|
2020-04-22 11:15:39 -04:00
|
|
|
DeviceBulkAddComponentForm
|
|
|
|
):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = PowerPort
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('name_pattern', 'label_pattern', 'type', 'maximum_draw', 'allocated_draw', 'description', 'tags')
|
2020-04-22 11:15:39 -04:00
|
|
|
|
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
class PowerPortBulkEditForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(PowerPort, ['label', 'type', 'maximum_draw', 'allocated_draw', 'mark_connected', 'description']),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
2020-02-06 20:58:14 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=PowerPort.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
mark_connected = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect
|
|
|
|
)
|
2020-02-06 20:58:14 -05:00
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'description']
|
2020-02-06 20:58:14 -05:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class PowerPortCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2019-12-05 21:36:11 +01:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
2021-01-26 10:17:58 -05:00
|
|
|
type = CSVChoiceField(
|
|
|
|
choices=PowerPortTypeChoices,
|
2021-01-26 10:35:03 -05:00
|
|
|
required=False,
|
2021-01-26 10:17:58 -05:00
|
|
|
help_text='Port type'
|
|
|
|
)
|
2019-12-05 21:36:11 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerPort
|
|
|
|
fields = PowerPort.csv_headers
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Power outlets
|
|
|
|
#
|
|
|
|
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
class PowerOutletFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = PowerOutlet
|
2020-02-26 17:17:00 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=PowerOutletTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2020-01-30 17:45:03 +00:00
|
|
|
tag = TagFilterField(model)
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class PowerOutletForm(BootstrapMixin, CustomFieldModelForm):
|
2019-04-10 14:16:16 -04:00
|
|
|
power_port = forms.ModelChoiceField(
|
|
|
|
queryset=PowerPort.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerOutlet
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2021-03-03 10:20:35 -05:00
|
|
|
'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'mark_connected', 'description', 'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:16:16 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit power_port choices to the local device
|
2019-05-01 12:02:18 -04:00
|
|
|
if hasattr(self.instance, 'device'):
|
|
|
|
self.fields['power_port'].queryset = PowerPort.objects.filter(
|
|
|
|
device=self.instance.device
|
|
|
|
)
|
2019-04-10 14:16:16 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-06-18 12:09:28 -04:00
|
|
|
class PowerOutletCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = PowerOutlet
|
2019-11-06 15:30:54 -05:00
|
|
|
type = forms.ChoiceField(
|
2019-11-15 21:00:34 -05:00
|
|
|
choices=add_blank_choice(PowerOutletTypeChoices),
|
2019-11-06 16:56:46 -05:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2019-11-06 15:30:54 -05:00
|
|
|
)
|
2019-05-02 10:12:27 -04:00
|
|
|
power_port = forms.ModelChoiceField(
|
|
|
|
queryset=PowerPort.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
feed_leg = forms.ChoiceField(
|
2019-11-27 21:29:58 -05:00
|
|
|
choices=add_blank_choice(PowerOutletFeedLegChoices),
|
2019-05-02 10:12:27 -04:00
|
|
|
required=False
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
field_order = (
|
|
|
|
'device', 'name_pattern', 'label_pattern', 'type', 'power_port', 'feed_leg', 'mark_connected', 'description',
|
|
|
|
'tags',
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2019-05-02 10:12:27 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2020-02-05 12:36:38 -05:00
|
|
|
# Limit power_port queryset to PowerPorts which belong to the parent Device
|
2020-02-05 15:29:35 -05:00
|
|
|
device = Device.objects.get(
|
|
|
|
pk=self.initial.get('device') or self.data.get('device')
|
|
|
|
)
|
|
|
|
self.fields['power_port'].queryset = PowerPort.objects.filter(device=device)
|
2019-05-02 10:12:27 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-04-22 11:15:39 -04:00
|
|
|
class PowerOutletBulkCreateForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(PowerOutlet, ['type', 'feed_leg', 'mark_connected']),
|
2020-04-22 11:15:39 -04:00
|
|
|
DeviceBulkAddComponentForm
|
|
|
|
):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = PowerOutlet
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('name_pattern', 'label_pattern', 'type', 'feed_leg', 'description', 'tags')
|
2020-04-22 11:15:39 -04:00
|
|
|
|
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
class PowerOutletBulkEditForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(PowerOutlet, ['label', 'type', 'feed_leg', 'power_port', 'mark_connected', 'description']),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=PowerOutlet.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
|
|
|
device = forms.ModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
required=False,
|
|
|
|
disabled=True,
|
|
|
|
widget=forms.HiddenInput()
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
mark_connected = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect
|
|
|
|
)
|
2020-04-22 11:47:26 -04:00
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'type', 'feed_leg', 'power_port', 'description']
|
2020-04-22 11:47:26 -04:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit power_port queryset to PowerPorts which belong to the parent Device
|
|
|
|
if 'device' in self.initial:
|
|
|
|
device = Device.objects.filter(pk=self.initial['device']).first()
|
|
|
|
self.fields['power_port'].queryset = PowerPort.objects.filter(device=device)
|
|
|
|
else:
|
|
|
|
self.fields['power_port'].choices = ()
|
|
|
|
self.fields['power_port'].widget.attrs['disabled'] = True
|
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class PowerOutletCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2019-12-05 21:36:11 +01:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
2021-01-26 10:17:58 -05:00
|
|
|
type = CSVChoiceField(
|
|
|
|
choices=PowerOutletTypeChoices,
|
2021-01-26 10:35:03 -05:00
|
|
|
required=False,
|
2021-01-26 10:17:58 -05:00
|
|
|
help_text='Outlet type'
|
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
power_port = CSVModelChoiceField(
|
2019-12-05 21:36:11 +01:00
|
|
|
queryset=PowerPort.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Local power port which feeds this outlet'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
|
|
|
feed_leg = CSVChoiceField(
|
2019-12-05 17:49:44 -05:00
|
|
|
choices=PowerOutletFeedLegChoices,
|
2019-12-05 21:36:11 +01:00
|
|
|
required=False,
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Electrical phase (for three-phase circuits)'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerOutlet
|
|
|
|
fields = PowerOutlet.csv_headers
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit PowerPort choices to those belonging to this device (or VC master)
|
|
|
|
if self.is_bound:
|
|
|
|
try:
|
|
|
|
device = self.fields['device'].to_python(self.data['device'])
|
|
|
|
except forms.ValidationError:
|
|
|
|
device = None
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
device = self.instance.device
|
|
|
|
except Device.DoesNotExist:
|
|
|
|
device = None
|
|
|
|
|
|
|
|
if device:
|
|
|
|
self.fields['power_port'].queryset = PowerPort.objects.filter(
|
|
|
|
device__in=[device, device.get_vc_master()]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.fields['power_port'].queryset = PowerPort.objects.none()
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Interfaces
|
|
|
|
#
|
|
|
|
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
class InterfaceFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = Interface
|
2020-02-26 17:17:00 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=InterfaceTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2020-02-20 14:24:22 -05:00
|
|
|
enabled = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2(
|
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
|
|
|
)
|
2021-01-07 11:29:59 -05:00
|
|
|
mgmt_only = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2(
|
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
|
|
|
)
|
2020-07-24 16:46:29 -04:00
|
|
|
mac_address = forms.CharField(
|
|
|
|
required=False,
|
|
|
|
label='MAC address'
|
|
|
|
)
|
2020-01-30 17:45:03 +00:00
|
|
|
tag = TagFilterField(model)
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class InterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm):
|
2021-03-05 14:13:03 -05:00
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label='Parent interface',
|
|
|
|
query_params={
|
|
|
|
'kind': 'physical',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
lag = DynamicModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label='LAG interface',
|
|
|
|
query_params={
|
|
|
|
'type': 'lag',
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
untagged_vlan = DynamicModelChoiceField(
|
2019-09-06 12:45:37 -05:00
|
|
|
queryset=VLAN.objects.all(),
|
|
|
|
required=False,
|
2021-03-30 21:32:48 -04:00
|
|
|
label='Untagged VLAN'
|
2019-09-06 12:45:37 -05:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
tagged_vlans = DynamicModelMultipleChoiceField(
|
2019-09-06 12:45:37 -05:00
|
|
|
queryset=VLAN.objects.all(),
|
|
|
|
required=False,
|
2021-03-30 21:32:48 -04:00
|
|
|
label='Tagged VLANs'
|
2019-09-06 12:45:37 -05:00
|
|
|
)
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Interface
|
2017-11-14 15:22:40 -05:00
|
|
|
fields = [
|
2021-03-05 13:49:41 -05:00
|
|
|
'device', 'name', 'label', 'type', 'enabled', 'parent', 'lag', 'mac_address', 'mtu', 'mgmt_only',
|
|
|
|
'mark_connected', 'description', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags',
|
2017-11-14 15:22:40 -05:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
2019-04-12 13:42:56 -04:00
|
|
|
'type': StaticSelect2(),
|
2019-01-04 14:41:36 -05:00
|
|
|
'mode': StaticSelect2(),
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
2018-03-07 17:01:51 -05:00
|
|
|
labels = {
|
|
|
|
'mode': '802.1Q Mode',
|
|
|
|
}
|
|
|
|
help_texts = {
|
2018-03-14 14:53:28 -04:00
|
|
|
'mode': INTERFACE_MODE_HELP_TEXT,
|
2018-03-07 17:01:51 -05:00
|
|
|
}
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2017-02-27 16:52:13 -05:00
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2017-02-27 16:52:13 -05:00
|
|
|
|
2021-03-05 14:13:03 -05:00
|
|
|
device = Device.objects.get(pk=self.data['device']) if self.is_bound else self.instance.device
|
2021-03-05 13:49:41 -05:00
|
|
|
|
2021-03-05 14:13:03 -05:00
|
|
|
# Restrict parent/LAG interface assignment by device
|
|
|
|
self.fields['parent'].widget.add_query_param('device_id', device.pk)
|
|
|
|
self.fields['lag'].widget.add_query_param('device_id', device.pk)
|
2017-02-27 16:52:13 -05:00
|
|
|
|
2021-03-30 21:32:48 -04:00
|
|
|
# Limit VLAN choices by device
|
|
|
|
self.fields['untagged_vlan'].widget.add_query_param('available_on_device', device.pk)
|
|
|
|
self.fields['tagged_vlans'].widget.add_query_param('available_on_device', device.pk)
|
2017-02-27 16:52:13 -05:00
|
|
|
|
2017-11-14 15:22:40 -05:00
|
|
|
|
2020-06-18 12:09:28 -04:00
|
|
|
class InterfaceCreateForm(ComponentCreateForm, InterfaceCommonForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = Interface
|
2019-04-12 13:42:56 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-21 22:11:02 -05:00
|
|
|
choices=InterfaceTypeChoices,
|
2019-01-04 14:41:36 -05:00
|
|
|
widget=StaticSelect2(),
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
enabled = forms.BooleanField(
|
2020-02-05 12:36:38 -05:00
|
|
|
required=False,
|
|
|
|
initial=True
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-05 14:13:03 -05:00
|
|
|
parent = DynamicModelChoiceField(
|
2021-03-05 13:49:41 -05:00
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
2021-03-05 14:13:03 -05:00
|
|
|
query_params={
|
|
|
|
'device_id': '$device',
|
|
|
|
'kind': 'physical',
|
|
|
|
}
|
2021-03-05 13:49:41 -05:00
|
|
|
)
|
2021-03-05 14:13:03 -05:00
|
|
|
lag = DynamicModelChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
2021-03-05 14:13:03 -05:00
|
|
|
query_params={
|
|
|
|
'device_id': '$device',
|
|
|
|
'type': 'lag',
|
|
|
|
}
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
|
|
|
mtu = forms.IntegerField(
|
|
|
|
required=False,
|
2020-01-24 14:21:59 -05:00
|
|
|
min_value=INTERFACE_MTU_MIN,
|
|
|
|
max_value=INTERFACE_MTU_MAX,
|
2018-11-27 11:57:29 -05:00
|
|
|
label='MTU'
|
|
|
|
)
|
|
|
|
mac_address = forms.CharField(
|
|
|
|
required=False,
|
|
|
|
label='MAC Address'
|
|
|
|
)
|
2018-02-21 10:38:45 -05:00
|
|
|
mgmt_only = forms.BooleanField(
|
|
|
|
required=False,
|
2018-11-27 11:57:29 -05:00
|
|
|
label='Management only',
|
2018-02-21 10:38:45 -05:00
|
|
|
help_text='This interface is used only for out-of-band management'
|
|
|
|
)
|
2018-11-27 11:57:29 -05:00
|
|
|
mode = forms.ChoiceField(
|
2019-11-21 22:39:15 -05:00
|
|
|
choices=add_blank_choice(InterfaceModeChoices),
|
2019-01-04 14:41:36 -05:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2(),
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
untagged_vlan = DynamicModelChoiceField(
|
2019-09-06 12:45:37 -05:00
|
|
|
queryset=VLAN.objects.all(),
|
2021-03-30 21:32:48 -04:00
|
|
|
required=False
|
2019-09-06 12:45:37 -05:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
tagged_vlans = DynamicModelMultipleChoiceField(
|
2019-09-06 12:45:37 -05:00
|
|
|
queryset=VLAN.objects.all(),
|
2021-03-30 21:32:48 -04:00
|
|
|
required=False
|
2019-09-06 12:45:37 -05:00
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = (
|
2021-03-05 13:49:41 -05:00
|
|
|
'device', 'name_pattern', 'label_pattern', 'type', 'enabled', 'parent', 'lag', 'mtu', 'mac_address',
|
|
|
|
'description', 'mgmt_only', 'mark_connected', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags'
|
2020-07-14 15:51:13 -04:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2017-02-27 16:52:13 -05:00
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2021-03-05 14:13:03 -05:00
|
|
|
|
2021-03-30 21:32:48 -04:00
|
|
|
# Limit VLAN choices by device
|
|
|
|
device_id = self.initial.get('device') or self.data.get('device')
|
|
|
|
self.fields['untagged_vlan'].widget.add_query_param('available_on_device', device_id)
|
|
|
|
self.fields['tagged_vlans'].widget.add_query_param('available_on_device', device_id)
|
2017-02-27 16:52:13 -05:00
|
|
|
|
2019-09-12 11:13:40 -05:00
|
|
|
|
2020-04-22 11:15:39 -04:00
|
|
|
class InterfaceBulkCreateForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(Interface, ['type', 'enabled', 'mtu', 'mgmt_only', 'mark_connected']),
|
2020-04-22 11:15:39 -04:00
|
|
|
DeviceBulkAddComponentForm
|
|
|
|
):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = Interface
|
2021-03-03 10:20:35 -05:00
|
|
|
field_order = (
|
|
|
|
'name_pattern', 'label_pattern', 'type', 'enabled', 'mtu', 'mgmt_only', 'mark_connected', 'description', 'tags',
|
|
|
|
)
|
2019-12-05 21:36:11 +01:00
|
|
|
|
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
class InterfaceBulkEditForm(
|
2020-06-30 16:15:17 -04:00
|
|
|
form_from_model(Interface, [
|
2021-03-05 13:49:41 -05:00
|
|
|
'label', 'type', 'parent', 'lag', 'mac_address', 'mtu', 'mgmt_only', 'mark_connected', 'description', 'mode',
|
2020-06-30 16:15:17 -04:00
|
|
|
]),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
2018-11-27 11:57:29 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2020-02-05 10:26:22 -05:00
|
|
|
device = forms.ModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
2020-02-06 21:44:28 -05:00
|
|
|
required=False,
|
2020-02-19 11:29:42 -05:00
|
|
|
disabled=True,
|
2020-02-05 10:26:22 -05:00
|
|
|
widget=forms.HiddenInput()
|
|
|
|
)
|
2020-12-15 16:52:58 -05:00
|
|
|
enabled = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect
|
|
|
|
)
|
2021-03-05 14:13:03 -05:00
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'kind': 'physical',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
lag = DynamicModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'type': 'lag',
|
|
|
|
}
|
|
|
|
)
|
2020-12-15 16:17:52 -05:00
|
|
|
mgmt_only = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect,
|
|
|
|
label='Management only'
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
mark_connected = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
untagged_vlan = DynamicModelChoiceField(
|
2019-09-06 12:45:37 -05:00
|
|
|
queryset=VLAN.objects.all(),
|
2021-03-30 21:32:48 -04:00
|
|
|
required=False
|
2019-09-06 12:45:37 -05:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
tagged_vlans = DynamicModelMultipleChoiceField(
|
2019-09-06 12:45:37 -05:00
|
|
|
queryset=VLAN.objects.all(),
|
2021-03-30 21:32:48 -04:00
|
|
|
required=False
|
2019-09-06 12:45:37 -05:00
|
|
|
)
|
2016-10-14 16:38:46 -04:00
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = [
|
2021-03-05 13:49:41 -05:00
|
|
|
'label', 'parent', 'lag', 'mac_address', 'mtu', 'description', 'mode', 'untagged_vlan', 'tagged_vlans'
|
2021-03-01 13:57:57 -05:00
|
|
|
]
|
2017-02-27 16:52:13 -05:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2020-02-04 18:08:40 -05:00
|
|
|
if 'device' in self.initial:
|
|
|
|
device = Device.objects.filter(pk=self.initial['device']).first()
|
2021-03-05 14:13:03 -05:00
|
|
|
|
|
|
|
# Restrict parent/LAG interface assignment by device
|
|
|
|
self.fields['parent'].widget.add_query_param('device_id', device.pk)
|
|
|
|
self.fields['lag'].widget.add_query_param('device_id', device.pk)
|
2020-01-15 12:23:34 +00:00
|
|
|
|
2021-03-30 21:32:48 -04:00
|
|
|
# Limit VLAN choices by device
|
|
|
|
self.fields['untagged_vlan'].widget.add_query_param('available_on_device', device.pk)
|
|
|
|
self.fields['tagged_vlans'].widget.add_query_param('available_on_device', device.pk)
|
2021-03-05 14:13:03 -05:00
|
|
|
|
2020-02-06 21:44:28 -05:00
|
|
|
else:
|
2021-03-05 13:49:41 -05:00
|
|
|
# See #4523
|
2020-09-29 14:45:02 -05:00
|
|
|
if 'pk' in self.initial:
|
|
|
|
site = None
|
|
|
|
interfaces = Interface.objects.filter(pk__in=self.initial['pk']).prefetch_related('device__site')
|
|
|
|
|
|
|
|
# Check interface sites. First interface should set site, further interfaces will either continue the
|
|
|
|
# loop or reset back to no site and break the loop.
|
|
|
|
for interface in interfaces:
|
|
|
|
if site is None:
|
|
|
|
site = interface.device.site
|
|
|
|
elif interface.device.site is not site:
|
|
|
|
site = None
|
|
|
|
break
|
|
|
|
|
|
|
|
if site is not None:
|
|
|
|
self.fields['untagged_vlan'].widget.add_query_param('site_id', site.pk)
|
|
|
|
self.fields['tagged_vlans'].widget.add_query_param('site_id', site.pk)
|
|
|
|
|
2021-03-05 14:13:03 -05:00
|
|
|
self.fields['parent'].choices = ()
|
|
|
|
self.fields['parent'].widget.attrs['disabled'] = True
|
2020-02-06 21:44:28 -05:00
|
|
|
self.fields['lag'].choices = ()
|
|
|
|
self.fields['lag'].widget.attrs['disabled'] = True
|
2016-10-14 16:38:46 -04:00
|
|
|
|
2020-01-28 14:19:29 -05:00
|
|
|
def clean(self):
|
2020-12-28 12:54:42 -05:00
|
|
|
super().clean()
|
2020-01-28 14:19:29 -05:00
|
|
|
|
|
|
|
# Untagged interfaces cannot be assigned tagged VLANs
|
|
|
|
if self.cleaned_data['mode'] == InterfaceModeChoices.MODE_ACCESS and self.cleaned_data['tagged_vlans']:
|
|
|
|
raise forms.ValidationError({
|
|
|
|
'mode': "An access interface cannot have tagged VLANs assigned."
|
|
|
|
})
|
|
|
|
|
|
|
|
# Remove all tagged VLAN assignments from "tagged all" interfaces
|
|
|
|
elif self.cleaned_data['mode'] == InterfaceModeChoices.MODE_TAGGED_ALL:
|
|
|
|
self.cleaned_data['tagged_vlans'] = []
|
|
|
|
|
2016-10-14 16:38:46 -04:00
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class InterfaceCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2020-04-22 11:15:39 -04:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2020-04-22 11:15:39 -04:00
|
|
|
)
|
2021-03-05 13:49:41 -05:00
|
|
|
parent = CSVModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
|
|
|
help_text='Parent interface'
|
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
lag = CSVModelChoiceField(
|
2020-04-22 11:15:39 -04:00
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Parent LAG interface'
|
2020-04-22 11:15:39 -04:00
|
|
|
)
|
|
|
|
type = CSVChoiceField(
|
|
|
|
choices=InterfaceTypeChoices,
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Physical medium'
|
2020-04-22 11:15:39 -04:00
|
|
|
)
|
|
|
|
mode = CSVChoiceField(
|
|
|
|
choices=InterfaceModeChoices,
|
|
|
|
required=False,
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='IEEE 802.1Q operational mode (for L2 interfaces)'
|
2020-04-22 11:15:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Interface
|
|
|
|
fields = Interface.csv_headers
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2020-09-04 16:09:05 -04:00
|
|
|
# Limit LAG choices to interfaces belonging to this device (or virtual chassis)
|
2020-07-02 13:27:54 -04:00
|
|
|
device = None
|
2020-04-22 11:15:39 -04:00
|
|
|
if self.is_bound and 'device' in self.data:
|
|
|
|
try:
|
|
|
|
device = self.fields['device'].to_python(self.data['device'])
|
|
|
|
except forms.ValidationError:
|
2020-07-02 13:27:54 -04:00
|
|
|
pass
|
2020-09-04 16:09:05 -04:00
|
|
|
if device and device.virtual_chassis:
|
2020-04-22 11:15:39 -04:00
|
|
|
self.fields['lag'].queryset = Interface.objects.filter(
|
2020-09-04 16:09:05 -04:00
|
|
|
Q(device=device) | Q(device__virtual_chassis=device.virtual_chassis),
|
|
|
|
type=InterfaceTypeChoices.TYPE_LAG
|
|
|
|
)
|
|
|
|
elif device:
|
|
|
|
self.fields['lag'].queryset = Interface.objects.filter(
|
|
|
|
device=device,
|
|
|
|
type=InterfaceTypeChoices.TYPE_LAG
|
2020-04-22 11:15:39 -04:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.fields['lag'].queryset = Interface.objects.none()
|
|
|
|
|
|
|
|
def clean_enabled(self):
|
|
|
|
# Make sure enabled is True when it's not included in the uploaded data
|
|
|
|
if 'enabled' not in self.data:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return self.cleaned_data['enabled']
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
2018-10-25 12:08:13 -04:00
|
|
|
# Front pass-through ports
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
|
2019-12-05 16:10:49 -06:00
|
|
|
class FrontPortFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = FrontPort
|
2020-02-26 17:17:00 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=PortTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2020-01-30 17:45:03 +00:00
|
|
|
tag = TagFilterField(model)
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class FrontPortForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
class Meta:
|
2018-10-25 12:08:13 -04:00
|
|
|
model = FrontPort
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2021-03-03 10:20:35 -05:00
|
|
|
'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'mark_connected', 'description',
|
|
|
|
'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2018-10-03 14:04:16 -04:00
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
2019-01-04 14:41:36 -05:00
|
|
|
'type': StaticSelect2(),
|
|
|
|
'rear_port': StaticSelect2(),
|
2018-10-03 14:04:16 -04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:09:44 -05:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit RearPort choices to the local device
|
|
|
|
if hasattr(self.instance, 'device'):
|
|
|
|
self.fields['rear_port'].queryset = self.fields['rear_port'].queryset.filter(
|
|
|
|
device=self.instance.device
|
|
|
|
)
|
|
|
|
|
2018-10-03 14:04:16 -04:00
|
|
|
|
2018-11-20 21:28:19 -05:00
|
|
|
# TODO: Merge with FrontPortTemplateCreateForm to remove duplicate logic
|
2020-06-18 12:09:28 -04:00
|
|
|
class FrontPortCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = FrontPort
|
2018-10-03 14:04:16 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-25 19:39:25 -05:00
|
|
|
choices=PortTypeChoices,
|
2019-01-04 14:41:36 -05:00
|
|
|
widget=StaticSelect2(),
|
2018-10-03 14:04:16 -04:00
|
|
|
)
|
|
|
|
rear_port_set = forms.MultipleChoiceField(
|
2017-02-17 14:48:00 -05:00
|
|
|
choices=[],
|
2018-10-03 14:04:16 -04:00
|
|
|
label='Rear ports',
|
2019-01-08 15:35:34 -08:00
|
|
|
help_text='Select one rear port assignment for each front port being created.',
|
2018-10-03 14:04:16 -04:00
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
field_order = (
|
|
|
|
'device', 'name_pattern', 'label_pattern', 'type', 'rear_port_set', 'mark_connected', 'description', 'tags',
|
|
|
|
)
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2018-10-03 14:04:16 -04:00
|
|
|
|
2020-02-05 15:29:35 -05:00
|
|
|
device = Device.objects.get(
|
|
|
|
pk=self.initial.get('device') or self.data.get('device')
|
|
|
|
)
|
2020-02-05 12:36:38 -05:00
|
|
|
|
2020-02-05 15:22:57 -05:00
|
|
|
# Determine which rear port positions are occupied. These will be excluded from the list of available
|
|
|
|
# mappings.
|
2018-10-03 14:04:16 -04:00
|
|
|
occupied_port_positions = [
|
|
|
|
(front_port.rear_port_id, front_port.rear_port_position)
|
2020-02-05 15:29:35 -05:00
|
|
|
for front_port in device.frontports.all()
|
2018-10-03 14:04:16 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
# Populate rear port choices
|
|
|
|
choices = []
|
2020-02-05 15:29:35 -05:00
|
|
|
rear_ports = RearPort.objects.filter(device=device)
|
2018-10-03 14:04:16 -04:00
|
|
|
for rear_port in rear_ports:
|
|
|
|
for i in range(1, rear_port.positions + 1):
|
|
|
|
if (rear_port.pk, i) not in occupied_port_positions:
|
|
|
|
choices.append(
|
|
|
|
('{}:{}'.format(rear_port.pk, i), '{}:{}'.format(rear_port.name, i))
|
|
|
|
)
|
|
|
|
self.fields['rear_port_set'].choices = choices
|
|
|
|
|
|
|
|
def clean(self):
|
2020-12-28 12:54:42 -05:00
|
|
|
super().clean()
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
# Validate that the number of ports being created equals the number of selected (rear port, position) tuples
|
|
|
|
front_port_count = len(self.cleaned_data['name_pattern'])
|
|
|
|
rear_port_count = len(self.cleaned_data['rear_port_set'])
|
|
|
|
if front_port_count != rear_port_count:
|
|
|
|
raise forms.ValidationError({
|
|
|
|
'rear_port_set': 'The provided name pattern will create {} ports, however {} rear port assignments '
|
|
|
|
'were selected. These counts must match.'.format(front_port_count, rear_port_count)
|
|
|
|
})
|
|
|
|
|
|
|
|
def get_iterative_data(self, iteration):
|
|
|
|
|
|
|
|
# Assign rear port and position from selected set
|
|
|
|
rear_port, position = self.cleaned_data['rear_port_set'][iteration].split(':')
|
|
|
|
|
|
|
|
return {
|
|
|
|
'rear_port': int(rear_port),
|
|
|
|
'rear_port_position': int(position),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-22 11:26:04 -04:00
|
|
|
# class FrontPortBulkCreateForm(
|
2020-07-02 10:46:02 -04:00
|
|
|
# form_from_model(FrontPort, ['label', 'type', 'description', 'tags']),
|
2020-04-22 11:26:04 -04:00
|
|
|
# DeviceBulkAddComponentForm
|
|
|
|
# ):
|
2020-04-22 14:05:27 -04:00
|
|
|
# pass
|
2020-04-22 11:26:04 -04:00
|
|
|
|
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
class FrontPortBulkEditForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(FrontPort, ['label', 'type', 'mark_connected', 'description']),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
2020-04-22 11:26:04 -04:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=FrontPort.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'description']
|
2020-04-22 11:26:04 -04:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class FrontPortCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2019-12-05 21:36:11 +01:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
rear_port = CSVModelChoiceField(
|
2019-12-05 21:36:11 +01:00
|
|
|
queryset=RearPort.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Corresponding rear port'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
|
|
|
type = CSVChoiceField(
|
2019-12-05 17:49:44 -05:00
|
|
|
choices=PortTypeChoices,
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Physical medium classification'
|
2019-12-05 21:36:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = FrontPort
|
|
|
|
fields = FrontPort.csv_headers
|
2020-05-01 15:40:34 -04:00
|
|
|
help_texts = {
|
|
|
|
'rear_port_position': 'Mapped position on corresponding rear port',
|
|
|
|
}
|
2019-12-05 21:36:11 +01:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit RearPort choices to those belonging to this device (or VC master)
|
|
|
|
if self.is_bound:
|
|
|
|
try:
|
|
|
|
device = self.fields['device'].to_python(self.data['device'])
|
|
|
|
except forms.ValidationError:
|
|
|
|
device = None
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
device = self.instance.device
|
|
|
|
except Device.DoesNotExist:
|
|
|
|
device = None
|
|
|
|
|
|
|
|
if device:
|
|
|
|
self.fields['rear_port'].queryset = RearPort.objects.filter(
|
|
|
|
device__in=[device, device.get_vc_master()]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.fields['rear_port'].queryset = RearPort.objects.none()
|
|
|
|
|
|
|
|
|
2018-10-03 14:04:16 -04:00
|
|
|
#
|
2018-10-25 12:08:13 -04:00
|
|
|
# Rear pass-through ports
|
2018-10-03 14:04:16 -04:00
|
|
|
#
|
|
|
|
|
2019-12-05 16:10:49 -06:00
|
|
|
class RearPortFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = RearPort
|
2020-02-26 17:17:00 -05:00
|
|
|
type = forms.MultipleChoiceField(
|
|
|
|
choices=PortTypeChoices,
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
2020-01-30 17:45:03 +00:00
|
|
|
tag = TagFilterField(model)
|
2019-12-05 16:10:49 -06:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class RearPortForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
class Meta:
|
2018-10-25 12:08:13 -04:00
|
|
|
model = RearPort
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2021-03-03 10:20:35 -05:00
|
|
|
'device', 'name', 'label', 'type', 'positions', 'mark_connected', 'description', 'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2018-10-03 14:04:16 -04:00
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
2019-01-04 14:41:36 -05:00
|
|
|
'type': StaticSelect2(),
|
2018-10-03 14:04:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 12:09:28 -04:00
|
|
|
class RearPortCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = RearPort
|
2018-10-03 14:04:16 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-25 19:39:25 -05:00
|
|
|
choices=PortTypeChoices,
|
2019-01-04 14:41:36 -05:00
|
|
|
widget=StaticSelect2(),
|
2018-10-03 14:04:16 -04:00
|
|
|
)
|
|
|
|
positions = forms.IntegerField(
|
2020-01-24 14:21:59 -05:00
|
|
|
min_value=REARPORT_POSITIONS_MIN,
|
|
|
|
max_value=REARPORT_POSITIONS_MAX,
|
2018-10-03 14:04:16 -04:00
|
|
|
initial=1,
|
|
|
|
help_text='The number of front ports which may be mapped to each rear port'
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
field_order = (
|
|
|
|
'device', 'name_pattern', 'label_pattern', 'type', 'positions', 'mark_connected', 'description', 'tags',
|
|
|
|
)
|
2018-10-03 14:04:16 -04:00
|
|
|
|
|
|
|
|
2020-04-22 11:26:04 -04:00
|
|
|
class RearPortBulkCreateForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(RearPort, ['type', 'positions', 'mark_connected']),
|
2020-04-22 11:26:04 -04:00
|
|
|
DeviceBulkAddComponentForm
|
|
|
|
):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = RearPort
|
2021-03-03 10:20:35 -05:00
|
|
|
field_order = ('name_pattern', 'label_pattern', 'type', 'positions', 'mark_connected', 'description', 'tags')
|
2019-12-05 21:36:11 +01:00
|
|
|
|
2020-04-22 11:15:39 -04:00
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
class RearPortBulkEditForm(
|
2021-03-03 10:20:35 -05:00
|
|
|
form_from_model(RearPort, ['label', 'type', 'mark_connected', 'description']),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
2019-02-08 09:31:10 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
2019-02-20 11:13:43 -05:00
|
|
|
queryset=RearPort.objects.all(),
|
2019-02-08 09:31:10 -05:00
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'description']
|
2019-02-08 09:31:10 -05:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class RearPortCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2020-04-22 11:26:04 -04:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2020-04-22 11:26:04 -04:00
|
|
|
)
|
|
|
|
type = CSVChoiceField(
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Physical medium classification',
|
2020-04-22 11:26:04 -04:00
|
|
|
choices=PortTypeChoices,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RearPort
|
|
|
|
fields = RearPort.csv_headers
|
2020-05-01 15:40:34 -04:00
|
|
|
help_texts = {
|
|
|
|
'positions': 'Number of front ports which may be mapped'
|
|
|
|
}
|
2020-04-22 11:26:04 -04:00
|
|
|
|
|
|
|
|
2020-04-22 11:47:26 -04:00
|
|
|
#
|
|
|
|
# Device bays
|
|
|
|
#
|
|
|
|
|
|
|
|
class DeviceBayFilterForm(DeviceComponentFilterForm):
|
|
|
|
model = DeviceBay
|
|
|
|
tag = TagFilterField(model)
|
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class DeviceBayForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2020-04-22 11:47:26 -04:00
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceBay
|
|
|
|
fields = [
|
2020-06-18 13:35:11 -04:00
|
|
|
'device', 'name', 'label', 'description', 'tags',
|
2020-04-22 11:47:26 -04:00
|
|
|
]
|
|
|
|
widgets = {
|
|
|
|
'device': forms.HiddenInput(),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-18 12:09:28 -04:00
|
|
|
class DeviceBayCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = DeviceBay
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('device', 'name_pattern', 'label_pattern', 'description', 'tags')
|
2020-04-22 11:47:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
class PopulateDeviceBayForm(BootstrapMixin, forms.Form):
|
|
|
|
installed_device = forms.ModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
label='Child Device',
|
|
|
|
help_text="Child devices must first be created and assigned to the site/rack of the parent device.",
|
|
|
|
widget=StaticSelect2(),
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, device_bay, *args, **kwargs):
|
|
|
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
self.fields['installed_device'].queryset = Device.objects.filter(
|
|
|
|
site=device_bay.device.site,
|
|
|
|
rack=device_bay.device.rack,
|
|
|
|
parent_bay__isnull=True,
|
|
|
|
device_type__u_height=0,
|
|
|
|
device_type__subdevice_role=SubdeviceRoleChoices.ROLE_CHILD
|
|
|
|
).exclude(pk=device_bay.device.pk)
|
|
|
|
|
|
|
|
|
2020-07-14 15:51:13 -04:00
|
|
|
class DeviceBayBulkCreateForm(DeviceBulkAddComponentForm):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = DeviceBay
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = ('name_pattern', 'label_pattern', 'description', 'tags')
|
2020-04-22 11:47:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
class DeviceBayBulkEditForm(
|
2020-06-30 16:15:17 -04:00
|
|
|
form_from_model(DeviceBay, ['label', 'description']),
|
2020-04-22 11:47:26 -04:00
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-04-22 11:47:26 -04:00
|
|
|
):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=DeviceBay.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'description']
|
2020-04-22 11:47:26 -04:00
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class DeviceBayCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
device = CSVModelChoiceField(
|
2020-04-22 11:47:26 -04:00
|
|
|
queryset=Device.objects.all(),
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2020-04-22 11:47:26 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
installed_device = CSVModelChoiceField(
|
2020-04-22 11:47:26 -04:00
|
|
|
queryset=Device.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Child device installed within this bay',
|
2020-04-22 11:47:26 -04:00
|
|
|
error_messages={
|
|
|
|
'invalid_choice': 'Child device not found.',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = DeviceBay
|
|
|
|
fields = DeviceBay.csv_headers
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Limit installed device choices to devices of the correct type and location
|
|
|
|
if self.is_bound:
|
|
|
|
try:
|
|
|
|
device = self.fields['device'].to_python(self.data['device'])
|
|
|
|
except forms.ValidationError:
|
|
|
|
device = None
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
device = self.instance.device
|
|
|
|
except Device.DoesNotExist:
|
|
|
|
device = None
|
|
|
|
|
|
|
|
if device:
|
|
|
|
self.fields['installed_device'].queryset = Device.objects.filter(
|
|
|
|
site=device.site,
|
|
|
|
rack=device.rack,
|
|
|
|
parent_bay__isnull=True,
|
|
|
|
device_type__u_height=0,
|
|
|
|
device_type__subdevice_role=SubdeviceRoleChoices.ROLE_CHILD
|
|
|
|
).exclude(pk=device.pk)
|
|
|
|
else:
|
|
|
|
self.fields['installed_device'].queryset = Interface.objects.none()
|
|
|
|
|
|
|
|
|
2020-07-01 14:55:11 -04:00
|
|
|
#
|
|
|
|
# Inventory items
|
|
|
|
#
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class InventoryItemForm(BootstrapMixin, CustomFieldModelForm):
|
2020-07-01 14:55:11 -04:00
|
|
|
device = DynamicModelChoiceField(
|
2021-03-16 10:29:15 -04:00
|
|
|
queryset=Device.objects.all()
|
2020-07-01 14:55:11 -04:00
|
|
|
)
|
2020-09-18 11:05:31 -04:00
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=InventoryItem.objects.all(),
|
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'device_id': '$device'
|
|
|
|
}
|
|
|
|
)
|
2020-07-01 14:55:11 -04:00
|
|
|
manufacturer = DynamicModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = InventoryItem
|
|
|
|
fields = [
|
2020-09-18 11:05:31 -04:00
|
|
|
'device', 'parent', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description',
|
|
|
|
'tags',
|
2020-07-01 14:55:11 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-07-02 10:46:02 -04:00
|
|
|
class InventoryItemCreateForm(ComponentCreateForm):
|
2021-03-01 13:37:53 -05:00
|
|
|
model = InventoryItem
|
2020-07-01 14:55:11 -04:00
|
|
|
manufacturer = DynamicModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2020-09-18 11:05:31 -04:00
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=InventoryItem.objects.all(),
|
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'device_id': '$device'
|
|
|
|
}
|
|
|
|
)
|
2020-07-01 14:55:11 -04:00
|
|
|
part_id = forms.CharField(
|
|
|
|
max_length=50,
|
|
|
|
required=False,
|
|
|
|
label='Part ID'
|
|
|
|
)
|
|
|
|
serial = forms.CharField(
|
|
|
|
max_length=50,
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
asset_tag = forms.CharField(
|
|
|
|
max_length=50,
|
|
|
|
required=False,
|
|
|
|
)
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = (
|
2020-09-18 11:05:31 -04:00
|
|
|
'device', 'parent', 'name_pattern', 'label_pattern', 'manufacturer', 'part_id', 'serial', 'asset_tag',
|
|
|
|
'description', 'tags',
|
2020-07-01 14:55:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-03-01 13:07:25 -05:00
|
|
|
class InventoryItemCSVForm(CustomFieldModelCSVForm):
|
2020-07-01 14:55:11 -04:00
|
|
|
device = CSVModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
to_field_name='name'
|
|
|
|
)
|
|
|
|
manufacturer = CSVModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
to_field_name='name',
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = InventoryItem
|
|
|
|
fields = InventoryItem.csv_headers
|
|
|
|
|
|
|
|
|
|
|
|
class InventoryItemBulkCreateForm(
|
2020-07-14 15:51:13 -04:00
|
|
|
form_from_model(InventoryItem, ['manufacturer', 'part_id', 'serial', 'asset_tag', 'discovered']),
|
2020-07-01 14:55:11 -04:00
|
|
|
DeviceBulkAddComponentForm
|
|
|
|
):
|
2021-03-01 13:42:31 -05:00
|
|
|
model = InventoryItem
|
2020-07-14 15:51:13 -04:00
|
|
|
field_order = (
|
|
|
|
'name_pattern', 'label_pattern', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'discovered', 'description',
|
|
|
|
'tags',
|
2020-07-01 14:55:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-07-02 10:46:02 -04:00
|
|
|
class InventoryItemBulkEditForm(
|
|
|
|
form_from_model(InventoryItem, ['label', 'manufacturer', 'part_id', 'description']),
|
|
|
|
BootstrapMixin,
|
|
|
|
AddRemoveTagsForm,
|
2021-03-01 13:57:57 -05:00
|
|
|
CustomFieldBulkEditForm
|
2020-07-02 10:46:02 -04:00
|
|
|
):
|
2020-07-01 14:55:11 -04:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=InventoryItem.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
|
|
|
manufacturer = DynamicModelChoiceField(
|
|
|
|
queryset=Manufacturer.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2021-03-01 13:57:57 -05:00
|
|
|
nullable_fields = ['label', 'manufacturer', 'part_id', 'description']
|
2020-07-01 14:55:11 -04:00
|
|
|
|
|
|
|
|
2020-07-02 10:46:02 -04:00
|
|
|
class InventoryItemFilterForm(DeviceComponentFilterForm):
|
2020-07-01 14:55:11 -04:00
|
|
|
model = InventoryItem
|
2021-03-01 17:24:30 -05:00
|
|
|
manufacturer_id = DynamicModelMultipleChoiceField(
|
2020-07-01 14:55:11 -04:00
|
|
|
queryset=Manufacturer.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Manufacturer')
|
2020-07-01 14:55:11 -04:00
|
|
|
)
|
2020-07-02 10:46:02 -04:00
|
|
|
serial = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
asset_tag = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
2020-07-01 14:55:11 -04:00
|
|
|
discovered = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2(
|
|
|
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
|
|
)
|
|
|
|
)
|
|
|
|
tag = TagFilterField(model)
|
|
|
|
|
|
|
|
|
2018-10-22 16:58:24 -04:00
|
|
|
#
|
|
|
|
# Cables
|
|
|
|
#
|
|
|
|
|
2020-11-10 12:33:20 -05:00
|
|
|
class ConnectCableToDeviceForm(BootstrapMixin, CustomFieldModelForm):
|
2019-04-09 16:49:04 -04:00
|
|
|
"""
|
|
|
|
Base form for connecting a Cable to a Device component
|
|
|
|
"""
|
2020-11-04 15:27:41 -05:00
|
|
|
termination_b_region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
label='Region',
|
|
|
|
required=False
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
termination_b_site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
label='Site group',
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
termination_b_site = DynamicModelChoiceField(
|
2017-02-17 14:48:00 -05:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
label='Site',
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$termination_b_region',
|
|
|
|
'group_id': '$termination_b_site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2017-02-17 14:48:00 -05:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
termination_b_rack = DynamicModelChoiceField(
|
2017-02-17 14:48:00 -05:00
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
label='Rack',
|
|
|
|
required=False,
|
2020-08-12 10:05:12 -04:00
|
|
|
null_option='None',
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$termination_b_site'
|
|
|
|
}
|
2017-02-17 14:48:00 -05:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
termination_b_device = DynamicModelChoiceField(
|
2017-02-17 14:48:00 -05:00
|
|
|
queryset=Device.objects.all(),
|
|
|
|
label='Device',
|
2019-01-03 03:00:27 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$termination_b_site',
|
|
|
|
'rack_id': '$termination_b_rack',
|
2020-08-12 12:58:32 -04:00
|
|
|
}
|
2017-02-17 14:48:00 -05:00
|
|
|
)
|
2020-11-10 12:33:20 -05:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2019-04-09 16:49:04 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Cable
|
|
|
|
fields = [
|
2020-11-04 15:27:41 -05:00
|
|
|
'termination_b_region', 'termination_b_site', 'termination_b_rack', 'termination_b_device',
|
2020-11-10 12:33:20 -05:00
|
|
|
'termination_b_id', 'type', 'status', 'label', 'color', 'length', 'length_unit', 'tags',
|
2019-04-09 16:49:04 -04:00
|
|
|
]
|
2020-01-22 16:07:09 -05:00
|
|
|
widgets = {
|
|
|
|
'status': StaticSelect2,
|
|
|
|
'type': StaticSelect2,
|
|
|
|
'length_unit': StaticSelect2,
|
|
|
|
}
|
2019-04-09 16:49:04 -04:00
|
|
|
|
2020-08-12 12:58:32 -04:00
|
|
|
def clean_termination_b_id(self):
|
|
|
|
# Return the PK rather than the object
|
|
|
|
return getattr(self.cleaned_data['termination_b_id'], 'pk', None)
|
|
|
|
|
2019-04-09 16:49:04 -04:00
|
|
|
|
|
|
|
class ConnectCableToConsolePortForm(ConnectCableToDeviceForm):
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=ConsolePort.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'device_id': '$termination_b_device'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2019-04-09 16:49:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectCableToConsoleServerPortForm(ConnectCableToDeviceForm):
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=ConsoleServerPort.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'device_id': '$termination_b_device'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2019-04-09 16:49:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectCableToPowerPortForm(ConnectCableToDeviceForm):
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=PowerPort.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'device_id': '$termination_b_device'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2018-10-22 16:58:24 -04:00
|
|
|
)
|
2019-04-09 16:49:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ConnectCableToPowerOutletForm(ConnectCableToDeviceForm):
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=PowerOutlet.objects.all(),
|
2018-10-22 16:58:24 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'device_id': '$termination_b_device'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2019-04-09 16:49:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectCableToInterfaceForm(ConnectCableToDeviceForm):
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'device_id': '$termination_b_device',
|
|
|
|
'kind': 'physical',
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2016-03-01 11:23:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-04-09 16:49:04 -04:00
|
|
|
class ConnectCableToFrontPortForm(ConnectCableToDeviceForm):
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=FrontPort.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'device_id': '$termination_b_device'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2019-04-09 16:49:04 -04:00
|
|
|
)
|
|
|
|
|
2018-10-22 16:58:24 -04:00
|
|
|
|
2019-04-09 16:49:04 -04:00
|
|
|
class ConnectCableToRearPortForm(ConnectCableToDeviceForm):
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=RearPort.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'device_id': '$termination_b_device'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2019-04-09 16:49:04 -04:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2020-11-10 12:33:20 -05:00
|
|
|
class ConnectCableToCircuitTerminationForm(BootstrapMixin, CustomFieldModelForm):
|
2020-02-11 10:43:22 -05:00
|
|
|
termination_b_provider = DynamicModelChoiceField(
|
2019-03-21 17:47:43 -04:00
|
|
|
queryset=Provider.objects.all(),
|
|
|
|
label='Provider',
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False
|
2019-03-21 17:47:43 -04:00
|
|
|
)
|
2020-11-04 15:27:41 -05:00
|
|
|
termination_b_region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
label='Region',
|
|
|
|
required=False
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
termination_b_site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
label='Site group',
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
termination_b_site = DynamicModelChoiceField(
|
2019-04-09 16:49:04 -04:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
label='Site',
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$termination_b_region',
|
|
|
|
'group_id': '$termination_b_site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2019-04-09 16:49:04 -04:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
termination_b_circuit = DynamicModelChoiceField(
|
2019-03-21 17:47:43 -04:00
|
|
|
queryset=Circuit.objects.all(),
|
|
|
|
label='Circuit',
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'provider_id': '$termination_b_provider',
|
|
|
|
'site_id': '$termination_b_site',
|
2020-08-12 12:58:32 -04:00
|
|
|
}
|
2019-03-21 17:47:43 -04:00
|
|
|
)
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=CircuitTermination.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Side',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'circuit_id': '$termination_b_circuit'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2019-03-21 17:47:43 -04:00
|
|
|
)
|
2020-11-10 12:33:20 -05:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2019-03-21 17:47:43 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Cable
|
|
|
|
fields = [
|
2020-11-04 15:27:41 -05:00
|
|
|
'termination_b_provider', 'termination_b_region', 'termination_b_site', 'termination_b_circuit',
|
2020-11-10 12:33:20 -05:00
|
|
|
'termination_b_id', 'type', 'status', 'label', 'color', 'length', 'length_unit', 'tags',
|
2019-03-21 17:47:43 -04:00
|
|
|
]
|
|
|
|
|
2020-08-12 12:58:32 -04:00
|
|
|
def clean_termination_b_id(self):
|
|
|
|
# Return the PK rather than the object
|
|
|
|
return getattr(self.cleaned_data['termination_b_id'], 'pk', None)
|
|
|
|
|
2019-03-21 17:47:43 -04:00
|
|
|
|
2020-11-10 12:33:20 -05:00
|
|
|
class ConnectCableToPowerFeedForm(BootstrapMixin, CustomFieldModelForm):
|
2020-11-04 15:27:41 -05:00
|
|
|
termination_b_region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
label='Region',
|
|
|
|
required=False
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
termination_b_site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
label='Site group',
|
|
|
|
required=False
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
termination_b_site = DynamicModelChoiceField(
|
2019-03-21 17:47:43 -04:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
label='Site',
|
2020-01-13 12:05:06 +00:00
|
|
|
required=False,
|
2020-11-04 15:27:41 -05:00
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$termination_b_region',
|
|
|
|
'group_id': '$termination_b_site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2019-03-21 17:47:43 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
termination_b_location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
|
|
|
label='Location',
|
2019-03-21 17:47:43 -04:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$termination_b_site'
|
|
|
|
}
|
2019-03-21 17:47:43 -04:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
termination_b_powerpanel = DynamicModelChoiceField(
|
2019-03-21 17:47:43 -04:00
|
|
|
queryset=PowerPanel.objects.all(),
|
|
|
|
label='Power Panel',
|
2020-01-13 12:05:06 +00:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$termination_b_site',
|
2021-03-03 13:30:33 -05:00
|
|
|
'location_id': '$termination_b_location',
|
2020-08-12 12:58:32 -04:00
|
|
|
}
|
2019-03-21 17:47:43 -04:00
|
|
|
)
|
2020-08-12 12:58:32 -04:00
|
|
|
termination_b_id = DynamicModelChoiceField(
|
|
|
|
queryset=PowerFeed.objects.all(),
|
2019-04-09 16:49:04 -04:00
|
|
|
label='Name',
|
2021-03-01 21:34:42 -05:00
|
|
|
disabled_indicator='_occupied',
|
2020-08-12 12:58:32 -04:00
|
|
|
query_params={
|
|
|
|
'power_panel_id': '$termination_b_powerpanel'
|
2020-08-12 13:30:49 -04:00
|
|
|
}
|
2019-03-21 17:47:43 -04:00
|
|
|
)
|
2020-11-10 12:33:20 -05:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2019-03-21 17:47:43 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Cable
|
|
|
|
fields = [
|
2021-03-03 13:30:33 -05:00
|
|
|
'termination_b_location', 'termination_b_powerpanel', 'termination_b_id', 'type', 'status', 'label',
|
2020-11-10 12:33:20 -05:00
|
|
|
'color', 'length', 'length_unit', 'tags',
|
2019-03-21 17:47:43 -04:00
|
|
|
]
|
|
|
|
|
2020-08-12 12:58:32 -04:00
|
|
|
def clean_termination_b_id(self):
|
|
|
|
# Return the PK rather than the object
|
|
|
|
return getattr(self.cleaned_data['termination_b_id'], 'pk', None)
|
|
|
|
|
2019-03-21 17:47:43 -04:00
|
|
|
|
2020-09-17 14:22:14 -04:00
|
|
|
class CableForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2020-06-10 14:55:46 -04:00
|
|
|
required=False
|
|
|
|
)
|
2018-10-25 15:51:12 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Cable
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-10 14:55:46 -04:00
|
|
|
'type', 'status', 'label', 'color', 'length', 'length_unit', 'tags',
|
2016-03-01 11:23:03 -05:00
|
|
|
]
|
2020-01-22 16:07:09 -05:00
|
|
|
widgets = {
|
|
|
|
'status': StaticSelect2,
|
|
|
|
'type': StaticSelect2,
|
|
|
|
'length_unit': StaticSelect2,
|
|
|
|
}
|
2020-05-07 10:34:33 -04:00
|
|
|
error_messages = {
|
|
|
|
'length': {
|
|
|
|
'max_value': 'Maximum length is 32767 (any unit)'
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2020-12-29 12:43:52 -05:00
|
|
|
class CableCSVForm(CustomFieldModelCSVForm):
|
2018-10-31 17:05:25 -04:00
|
|
|
# Termination A
|
2020-05-06 09:43:10 -04:00
|
|
|
side_a_device = CSVModelChoiceField(
|
2017-02-17 14:48:00 -05:00
|
|
|
queryset=Device.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Side A device'
|
2018-10-31 17:05:25 -04:00
|
|
|
)
|
2020-12-01 11:03:05 -05:00
|
|
|
side_a_type = CSVContentTypeField(
|
2018-10-31 17:05:25 -04:00
|
|
|
queryset=ContentType.objects.all(),
|
2020-01-15 15:51:51 -05:00
|
|
|
limit_choices_to=CABLE_TERMINATION_MODELS,
|
2018-11-01 09:59:53 -04:00
|
|
|
help_text='Side A type'
|
2017-02-17 14:48:00 -05:00
|
|
|
)
|
2018-11-01 09:59:53 -04:00
|
|
|
side_a_name = forms.CharField(
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Side A component name'
|
2017-06-05 15:04:23 -04:00
|
|
|
)
|
2018-10-31 17:05:25 -04:00
|
|
|
|
|
|
|
# Termination B
|
2020-05-06 09:43:10 -04:00
|
|
|
side_b_device = CSVModelChoiceField(
|
2017-02-17 14:48:00 -05:00
|
|
|
queryset=Device.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Side B device'
|
2018-10-31 17:05:25 -04:00
|
|
|
)
|
2020-12-01 11:03:05 -05:00
|
|
|
side_b_type = CSVContentTypeField(
|
2018-10-31 17:05:25 -04:00
|
|
|
queryset=ContentType.objects.all(),
|
2020-01-15 15:51:51 -05:00
|
|
|
limit_choices_to=CABLE_TERMINATION_MODELS,
|
2018-11-01 09:59:53 -04:00
|
|
|
help_text='Side B type'
|
2017-02-17 14:48:00 -05:00
|
|
|
)
|
2018-11-01 09:59:53 -04:00
|
|
|
side_b_name = forms.CharField(
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Side B component name'
|
2017-06-05 15:04:23 -04:00
|
|
|
)
|
2018-10-31 17:05:25 -04:00
|
|
|
|
|
|
|
# Cable attributes
|
|
|
|
status = CSVChoiceField(
|
2019-12-10 09:55:10 -05:00
|
|
|
choices=CableStatusChoices,
|
2018-10-31 17:05:25 -04:00
|
|
|
required=False,
|
2017-06-07 13:22:06 -04:00
|
|
|
help_text='Connection status'
|
|
|
|
)
|
2018-11-01 09:59:53 -04:00
|
|
|
type = CSVChoiceField(
|
2019-11-25 19:57:13 -05:00
|
|
|
choices=CableTypeChoices,
|
2018-11-01 09:59:53 -04:00
|
|
|
required=False,
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Physical medium classification'
|
2018-11-01 09:59:53 -04:00
|
|
|
)
|
|
|
|
length_unit = CSVChoiceField(
|
2019-11-25 20:40:29 -05:00
|
|
|
choices=CableLengthUnitChoices,
|
2018-11-01 09:59:53 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Length unit'
|
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2017-06-05 15:04:23 -04:00
|
|
|
class Meta:
|
2018-10-31 17:05:25 -04:00
|
|
|
model = Cable
|
|
|
|
fields = [
|
2018-11-01 09:59:53 -04:00
|
|
|
'side_a_device', 'side_a_type', 'side_a_name', 'side_b_device', 'side_b_type', 'side_b_name', 'type',
|
|
|
|
'status', 'label', 'color', 'length', 'length_unit',
|
2018-10-31 17:05:25 -04:00
|
|
|
]
|
2018-11-01 09:59:53 -04:00
|
|
|
help_texts = {
|
2020-05-01 15:40:34 -04:00
|
|
|
'color': mark_safe('RGB color in hexadecimal (e.g. <code>00ff00</code>)'),
|
2018-11-01 09:59:53 -04:00
|
|
|
}
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-12-02 13:17:30 -05:00
|
|
|
def _clean_side(self, side):
|
|
|
|
"""
|
|
|
|
Derive a Cable's A/B termination objects.
|
|
|
|
|
|
|
|
:param side: 'a' or 'b'
|
|
|
|
"""
|
|
|
|
assert side in 'ab', f"Invalid side designation: {side}"
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-12-02 13:17:30 -05:00
|
|
|
device = self.cleaned_data.get(f'side_{side}_device')
|
|
|
|
content_type = self.cleaned_data.get(f'side_{side}_type')
|
|
|
|
name = self.cleaned_data.get(f'side_{side}_name')
|
2018-10-31 17:05:25 -04:00
|
|
|
if not device or not content_type or not name:
|
2017-06-05 15:04:23 -04:00
|
|
|
return None
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2018-10-31 17:05:25 -04:00
|
|
|
model = content_type.model_class()
|
2017-06-05 15:04:23 -04:00
|
|
|
try:
|
2020-12-02 13:17:30 -05:00
|
|
|
termination_object = model.objects.get(device=device, name=name)
|
2018-10-31 17:05:25 -04:00
|
|
|
if termination_object.cable is not None:
|
2020-12-02 13:17:30 -05:00
|
|
|
raise forms.ValidationError(f"Side {side.upper()}: {device} {termination_object} is already connected")
|
2018-10-31 17:05:25 -04:00
|
|
|
except ObjectDoesNotExist:
|
2020-12-02 13:17:30 -05:00
|
|
|
raise forms.ValidationError(f"{side.upper()} side termination not found: {device} {name}")
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-12-02 13:17:30 -05:00
|
|
|
setattr(self.instance, f'termination_{side}', termination_object)
|
2018-10-31 17:05:25 -04:00
|
|
|
return termination_object
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-12-02 13:17:30 -05:00
|
|
|
def clean_side_a_name(self):
|
|
|
|
return self._clean_side('a')
|
2018-10-31 17:05:25 -04:00
|
|
|
|
2020-12-02 13:17:30 -05:00
|
|
|
def clean_side_b_name(self):
|
|
|
|
return self._clean_side('b')
|
2018-10-31 17:05:25 -04:00
|
|
|
|
2018-11-06 12:12:01 -05:00
|
|
|
def clean_length_unit(self):
|
|
|
|
# Avoid trying to save as NULL
|
|
|
|
length_unit = self.cleaned_data.get('length_unit', None)
|
|
|
|
return length_unit if length_unit is not None else ''
|
|
|
|
|
2018-10-31 17:05:25 -04:00
|
|
|
|
2020-12-29 11:55:31 -05:00
|
|
|
class CableBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2018-11-01 13:19:24 -04:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Cable.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
|
|
|
type = forms.ChoiceField(
|
2019-11-25 19:57:13 -05:00
|
|
|
choices=add_blank_choice(CableTypeChoices),
|
2018-11-01 13:19:24 -04:00
|
|
|
required=False,
|
2019-01-08 15:35:34 -08:00
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
2018-11-01 13:19:24 -04:00
|
|
|
)
|
|
|
|
status = forms.ChoiceField(
|
2019-12-10 09:55:10 -05:00
|
|
|
choices=add_blank_choice(CableStatusChoices),
|
2018-11-01 13:19:24 -04:00
|
|
|
required=False,
|
2019-04-04 12:43:14 -04:00
|
|
|
widget=StaticSelect2(),
|
2018-11-01 13:19:24 -04:00
|
|
|
initial=''
|
|
|
|
)
|
|
|
|
label = forms.CharField(
|
|
|
|
max_length=100,
|
2019-04-04 12:43:14 -04:00
|
|
|
required=False
|
2018-11-01 13:19:24 -04:00
|
|
|
)
|
|
|
|
color = forms.CharField(
|
2020-01-24 14:21:59 -05:00
|
|
|
max_length=6, # RGB color code
|
2018-11-01 13:19:24 -04:00
|
|
|
required=False,
|
|
|
|
widget=ColorSelect()
|
|
|
|
)
|
|
|
|
length = forms.IntegerField(
|
|
|
|
min_value=1,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
length_unit = forms.ChoiceField(
|
2019-11-25 20:40:29 -05:00
|
|
|
choices=add_blank_choice(CableLengthUnitChoices),
|
2018-11-01 13:19:24 -04:00
|
|
|
required=False,
|
2019-01-08 15:35:34 -08:00
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
2018-11-01 13:19:24 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2018-11-27 11:57:29 -05:00
|
|
|
nullable_fields = [
|
|
|
|
'type', 'status', 'label', 'color', 'length',
|
|
|
|
]
|
2018-11-01 13:19:24 -04:00
|
|
|
|
|
|
|
def clean(self):
|
2020-12-28 12:54:42 -05:00
|
|
|
super().clean()
|
2018-11-01 13:19:24 -04:00
|
|
|
|
|
|
|
# Validate length/unit
|
|
|
|
length = self.cleaned_data.get('length')
|
|
|
|
length_unit = self.cleaned_data.get('length_unit')
|
|
|
|
if length and not length_unit:
|
|
|
|
raise forms.ValidationError({
|
|
|
|
'length_unit': "Must specify a unit when setting length"
|
|
|
|
})
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2018-11-01 13:19:24 -04:00
|
|
|
|
2021-03-31 17:02:21 -04:00
|
|
|
class CableFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
2018-10-24 14:59:46 -04:00
|
|
|
model = Cable
|
2018-11-27 11:57:29 -05:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-11-04 15:27:41 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-11-04 15:27:41 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-10-10 12:28:17 -04:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2019-10-10 12:28:17 -04:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
tenant_id = DynamicModelMultipleChoiceField(
|
2020-01-10 15:59:56 +00:00
|
|
|
queryset=Tenant.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Tenant')
|
2020-01-10 15:59:56 +00:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
rack_id = DynamicModelMultipleChoiceField(
|
2019-10-10 12:28:17 -04:00
|
|
|
queryset=Rack.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2019-10-10 12:28:17 -04:00
|
|
|
label='Rack',
|
2020-08-12 09:47:13 -04:00
|
|
|
null_option='None',
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
2020-08-12 12:36:53 -04:00
|
|
|
}
|
2019-10-10 12:28:17 -04:00
|
|
|
)
|
2019-01-08 15:35:34 -08:00
|
|
|
type = forms.MultipleChoiceField(
|
2019-11-25 19:57:13 -05:00
|
|
|
choices=add_blank_choice(CableTypeChoices),
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
2018-10-24 14:59:46 -04:00
|
|
|
)
|
2019-02-20 11:36:55 -05:00
|
|
|
status = forms.ChoiceField(
|
|
|
|
required=False,
|
2019-12-10 09:55:10 -05:00
|
|
|
choices=add_blank_choice(CableStatusChoices),
|
2019-02-20 11:36:55 -05:00
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2019-01-08 15:35:34 -08:00
|
|
|
color = forms.CharField(
|
2020-01-24 14:21:59 -05:00
|
|
|
max_length=6, # RGB color code
|
2019-01-08 15:35:34 -08:00
|
|
|
required=False,
|
|
|
|
widget=ColorSelect()
|
2018-10-24 14:59:46 -04:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
device_id = DynamicModelMultipleChoiceField(
|
2020-01-02 21:21:52 +00:00
|
|
|
queryset=Device.objects.all(),
|
2019-04-29 11:29:07 -04:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id',
|
|
|
|
'tenant_id': '$tenant_id',
|
2020-08-12 12:36:53 -04:00
|
|
|
'rack_id': '$rack_id',
|
2021-03-01 17:24:30 -05:00
|
|
|
},
|
|
|
|
label=_('Device')
|
2019-04-29 11:29:07 -04:00
|
|
|
)
|
2020-06-10 14:55:46 -04:00
|
|
|
tag = TagFilterField(model)
|
2017-06-05 15:04:23 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Connections
|
|
|
|
#
|
|
|
|
|
2016-12-21 14:15:18 -05:00
|
|
|
class ConsoleConnectionFilterForm(BootstrapMixin, forms.Form):
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-11-04 15:27:41 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-11-04 15:27:41 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
device_id = DynamicModelMultipleChoiceField(
|
2020-01-02 21:21:52 +00:00
|
|
|
queryset=Device.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
|
|
|
label=_('Device')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2016-12-21 14:15:18 -05:00
|
|
|
class PowerConnectionFilterForm(BootstrapMixin, forms.Form):
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-11-04 15:27:41 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-11-04 15:27:41 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
device_id = DynamicModelMultipleChoiceField(
|
2020-01-02 21:21:52 +00:00
|
|
|
queryset=Device.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
|
|
|
label=_('Device')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2016-12-21 14:15:18 -05:00
|
|
|
class InterfaceConnectionFilterForm(BootstrapMixin, forms.Form):
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-11-04 15:27:41 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-11-04 15:27:41 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2018-11-27 11:57:29 -05:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
device_id = DynamicModelMultipleChoiceField(
|
2020-01-02 21:21:52 +00:00
|
|
|
queryset=Device.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
|
|
|
label=_('Device')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2017-11-17 16:47:26 -05:00
|
|
|
#
|
|
|
|
# Virtual chassis
|
|
|
|
#
|
|
|
|
|
2017-11-29 12:58:36 -05:00
|
|
|
class DeviceSelectionForm(forms.Form):
|
2018-11-27 11:57:29 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2017-11-29 12:58:36 -05:00
|
|
|
|
|
|
|
|
2020-09-17 14:22:14 -04:00
|
|
|
class VirtualChassisCreateForm(BootstrapMixin, CustomFieldModelForm):
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-06-24 15:12:22 -04:00
|
|
|
site = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2020-06-24 15:12:22 -04:00
|
|
|
)
|
|
|
|
rack = DynamicModelChoiceField(
|
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
required=False,
|
2020-08-12 10:05:12 -04:00
|
|
|
null_option='None',
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2020-06-24 15:12:22 -04:00
|
|
|
)
|
|
|
|
members = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site',
|
|
|
|
'rack_id': '$rack',
|
|
|
|
}
|
2020-06-24 15:12:22 -04:00
|
|
|
)
|
|
|
|
initial_position = forms.IntegerField(
|
|
|
|
initial=1,
|
|
|
|
required=False,
|
|
|
|
help_text='Position of the first member device. Increases by one for each additional member.'
|
|
|
|
)
|
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = VirtualChassis
|
|
|
|
fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'name', 'domain', 'region', 'site_group', 'site', 'rack', 'members', 'initial_position', 'tags',
|
2020-06-24 15:12:22 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
instance = super().save(*args, **kwargs)
|
|
|
|
|
|
|
|
# Assign VC members
|
|
|
|
if instance.pk:
|
|
|
|
initial_position = self.cleaned_data.get('initial_position') or 1
|
|
|
|
for i, member in enumerate(self.cleaned_data['members'], start=initial_position):
|
|
|
|
member.virtual_chassis = instance
|
|
|
|
member.vc_position = i
|
|
|
|
member.save()
|
|
|
|
|
|
|
|
return instance
|
|
|
|
|
|
|
|
|
2020-09-17 14:22:14 -04:00
|
|
|
class VirtualChassisForm(BootstrapMixin, CustomFieldModelForm):
|
2020-06-24 15:12:22 -04:00
|
|
|
master = forms.ModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
required=False,
|
|
|
|
)
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2018-11-27 11:57:29 -05:00
|
|
|
required=False
|
|
|
|
)
|
2017-11-29 12:58:36 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = VirtualChassis
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
2020-06-24 15:12:22 -04:00
|
|
|
'name', 'domain', 'master', 'tags',
|
2018-11-27 11:57:29 -05:00
|
|
|
]
|
2018-02-14 11:14:04 -05:00
|
|
|
widgets = {
|
2018-11-27 11:57:29 -05:00
|
|
|
'master': SelectWithPK(),
|
2018-02-14 11:14:04 -05:00
|
|
|
}
|
2017-11-29 12:58:36 -05:00
|
|
|
|
2020-06-24 15:12:22 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
self.fields['master'].queryset = Device.objects.filter(virtual_chassis=self.instance)
|
|
|
|
|
2018-01-19 12:34:09 -05:00
|
|
|
|
2018-02-14 12:05:00 -05:00
|
|
|
class BaseVCMemberFormSet(forms.BaseModelFormSet):
|
|
|
|
|
|
|
|
def clean(self):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().clean()
|
2018-02-14 12:05:00 -05:00
|
|
|
|
|
|
|
# Check for duplicate VC position values
|
|
|
|
vc_position_list = []
|
|
|
|
for form in self.forms:
|
2018-03-01 14:40:39 -05:00
|
|
|
vc_position = form.cleaned_data.get('vc_position')
|
|
|
|
if vc_position:
|
|
|
|
if vc_position in vc_position_list:
|
|
|
|
error_msg = 'A virtual chassis member already exists in position {}.'.format(vc_position)
|
|
|
|
form.add_error('vc_position', error_msg)
|
|
|
|
vc_position_list.append(vc_position)
|
2018-02-14 12:05:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
class DeviceVCMembershipForm(forms.ModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Device
|
2018-11-27 11:57:29 -05:00
|
|
|
fields = [
|
|
|
|
'vc_position', 'vc_priority',
|
|
|
|
]
|
2018-02-14 12:05:00 -05:00
|
|
|
labels = {
|
|
|
|
'vc_position': 'Position',
|
|
|
|
'vc_priority': 'Priority',
|
|
|
|
}
|
|
|
|
|
2018-02-26 13:28:05 -05:00
|
|
|
def __init__(self, validate_vc_position=False, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2018-02-14 12:05:00 -05:00
|
|
|
|
|
|
|
# Require VC position (only required when the Device is a VirtualChassis member)
|
|
|
|
self.fields['vc_position'].required = True
|
|
|
|
|
|
|
|
# Validation of vc_position is optional. This is only required when adding a new member to an existing
|
|
|
|
# VirtualChassis. Otherwise, vc_position validation is handled by BaseVCMemberFormSet.
|
|
|
|
self.validate_vc_position = validate_vc_position
|
|
|
|
|
|
|
|
def clean_vc_position(self):
|
|
|
|
vc_position = self.cleaned_data['vc_position']
|
|
|
|
|
|
|
|
if self.validate_vc_position:
|
|
|
|
conflicting_members = Device.objects.filter(
|
|
|
|
virtual_chassis=self.instance.virtual_chassis,
|
|
|
|
vc_position=vc_position
|
|
|
|
)
|
|
|
|
if conflicting_members.exists():
|
|
|
|
raise forms.ValidationError(
|
|
|
|
'A virtual chassis member already exists in position {}.'.format(vc_position)
|
|
|
|
)
|
|
|
|
|
|
|
|
return vc_position
|
|
|
|
|
|
|
|
|
2020-02-10 17:23:52 -05:00
|
|
|
class VCMemberSelectForm(BootstrapMixin, forms.Form):
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
site = DynamicModelChoiceField(
|
2018-02-01 11:39:13 -05:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2018-02-01 11:39:13 -05:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
rack = DynamicModelChoiceField(
|
2018-02-01 11:39:13 -05:00
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
required=False,
|
2020-08-12 10:05:12 -04:00
|
|
|
null_option='None',
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2018-02-01 11:39:13 -05:00
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
device = DynamicModelChoiceField(
|
2020-08-12 10:17:21 -04:00
|
|
|
queryset=Device.objects.all(),
|
|
|
|
query_params={
|
2020-08-12 12:36:53 -04:00
|
|
|
'site_id': '$site',
|
|
|
|
'rack_id': '$rack',
|
|
|
|
'virtual_chassis_id': 'null',
|
2020-08-12 10:17:21 -04:00
|
|
|
}
|
2018-02-01 11:39:13 -05:00
|
|
|
)
|
|
|
|
|
2018-02-01 15:53:59 -05:00
|
|
|
def clean_device(self):
|
|
|
|
device = self.cleaned_data['device']
|
|
|
|
if device.virtual_chassis is not None:
|
2018-11-27 11:57:29 -05:00
|
|
|
raise forms.ValidationError(
|
2020-06-24 15:12:22 -04:00
|
|
|
f"Device {device} is already assigned to a virtual chassis."
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2018-02-14 12:05:00 -05:00
|
|
|
return device
|
2018-02-21 09:53:23 -05:00
|
|
|
|
|
|
|
|
2020-12-29 11:55:31 -05:00
|
|
|
class VirtualChassisBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2020-04-24 15:20:52 -04:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=VirtualChassis.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
|
|
|
domain = forms.CharField(
|
|
|
|
max_length=30,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['domain']
|
|
|
|
|
|
|
|
|
2020-12-29 12:43:52 -05:00
|
|
|
class VirtualChassisCSVForm(CustomFieldModelCSVForm):
|
2020-06-24 15:29:25 -04:00
|
|
|
master = CSVModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
|
|
|
to_field_name='name',
|
|
|
|
required=False,
|
|
|
|
help_text='Master device'
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = VirtualChassis
|
|
|
|
fields = VirtualChassis.csv_headers
|
|
|
|
|
|
|
|
|
2021-03-01 17:24:30 -05:00
|
|
|
class VirtualChassisFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
|
2018-02-21 09:53:23 -05:00
|
|
|
model = VirtualChassis
|
2021-03-08 13:28:53 -05:00
|
|
|
field_order = ['q', 'region_id', 'site_group_id', 'site_id', 'tenant_group_id', 'tenant_id']
|
2018-11-27 11:57:29 -05:00
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2018-11-27 11:57:29 -05:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-01-03 13:52:50 -05:00
|
|
|
queryset=Region.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Region')
|
2019-05-09 14:32:49 -04:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label=_('Site group')
|
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2018-02-21 09:53:23 -05:00
|
|
|
)
|
2020-01-14 08:22:27 +00:00
|
|
|
tag = TagFilterField(model)
|
2020-01-13 20:16:13 +00:00
|
|
|
|
2019-03-11 22:40:52 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Power panels
|
|
|
|
#
|
|
|
|
|
2020-09-17 14:22:14 -04:00
|
|
|
class PowerPanelForm(BootstrapMixin, CustomFieldModelForm):
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
site = DynamicModelChoiceField(
|
2020-11-04 15:27:41 -05:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2019-03-11 22:40:52 -04:00
|
|
|
)
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2020-06-10 14:55:46 -04:00
|
|
|
required=False
|
|
|
|
)
|
2019-03-11 22:40:52 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerPanel
|
|
|
|
fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'region', 'site_group', 'site', 'location', 'name', 'tags',
|
2019-03-11 22:40:52 -04:00
|
|
|
]
|
2021-02-25 13:51:48 -05:00
|
|
|
fieldsets = (
|
2021-03-29 16:23:26 -04:00
|
|
|
('Power Panel', ('region', 'site_group', 'site', 'location', 'name', 'tags')),
|
2021-02-25 13:51:48 -05:00
|
|
|
)
|
2019-03-11 22:40:52 -04:00
|
|
|
|
|
|
|
|
2020-12-29 12:43:52 -05:00
|
|
|
class PowerPanelCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
site = CSVModelChoiceField(
|
2019-03-11 22:40:52 -04:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Name of parent site'
|
2019-03-11 22:40:52 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = CSVModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2019-04-09 14:55:17 -04:00
|
|
|
required=False,
|
2020-05-06 09:58:12 -04:00
|
|
|
to_field_name='name'
|
2019-03-11 22:40:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerPanel
|
|
|
|
fields = PowerPanel.csv_headers
|
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
|
super().__init__(data, *args, **kwargs)
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
if data:
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
# Limit group queryset by assigned site
|
|
|
|
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
2021-03-03 13:30:33 -05:00
|
|
|
self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2019-03-11 22:40:52 -04:00
|
|
|
|
2020-12-29 11:55:31 -05:00
|
|
|
class PowerPanelBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
2020-03-06 16:05:26 -05:00
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=PowerPanel.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-03-06 16:05:26 -05:00
|
|
|
site = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 15:27:41 -05:00
|
|
|
required=False,
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 15:27:41 -05:00
|
|
|
}
|
2020-03-06 16:05:26 -05:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2020-03-06 16:05:26 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2021-03-03 13:30:33 -05:00
|
|
|
nullable_fields = ['location']
|
2020-03-06 16:05:26 -05:00
|
|
|
|
|
|
|
|
2019-03-12 12:05:58 -04:00
|
|
|
class PowerPanelFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|
|
|
model = PowerPanel
|
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2019-03-12 12:05:58 -04:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-01-03 13:52:50 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-01-03 13:52:50 -05:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label=_('Site group')
|
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-03-12 12:05:58 -04:00
|
|
|
queryset=Site.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2019-03-12 12:05:58 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
null_option='None',
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
2021-03-03 13:30:33 -05:00
|
|
|
label=_('Location')
|
2019-03-12 12:05:58 -04:00
|
|
|
)
|
2020-06-10 14:55:46 -04:00
|
|
|
tag = TagFilterField(model)
|
2019-03-12 12:05:58 -04:00
|
|
|
|
|
|
|
|
2019-03-11 22:40:52 -04:00
|
|
|
#
|
|
|
|
# Power feeds
|
|
|
|
#
|
|
|
|
|
2020-01-29 10:49:02 -05:00
|
|
|
class PowerFeedForm(BootstrapMixin, CustomFieldModelForm):
|
2020-11-04 15:27:41 -05:00
|
|
|
region = DynamicModelChoiceField(
|
|
|
|
queryset=Region.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites__powerpanel': '$power_panel'
|
|
|
|
}
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group = DynamicModelChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
initial_params={
|
|
|
|
'sites': '$site'
|
|
|
|
}
|
|
|
|
)
|
2020-02-10 17:23:52 -05:00
|
|
|
site = DynamicModelChoiceField(
|
2019-03-12 10:15:56 -04:00
|
|
|
queryset=Site.objects.all(),
|
2020-11-04 11:09:13 -05:00
|
|
|
required=False,
|
|
|
|
initial_params={
|
2020-11-04 13:05:24 -05:00
|
|
|
'powerpanel': '$power_panel'
|
2020-11-04 15:27:41 -05:00
|
|
|
},
|
|
|
|
query_params={
|
2021-03-08 13:28:53 -05:00
|
|
|
'region_id': '$region',
|
|
|
|
'group_id': '$site_group',
|
2020-11-04 11:09:13 -05:00
|
|
|
}
|
2019-03-12 10:15:56 -04:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
power_panel = DynamicModelChoiceField(
|
2020-08-12 12:36:53 -04:00
|
|
|
queryset=PowerPanel.objects.all(),
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
|
|
|
rack = DynamicModelChoiceField(
|
|
|
|
queryset=Rack.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'site_id': '$site'
|
|
|
|
}
|
2020-02-11 10:43:22 -05:00
|
|
|
)
|
2019-04-11 10:49:43 -04:00
|
|
|
comments = CommentField()
|
2020-06-12 09:58:59 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerFeed
|
|
|
|
fields = [
|
2021-03-08 13:28:53 -05:00
|
|
|
'region', 'site_group', 'site', 'power_panel', 'rack', 'name', 'status', 'type', 'mark_connected', 'supply',
|
|
|
|
'phase', 'voltage', 'amperage', 'max_utilization', 'comments', 'tags',
|
2019-03-11 22:40:52 -04:00
|
|
|
]
|
2021-02-25 13:51:48 -05:00
|
|
|
fieldsets = (
|
|
|
|
('Power Panel', ('region', 'site', 'power_panel')),
|
2021-03-01 21:34:42 -05:00
|
|
|
('Power Feed', ('rack', 'name', 'status', 'type', 'mark_connected', 'tags')),
|
2021-02-25 13:51:48 -05:00
|
|
|
('Characteristics', ('supply', 'voltage', 'amperage', 'phase', 'max_utilization')),
|
|
|
|
)
|
2019-03-11 22:40:52 -04:00
|
|
|
widgets = {
|
|
|
|
'status': StaticSelect2(),
|
2019-03-12 11:36:29 -04:00
|
|
|
'type': StaticSelect2(),
|
2019-03-11 22:40:52 -04:00
|
|
|
'supply': StaticSelect2(),
|
|
|
|
'phase': StaticSelect2(),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-29 13:53:26 -05:00
|
|
|
class PowerFeedCSVForm(CustomFieldModelCSVForm):
|
2020-05-06 09:43:10 -04:00
|
|
|
site = CSVModelChoiceField(
|
2019-04-09 14:55:17 -04:00
|
|
|
queryset=Site.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Assigned site'
|
2019-04-09 14:55:17 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
power_panel = CSVModelChoiceField(
|
2019-04-09 14:55:17 -04:00
|
|
|
queryset=PowerPanel.objects.all(),
|
|
|
|
to_field_name='name',
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Upstream power panel'
|
2019-04-09 14:55:17 -04:00
|
|
|
)
|
2021-03-03 13:30:33 -05:00
|
|
|
location = CSVModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2020-05-05 16:15:09 -04:00
|
|
|
to_field_name='name',
|
2019-04-09 14:55:17 -04:00
|
|
|
required=False,
|
2021-03-03 13:30:33 -05:00
|
|
|
help_text="Rack's location (if any)"
|
2019-04-09 14:55:17 -04:00
|
|
|
)
|
2020-05-06 09:43:10 -04:00
|
|
|
rack = CSVModelChoiceField(
|
2020-05-05 16:15:09 -04:00
|
|
|
queryset=Rack.objects.all(),
|
|
|
|
to_field_name='name',
|
2019-04-09 14:55:17 -04:00
|
|
|
required=False,
|
2020-05-06 09:58:12 -04:00
|
|
|
help_text='Rack'
|
2019-04-09 14:55:17 -04:00
|
|
|
)
|
2019-03-11 22:40:52 -04:00
|
|
|
status = CSVChoiceField(
|
2019-11-25 21:21:35 -05:00
|
|
|
choices=PowerFeedStatusChoices,
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Operational status'
|
|
|
|
)
|
2019-03-12 11:36:29 -04:00
|
|
|
type = CSVChoiceField(
|
2019-11-25 21:03:11 -05:00
|
|
|
choices=PowerFeedTypeChoices,
|
2019-03-12 11:36:29 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Primary or redundant'
|
|
|
|
)
|
2019-03-11 22:40:52 -04:00
|
|
|
supply = CSVChoiceField(
|
2019-11-25 21:08:34 -05:00
|
|
|
choices=PowerFeedSupplyChoices,
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False,
|
2020-05-01 15:40:34 -04:00
|
|
|
help_text='Supply type (AC/DC)'
|
2019-03-11 22:40:52 -04:00
|
|
|
)
|
2019-04-09 14:55:17 -04:00
|
|
|
phase = CSVChoiceField(
|
2019-11-25 21:14:04 -05:00
|
|
|
choices=PowerFeedPhaseChoices,
|
2019-04-09 14:55:17 -04:00
|
|
|
required=False,
|
|
|
|
help_text='Single or three-phase'
|
|
|
|
)
|
2019-03-11 22:40:52 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PowerFeed
|
|
|
|
fields = PowerFeed.csv_headers
|
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
|
super().__init__(data, *args, **kwargs)
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
if data:
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
# Limit power_panel queryset by site
|
|
|
|
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
|
|
|
self.fields['power_panel'].queryset = self.fields['power_panel'].queryset.filter(**params)
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2021-03-03 13:30:33 -05:00
|
|
|
# Limit location queryset by site
|
2020-05-05 16:15:09 -04:00
|
|
|
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
2021-03-03 13:30:33 -05:00
|
|
|
self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2020-05-05 16:15:09 -04:00
|
|
|
# Limit rack queryset by site and group
|
|
|
|
params = {
|
|
|
|
f"site__{self.fields['site'].to_field_name}": data.get('site'),
|
2021-03-03 13:30:33 -05:00
|
|
|
f"location__{self.fields['location'].to_field_name}": data.get('location'),
|
2020-05-05 16:15:09 -04:00
|
|
|
}
|
|
|
|
self.fields['rack'].queryset = self.fields['rack'].queryset.filter(**params)
|
2019-04-09 14:55:17 -04:00
|
|
|
|
2019-03-11 22:40:52 -04:00
|
|
|
|
|
|
|
class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=PowerFeed.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput
|
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
power_panel = DynamicModelChoiceField(
|
2019-03-11 22:40:52 -04:00
|
|
|
queryset=PowerPanel.objects.all(),
|
2020-08-12 12:36:53 -04:00
|
|
|
required=False
|
2019-03-11 22:40:52 -04:00
|
|
|
)
|
2020-02-11 10:43:22 -05:00
|
|
|
rack = DynamicModelChoiceField(
|
2019-04-11 10:49:43 -04:00
|
|
|
queryset=Rack.objects.all(),
|
2020-08-13 09:27:21 -04:00
|
|
|
required=False,
|
2019-03-11 22:40:52 -04:00
|
|
|
)
|
2019-03-12 11:36:29 -04:00
|
|
|
status = forms.ChoiceField(
|
2019-11-25 21:21:35 -05:00
|
|
|
choices=add_blank_choice(PowerFeedStatusChoices),
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False,
|
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2019-03-12 11:36:29 -04:00
|
|
|
type = forms.ChoiceField(
|
2019-11-25 21:03:11 -05:00
|
|
|
choices=add_blank_choice(PowerFeedTypeChoices),
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False,
|
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
|
|
|
supply = forms.ChoiceField(
|
2019-11-25 21:08:34 -05:00
|
|
|
choices=add_blank_choice(PowerFeedSupplyChoices),
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False,
|
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
|
|
|
phase = forms.ChoiceField(
|
2019-11-25 21:14:04 -05:00
|
|
|
choices=add_blank_choice(PowerFeedPhaseChoices),
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False,
|
|
|
|
initial='',
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2019-03-12 11:36:29 -04:00
|
|
|
voltage = forms.IntegerField(
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
amperage = forms.IntegerField(
|
|
|
|
required=False
|
|
|
|
)
|
2019-06-17 14:52:11 -04:00
|
|
|
max_utilization = forms.IntegerField(
|
2019-03-11 22:40:52 -04:00
|
|
|
required=False
|
|
|
|
)
|
2021-03-03 10:20:35 -05:00
|
|
|
mark_connected = forms.NullBooleanField(
|
|
|
|
required=False,
|
|
|
|
widget=BulkEditNullBooleanSelect
|
|
|
|
)
|
2020-01-28 16:09:10 -05:00
|
|
|
comments = CommentField(
|
|
|
|
widget=SmallTextarea,
|
|
|
|
label='Comments'
|
2019-03-11 22:40:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = [
|
2021-03-03 13:30:33 -05:00
|
|
|
'location', 'comments',
|
2019-03-11 22:40:52 -04:00
|
|
|
]
|
2019-03-12 12:05:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
class PowerFeedFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|
|
|
model = PowerFeed
|
|
|
|
q = forms.CharField(
|
|
|
|
required=False,
|
2021-03-01 17:24:30 -05:00
|
|
|
label=_('Search')
|
2019-03-12 12:05:58 -04:00
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
region_id = DynamicModelMultipleChoiceField(
|
2020-01-03 13:52:50 -05:00
|
|
|
queryset=Region.objects.all(),
|
2021-03-01 17:24:30 -05:00
|
|
|
required=False,
|
|
|
|
label=_('Region')
|
2020-01-03 13:52:50 -05:00
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
site_group_id = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=SiteGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label=_('Site group')
|
|
|
|
)
|
2021-03-01 17:24:30 -05:00
|
|
|
site_id = DynamicModelMultipleChoiceField(
|
2019-03-12 12:05:58 -04:00
|
|
|
queryset=Site.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'region_id': '$region_id'
|
|
|
|
},
|
|
|
|
label=_('Site')
|
2019-03-12 12:05:58 -04:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
power_panel_id = DynamicModelMultipleChoiceField(
|
2019-04-19 13:17:43 -04:00
|
|
|
queryset=PowerPanel.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
null_option='None',
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
|
|
|
label=_('Power panel')
|
2019-04-19 13:17:43 -04:00
|
|
|
)
|
2020-02-11 09:26:39 -05:00
|
|
|
rack_id = DynamicModelMultipleChoiceField(
|
2019-03-12 12:05:58 -04:00
|
|
|
queryset=Rack.objects.all(),
|
2020-02-11 09:26:39 -05:00
|
|
|
required=False,
|
2020-08-12 12:36:53 -04:00
|
|
|
null_option='None',
|
|
|
|
query_params={
|
2021-03-01 17:24:30 -05:00
|
|
|
'site_id': '$site_id'
|
|
|
|
},
|
|
|
|
label=_('Rack')
|
2019-03-12 12:05:58 -04:00
|
|
|
)
|
|
|
|
status = forms.MultipleChoiceField(
|
2019-11-25 21:21:35 -05:00
|
|
|
choices=PowerFeedStatusChoices,
|
2019-03-12 12:05:58 -04:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2Multiple()
|
|
|
|
)
|
|
|
|
type = forms.ChoiceField(
|
2019-11-25 21:03:11 -05:00
|
|
|
choices=add_blank_choice(PowerFeedTypeChoices),
|
2019-03-12 12:05:58 -04:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
|
|
|
supply = forms.ChoiceField(
|
2019-11-25 21:08:34 -05:00
|
|
|
choices=add_blank_choice(PowerFeedSupplyChoices),
|
2019-03-12 12:05:58 -04:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
|
|
|
phase = forms.ChoiceField(
|
2019-11-25 21:14:04 -05:00
|
|
|
choices=add_blank_choice(PowerFeedPhaseChoices),
|
2019-03-12 12:05:58 -04:00
|
|
|
required=False,
|
|
|
|
widget=StaticSelect2()
|
|
|
|
)
|
2019-04-11 10:49:43 -04:00
|
|
|
voltage = forms.IntegerField(
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
amperage = forms.IntegerField(
|
|
|
|
required=False
|
|
|
|
)
|
2019-06-17 14:52:11 -04:00
|
|
|
max_utilization = forms.IntegerField(
|
2019-04-11 10:49:43 -04:00
|
|
|
required=False
|
|
|
|
)
|
2020-01-14 08:22:27 +00:00
|
|
|
tag = TagFilterField(model)
|