| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761 |
- from django import forms
- from django.conf import settings
- from django.utils.translation import gettext_lazy as _
- from timezone_field import TimeZoneFormField
- from dcim.choices import *
- from dcim.constants import *
- from dcim.models import *
- from extras.models import ConfigTemplate
- from ipam.choices import VLANQinQRoleChoices
- from ipam.models import ASN, VLAN, VRF, VLANGroup
- from netbox.choices import *
- from netbox.forms import (
- NestedGroupModelBulkEditForm,
- NetBoxModelBulkEditForm,
- OrganizationalModelBulkEditForm,
- PrimaryModelBulkEditForm,
- )
- from netbox.forms.mixins import ChangelogMessageMixin, OwnerMixin
- from tenancy.models import Tenant
- from users.models import User
- from utilities.forms import BulkEditForm, add_blank_choice, form_from_model
- from utilities.forms.fields import ColorField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, JSONField
- from utilities.forms.rendering import FieldSet, InlineFields, TabbedGroups
- from utilities.forms.widgets import BulkEditNullBooleanSelect, NumberWithOptions
- from virtualization.models import Cluster
- from wireless.choices import WirelessRoleChoices
- from wireless.models import WirelessLAN, WirelessLANGroup
- __all__ = (
- 'CableBulkEditForm',
- 'ConsolePortBulkEditForm',
- 'ConsolePortTemplateBulkEditForm',
- 'ConsoleServerPortBulkEditForm',
- 'ConsoleServerPortTemplateBulkEditForm',
- 'DeviceBayBulkEditForm',
- 'DeviceBayTemplateBulkEditForm',
- 'DeviceBulkEditForm',
- 'DeviceRoleBulkEditForm',
- 'DeviceTypeBulkEditForm',
- 'FrontPortBulkEditForm',
- 'FrontPortTemplateBulkEditForm',
- 'InterfaceBulkEditForm',
- 'InterfaceTemplateBulkEditForm',
- 'InventoryItemBulkEditForm',
- 'InventoryItemRoleBulkEditForm',
- 'InventoryItemTemplateBulkEditForm',
- 'LocationBulkEditForm',
- 'MACAddressBulkEditForm',
- 'ManufacturerBulkEditForm',
- 'ModuleBulkEditForm',
- 'ModuleBayBulkEditForm',
- 'ModuleBayTemplateBulkEditForm',
- 'ModuleTypeBulkEditForm',
- 'ModuleTypeProfileBulkEditForm',
- 'PlatformBulkEditForm',
- 'PowerFeedBulkEditForm',
- 'PowerOutletBulkEditForm',
- 'PowerOutletTemplateBulkEditForm',
- 'PowerPanelBulkEditForm',
- 'PowerPortBulkEditForm',
- 'PowerPortTemplateBulkEditForm',
- 'RackBulkEditForm',
- 'RackReservationBulkEditForm',
- 'RackRoleBulkEditForm',
- 'RackTypeBulkEditForm',
- 'RearPortBulkEditForm',
- 'RearPortTemplateBulkEditForm',
- 'RegionBulkEditForm',
- 'SiteBulkEditForm',
- 'SiteGroupBulkEditForm',
- 'VirtualChassisBulkEditForm',
- 'VirtualDeviceContextBulkEditForm'
- )
- class RegionBulkEditForm(NestedGroupModelBulkEditForm):
- parent = DynamicModelChoiceField(
- label=_('Parent'),
- queryset=Region.objects.all(),
- required=False
- )
- model = Region
- fieldsets = (
- FieldSet('parent', 'description'),
- )
- nullable_fields = ('parent', 'description', 'comments')
- class SiteGroupBulkEditForm(NestedGroupModelBulkEditForm):
- parent = DynamicModelChoiceField(
- label=_('Parent'),
- queryset=SiteGroup.objects.all(),
- required=False
- )
- model = SiteGroup
- fieldsets = (
- FieldSet('parent', 'description'),
- )
- nullable_fields = ('parent', 'description', 'comments')
- class SiteBulkEditForm(PrimaryModelBulkEditForm):
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(SiteStatusChoices),
- required=False,
- initial=''
- )
- region = DynamicModelChoiceField(
- label=_('Region'),
- queryset=Region.objects.all(),
- required=False
- )
- group = DynamicModelChoiceField(
- label=_('Group'),
- queryset=SiteGroup.objects.all(),
- required=False
- )
- tenant = DynamicModelChoiceField(
- label=_('Tenant'),
- queryset=Tenant.objects.all(),
- required=False
- )
- facility = forms.CharField(
- label=_('Facility'),
- max_length=50,
- required=False
- )
- asns = DynamicModelMultipleChoiceField(
- queryset=ASN.objects.all(),
- label=_('ASNs'),
- required=False
- )
- contact_name = forms.CharField(
- label=_('Contact name'),
- max_length=50,
- required=False
- )
- contact_phone = forms.CharField(
- label=_('Contact phone'),
- max_length=20,
- required=False
- )
- contact_email = forms.EmailField(
- required=False,
- label=_('Contact E-mail')
- )
- time_zone = TimeZoneFormField(
- label=_('Time zone'),
- choices=add_blank_choice(TimeZoneFormField().choices),
- required=False
- )
- model = Site
- fieldsets = (
- FieldSet('status', 'region', 'group', 'tenant', 'facility', 'asns', 'time_zone', 'description'),
- )
- nullable_fields = (
- 'region', 'group', 'tenant', 'facility', 'asns', 'time_zone', 'description', 'comments',
- )
- class LocationBulkEditForm(NestedGroupModelBulkEditForm):
- site = DynamicModelChoiceField(
- label=_('Site'),
- queryset=Site.objects.all(),
- required=False
- )
- parent = DynamicModelChoiceField(
- label=_('Parent'),
- queryset=Location.objects.all(),
- required=False,
- query_params={
- 'site_id': '$site'
- }
- )
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(LocationStatusChoices),
- required=False,
- initial=''
- )
- tenant = DynamicModelChoiceField(
- label=_('Tenant'),
- queryset=Tenant.objects.all(),
- required=False
- )
- facility = forms.CharField(
- label=_('Facility'),
- max_length=50,
- required=False
- )
- model = Location
- fieldsets = (
- FieldSet('site', 'parent', 'status', 'tenant', 'facility', 'description'),
- )
- nullable_fields = ('parent', 'tenant', 'facility', 'description', 'comments')
- class RackRoleBulkEditForm(OrganizationalModelBulkEditForm):
- color = ColorField(
- label=_('Color'),
- required=False
- )
- model = RackRole
- fieldsets = (
- FieldSet('color', 'description'),
- )
- nullable_fields = ('color', 'description', 'comments')
- class RackTypeBulkEditForm(PrimaryModelBulkEditForm):
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- form_factor = forms.ChoiceField(
- label=_('Form factor'),
- choices=add_blank_choice(RackFormFactorChoices),
- required=False
- )
- width = forms.ChoiceField(
- label=_('Width'),
- choices=add_blank_choice(RackWidthChoices),
- required=False
- )
- u_height = forms.IntegerField(
- required=False,
- label=_('Height (U)')
- )
- starting_unit = forms.IntegerField(
- required=False,
- min_value=1
- )
- desc_units = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect,
- label=_('Descending units')
- )
- outer_width = forms.IntegerField(
- label=_('Outer width'),
- required=False,
- min_value=1
- )
- outer_height = forms.IntegerField(
- label=_('Outer height'),
- required=False,
- min_value=1
- )
- outer_depth = forms.IntegerField(
- label=_('Outer depth'),
- required=False,
- min_value=1
- )
- outer_unit = forms.ChoiceField(
- label=_('Outer unit'),
- choices=add_blank_choice(RackDimensionUnitChoices),
- required=False
- )
- mounting_depth = forms.IntegerField(
- label=_('Mounting depth'),
- required=False,
- min_value=1
- )
- weight = forms.DecimalField(
- label=_('Weight'),
- min_value=0,
- required=False
- )
- max_weight = forms.IntegerField(
- label=_('Max weight'),
- min_value=0,
- required=False
- )
- weight_unit = forms.ChoiceField(
- label=_('Weight unit'),
- choices=add_blank_choice(WeightUnitChoices),
- required=False,
- initial=''
- )
- model = RackType
- fieldsets = (
- FieldSet('manufacturer', 'description', 'form_factor', 'width', 'u_height', name=_('Rack Type')),
- FieldSet(
- InlineFields('outer_width', 'outer_height', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')),
- InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')),
- 'mounting_depth',
- name=_('Dimensions')
- ),
- FieldSet('starting_unit', 'desc_units', name=_('Numbering')),
- )
- nullable_fields = (
- 'outer_width', 'outer_height', 'outer_depth', 'outer_unit', 'weight',
- 'max_weight', 'weight_unit', 'description', 'comments',
- )
- class RackBulkEditForm(PrimaryModelBulkEditForm):
- region = DynamicModelChoiceField(
- label=_('Region'),
- queryset=Region.objects.all(),
- required=False,
- initial_params={
- 'sites': '$site'
- }
- )
- site_group = DynamicModelChoiceField(
- label=_('Site group'),
- queryset=SiteGroup.objects.all(),
- required=False,
- initial_params={
- 'sites': '$site'
- }
- )
- site = DynamicModelChoiceField(
- label=_('Site'),
- queryset=Site.objects.all(),
- required=False,
- query_params={
- 'region_id': '$region',
- 'group_id': '$site_group',
- }
- )
- location = DynamicModelChoiceField(
- label=_('Location'),
- queryset=Location.objects.all(),
- required=False,
- query_params={
- 'site_id': '$site'
- }
- )
- tenant = DynamicModelChoiceField(
- label=_('Tenant'),
- queryset=Tenant.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(RackStatusChoices),
- required=False,
- initial=''
- )
- role = DynamicModelChoiceField(
- label=_('Role'),
- queryset=RackRole.objects.all(),
- required=False
- )
- rack_type = DynamicModelChoiceField(
- label=_('Rack type'),
- queryset=RackType.objects.all(),
- required=False,
- )
- serial = forms.CharField(
- max_length=50,
- required=False,
- label=_('Serial Number')
- )
- asset_tag = forms.CharField(
- label=_('Asset tag'),
- max_length=50,
- required=False
- )
- form_factor = forms.ChoiceField(
- label=_('Form factor'),
- choices=add_blank_choice(RackFormFactorChoices),
- required=False
- )
- width = forms.ChoiceField(
- label=_('Width'),
- choices=add_blank_choice(RackWidthChoices),
- required=False
- )
- u_height = forms.IntegerField(
- required=False,
- label=_('Height (U)')
- )
- desc_units = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect,
- label=_('Descending units')
- )
- outer_width = forms.IntegerField(
- label=_('Outer width'),
- required=False,
- min_value=1
- )
- outer_height = forms.IntegerField(
- label=_('Outer height'),
- required=False,
- min_value=1
- )
- outer_depth = forms.IntegerField(
- label=_('Outer depth'),
- required=False,
- min_value=1
- )
- outer_unit = forms.ChoiceField(
- label=_('Outer unit'),
- choices=add_blank_choice(RackDimensionUnitChoices),
- required=False
- )
- mounting_depth = forms.IntegerField(
- label=_('Mounting depth'),
- required=False,
- min_value=1
- )
- airflow = forms.ChoiceField(
- label=_('Airflow'),
- choices=add_blank_choice(RackAirflowChoices),
- required=False
- )
- weight = forms.DecimalField(
- label=_('Weight'),
- min_value=0,
- required=False
- )
- max_weight = forms.IntegerField(
- label=_('Max weight'),
- min_value=0,
- required=False
- )
- weight_unit = forms.ChoiceField(
- label=_('Weight unit'),
- choices=add_blank_choice(WeightUnitChoices),
- required=False,
- initial=''
- )
- model = Rack
- fieldsets = (
- FieldSet('status', 'role', 'tenant', 'serial', 'asset_tag', 'rack_type', 'description', name=_('Rack')),
- FieldSet('region', 'site_group', 'site', 'location', name=_('Location')),
- FieldSet('outer_width', 'outer_height', 'outer_depth', 'outer_unit', name=_('Outer Dimensions')),
- FieldSet('form_factor', 'width', 'u_height', 'desc_units', 'airflow', 'mounting_depth', name=_('Hardware')),
- FieldSet('weight', 'max_weight', 'weight_unit', name=_('Weight')),
- )
- nullable_fields = (
- 'location', 'tenant', 'role', 'serial', 'asset_tag', 'outer_width', 'outer_height', 'outer_depth',
- 'outer_unit', 'weight', 'max_weight', 'weight_unit', 'description', 'comments',
- )
- class RackReservationBulkEditForm(PrimaryModelBulkEditForm):
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(RackReservationStatusChoices),
- required=False,
- initial=''
- )
- user = forms.ModelChoiceField(
- label=_('User'),
- queryset=User.objects.order_by('username'),
- required=False
- )
- tenant = DynamicModelChoiceField(
- label=_('Tenant'),
- queryset=Tenant.objects.all(),
- required=False
- )
- model = RackReservation
- fieldsets = (
- FieldSet('status', 'user', 'tenant', 'description'),
- )
- nullable_fields = ('comments',)
- class ManufacturerBulkEditForm(OrganizationalModelBulkEditForm):
- model = Manufacturer
- fieldsets = (
- FieldSet('description'),
- )
- nullable_fields = ('description', 'comments')
- class DeviceTypeBulkEditForm(PrimaryModelBulkEditForm):
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- default_platform = DynamicModelChoiceField(
- label=_('Default platform'),
- queryset=Platform.objects.all(),
- required=False
- )
- part_number = forms.CharField(
- label=_('Part number'),
- required=False
- )
- u_height = forms.IntegerField(
- label=_('U height'),
- min_value=0,
- required=False
- )
- is_full_depth = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect(),
- label=_('Is full depth')
- )
- exclude_from_utilization = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect(),
- label=_('Exclude from utilization')
- )
- airflow = forms.ChoiceField(
- label=_('Airflow'),
- choices=add_blank_choice(DeviceAirflowChoices),
- required=False
- )
- weight = forms.DecimalField(
- label=_('Weight'),
- min_value=0,
- required=False
- )
- weight_unit = forms.ChoiceField(
- label=_('Weight unit'),
- choices=add_blank_choice(WeightUnitChoices),
- required=False,
- initial=''
- )
- model = DeviceType
- fieldsets = (
- FieldSet(
- 'manufacturer', 'default_platform', 'part_number', 'u_height', 'exclude_from_utilization', 'is_full_depth',
- 'airflow', 'description', name=_('Device Type')
- ),
- FieldSet('weight', 'weight_unit', name=_('Weight')),
- )
- nullable_fields = ('part_number', 'airflow', 'weight', 'weight_unit', 'description', 'comments')
- class ModuleTypeProfileBulkEditForm(PrimaryModelBulkEditForm):
- schema = JSONField(
- label=_('Schema'),
- required=False
- )
- model = ModuleTypeProfile
- fieldsets = (
- FieldSet('name', 'description', 'schema', name=_('Profile')),
- )
- nullable_fields = ('description', 'comments')
- class ModuleTypeBulkEditForm(PrimaryModelBulkEditForm):
- profile = DynamicModelChoiceField(
- label=_('Profile'),
- queryset=ModuleTypeProfile.objects.all(),
- required=False
- )
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- part_number = forms.CharField(
- label=_('Part number'),
- required=False
- )
- airflow = forms.ChoiceField(
- label=_('Airflow'),
- choices=add_blank_choice(ModuleAirflowChoices),
- required=False
- )
- weight = forms.DecimalField(
- label=_('Weight'),
- min_value=0,
- required=False
- )
- weight_unit = forms.ChoiceField(
- label=_('Weight unit'),
- choices=add_blank_choice(WeightUnitChoices),
- required=False,
- initial=''
- )
- model = ModuleType
- fieldsets = (
- FieldSet('profile', 'manufacturer', 'part_number', 'description', name=_('Module Type')),
- FieldSet(
- 'airflow',
- InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')),
- name=_('Chassis')
- ),
- )
- nullable_fields = ('part_number', 'weight', 'weight_unit', 'profile', 'description', 'comments')
- class DeviceRoleBulkEditForm(NestedGroupModelBulkEditForm):
- parent = DynamicModelChoiceField(
- label=_('Parent'),
- queryset=DeviceRole.objects.all(),
- required=False,
- )
- color = ColorField(
- label=_('Color'),
- required=False
- )
- vm_role = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect,
- label=_('VM role')
- )
- config_template = DynamicModelChoiceField(
- label=_('Config template'),
- queryset=ConfigTemplate.objects.all(),
- required=False
- )
- model = DeviceRole
- fieldsets = (
- FieldSet('parent', 'color', 'vm_role', 'config_template', 'description'),
- )
- nullable_fields = ('parent', 'color', 'config_template', 'description', 'comments')
- class PlatformBulkEditForm(NestedGroupModelBulkEditForm):
- parent = DynamicModelChoiceField(
- label=_('Parent'),
- queryset=Platform.objects.all(),
- required=False,
- )
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- config_template = DynamicModelChoiceField(
- label=_('Config template'),
- queryset=ConfigTemplate.objects.all(),
- required=False
- )
- model = Platform
- fieldsets = (
- FieldSet('parent', 'manufacturer', 'config_template', 'description'),
- )
- nullable_fields = ('parent', 'manufacturer', 'config_template', 'description', 'comments')
- class DeviceBulkEditForm(PrimaryModelBulkEditForm):
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- device_type = DynamicModelChoiceField(
- label=_('Device type'),
- queryset=DeviceType.objects.all(),
- required=False,
- context={
- 'parent': 'manufacturer',
- },
- query_params={
- 'manufacturer_id': '$manufacturer'
- }
- )
- role = DynamicModelChoiceField(
- label=_('Device role'),
- queryset=DeviceRole.objects.all(),
- required=False
- )
- site = DynamicModelChoiceField(
- label=_('Site'),
- queryset=Site.objects.all(),
- required=False
- )
- location = DynamicModelChoiceField(
- label=_('Location'),
- queryset=Location.objects.all(),
- required=False,
- query_params={
- 'site_id': '$site'
- }
- )
- tenant = DynamicModelChoiceField(
- label=_('Tenant'),
- queryset=Tenant.objects.all(),
- required=False
- )
- platform = DynamicModelChoiceField(
- label=_('Platform'),
- queryset=Platform.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(DeviceStatusChoices),
- required=False
- )
- airflow = forms.ChoiceField(
- label=_('Airflow'),
- choices=add_blank_choice(DeviceAirflowChoices),
- required=False
- )
- serial = forms.CharField(
- max_length=50,
- required=False,
- label=_('Serial Number')
- )
- config_template = DynamicModelChoiceField(
- label=_('Config template'),
- queryset=ConfigTemplate.objects.all(),
- required=False
- )
- cluster = DynamicModelChoiceField(
- label=_('Cluster'),
- queryset=Cluster.objects.all(),
- required=False,
- query_params={
- 'site_id': ['$site', 'null']
- },
- )
- model = Device
- fieldsets = (
- FieldSet('role', 'status', 'tenant', 'platform', 'description', name=_('Device')),
- FieldSet('site', 'location', name=_('Location')),
- FieldSet('manufacturer', 'device_type', 'airflow', 'serial', name=_('Hardware')),
- FieldSet('config_template', name=_('Configuration')),
- FieldSet('cluster', name=_('Virtualization')),
- )
- nullable_fields = (
- 'location', 'tenant', 'platform', 'serial', 'airflow', 'description', 'cluster', 'comments',
- )
- class ModuleBulkEditForm(PrimaryModelBulkEditForm):
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- module_type = DynamicModelChoiceField(
- label=_('Module type'),
- queryset=ModuleType.objects.all(),
- required=False,
- query_params={
- 'manufacturer_id': '$manufacturer'
- },
- context={
- 'parent': 'manufacturer',
- }
- )
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(ModuleStatusChoices),
- required=False,
- initial=''
- )
- serial = forms.CharField(
- max_length=50,
- required=False,
- label=_('Serial Number')
- )
- model = Module
- fieldsets = (
- FieldSet('manufacturer', 'module_type', 'status', 'serial', 'description'),
- )
- nullable_fields = ('serial', 'description', 'comments')
- class CableBulkEditForm(PrimaryModelBulkEditForm):
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(CableTypeChoices),
- required=False,
- initial=''
- )
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(LinkStatusChoices),
- required=False,
- initial=''
- )
- profile = forms.ChoiceField(
- label=_('Profile'),
- choices=add_blank_choice(CableProfileChoices),
- required=False,
- initial=''
- )
- tenant = DynamicModelChoiceField(
- label=_('Tenant'),
- queryset=Tenant.objects.all(),
- required=False
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=100,
- required=False
- )
- color = ColorField(
- label=_('Color'),
- required=False
- )
- length = forms.DecimalField(
- label=_('Length'),
- min_value=0,
- required=False
- )
- length_unit = forms.ChoiceField(
- label=_('Length unit'),
- choices=add_blank_choice(CableLengthUnitChoices),
- required=False,
- initial=''
- )
- model = Cable
- fieldsets = (
- FieldSet('type', 'status', 'profile', 'tenant', 'label', 'description'),
- FieldSet('color', 'length', 'length_unit', name=_('Attributes')),
- )
- nullable_fields = (
- 'type', 'status', 'profile', 'tenant', 'label', 'color', 'length', 'description', 'comments',
- )
- class VirtualChassisBulkEditForm(PrimaryModelBulkEditForm):
- domain = forms.CharField(
- label=_('Domain'),
- max_length=30,
- required=False
- )
- model = VirtualChassis
- fieldsets = (
- FieldSet('domain', 'description'),
- )
- nullable_fields = ('domain', 'description', 'comments')
- class PowerPanelBulkEditForm(PrimaryModelBulkEditForm):
- region = DynamicModelChoiceField(
- label=_('Region'),
- queryset=Region.objects.all(),
- required=False,
- initial_params={
- 'sites': '$site'
- }
- )
- site_group = DynamicModelChoiceField(
- label=_('Site group'),
- queryset=SiteGroup.objects.all(),
- required=False,
- initial_params={
- 'sites': '$site'
- }
- )
- site = DynamicModelChoiceField(
- label=_('Site'),
- queryset=Site.objects.all(),
- required=False,
- query_params={
- 'region_id': '$region',
- 'group_id': '$site_group',
- }
- )
- location = DynamicModelChoiceField(
- label=_('Location'),
- queryset=Location.objects.all(),
- required=False,
- query_params={
- 'site_id': '$site'
- }
- )
- model = PowerPanel
- fieldsets = (
- FieldSet('region', 'site_group', 'site', 'location', 'description'),
- )
- nullable_fields = ('location', 'description', 'comments')
- class PowerFeedBulkEditForm(PrimaryModelBulkEditForm):
- power_panel = DynamicModelChoiceField(
- label=_('Power panel'),
- queryset=PowerPanel.objects.all(),
- required=False
- )
- rack = DynamicModelChoiceField(
- label=_('Rack'),
- queryset=Rack.objects.all(),
- required=False,
- )
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(PowerFeedStatusChoices),
- required=False,
- initial=''
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(PowerFeedTypeChoices),
- required=False,
- initial=''
- )
- supply = forms.ChoiceField(
- label=_('Supply'),
- choices=add_blank_choice(PowerFeedSupplyChoices),
- required=False,
- initial=''
- )
- phase = forms.ChoiceField(
- label=_('Phase'),
- choices=add_blank_choice(PowerFeedPhaseChoices),
- required=False,
- initial=''
- )
- voltage = forms.IntegerField(
- label=_('Voltage'),
- required=False
- )
- amperage = forms.IntegerField(
- label=_('Amperage'),
- required=False
- )
- max_utilization = forms.IntegerField(
- label=_('Max utilization'),
- required=False
- )
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- model = PowerFeed
- fieldsets = (
- FieldSet('power_panel', 'rack', 'status', 'type', 'mark_connected', 'description', 'tenant'),
- FieldSet('supply', 'phase', 'voltage', 'amperage', 'max_utilization', name=_('Power'))
- )
- nullable_fields = ('location', 'tenant', 'description', 'comments')
- #
- # Device component templates
- #
- class ComponentTemplateBulkEditForm(ChangelogMessageMixin, BulkEditForm):
- pass
- class ConsolePortTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=ConsolePortTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(ConsolePortTypeChoices),
- required=False
- )
- nullable_fields = ('label', 'type', 'description')
- class ConsoleServerPortTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=ConsoleServerPortTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(ConsolePortTypeChoices),
- required=False
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- nullable_fields = ('label', 'type', 'description')
- class PowerPortTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=PowerPortTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(PowerPortTypeChoices),
- required=False
- )
- maximum_draw = forms.IntegerField(
- label=_('Maximum draw'),
- min_value=1,
- required=False,
- help_text=_("Maximum power draw (watts)")
- )
- allocated_draw = forms.IntegerField(
- label=_('Allocated draw'),
- min_value=1,
- required=False,
- help_text=_("Allocated power draw (watts)")
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- nullable_fields = ('label', 'type', 'maximum_draw', 'allocated_draw', 'description')
- class PowerOutletTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=PowerOutletTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- device_type = forms.ModelChoiceField(
- label=_('Device type'),
- queryset=DeviceType.objects.all(),
- required=False,
- disabled=True,
- widget=forms.HiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(PowerOutletTypeChoices),
- required=False
- )
- color = ColorField(
- label=_('Color'),
- required=False
- )
- power_port = forms.ModelChoiceField(
- label=_('Power port'),
- queryset=PowerPortTemplate.objects.all(),
- required=False
- )
- feed_leg = forms.ChoiceField(
- label=_('Feed leg'),
- choices=add_blank_choice(PowerOutletFeedLegChoices),
- required=False
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- nullable_fields = ('label', 'type', 'power_port', 'feed_leg', 'description')
- 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
- class InterfaceTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=InterfaceTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(InterfaceTypeChoices),
- required=False
- )
- enabled = forms.NullBooleanField(
- label=_('Enabled'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- mgmt_only = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect,
- label=_('Management only')
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- poe_mode = forms.ChoiceField(
- choices=add_blank_choice(InterfacePoEModeChoices),
- required=False,
- initial='',
- label=_('PoE mode')
- )
- poe_type = forms.ChoiceField(
- choices=add_blank_choice(InterfacePoETypeChoices),
- required=False,
- initial='',
- label=_('PoE type')
- )
- rf_role = forms.ChoiceField(
- choices=add_blank_choice(WirelessRoleChoices),
- required=False,
- initial='',
- label=_('Wireless role')
- )
- nullable_fields = ('label', 'description', 'poe_mode', 'poe_type', 'rf_role')
- class FrontPortTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=FrontPortTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(PortTypeChoices),
- required=False
- )
- color = ColorField(
- label=_('Color'),
- required=False
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- nullable_fields = ('description',)
- class RearPortTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=RearPortTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- type = forms.ChoiceField(
- label=_('Type'),
- choices=add_blank_choice(PortTypeChoices),
- required=False
- )
- color = ColorField(
- label=_('Color'),
- required=False
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- nullable_fields = ('description',)
- class ModuleBayTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=ModuleBayTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- nullable_fields = ('label', 'position', 'description')
- class DeviceBayTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=DeviceBayTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- nullable_fields = ('label', 'description')
- class InventoryItemTemplateBulkEditForm(ComponentTemplateBulkEditForm):
- pk = forms.ModelMultipleChoiceField(
- queryset=InventoryItemTemplate.objects.all(),
- widget=forms.MultipleHiddenInput()
- )
- label = forms.CharField(
- label=_('Label'),
- max_length=64,
- required=False
- )
- description = forms.CharField(
- label=_('Description'),
- required=False
- )
- role = DynamicModelChoiceField(
- label=_('Role'),
- queryset=InventoryItemRole.objects.all(),
- required=False
- )
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- nullable_fields = ('label', 'role', 'manufacturer', 'part_id', 'description')
- #
- # Device components
- #
- class ComponentBulkEditForm(OwnerMixin, NetBoxModelBulkEditForm):
- device = forms.ModelChoiceField(
- label=_('Device'),
- queryset=Device.objects.all(),
- required=False,
- disabled=True,
- widget=forms.HiddenInput()
- )
- module = forms.ModelChoiceField(
- label=_('Module'),
- queryset=Module.objects.all(),
- required=False
- )
- def __init__(self, *args, initial=None, **kwargs):
- try:
- self.device_id = int(initial.get('device'))
- except (TypeError, ValueError):
- self.device_id = None
- super().__init__(*args, initial=initial, **kwargs)
- # Limit module queryset to Modules which belong to the parent Device
- if self.device_id:
- device = Device.objects.filter(pk=self.device_id).first()
- self.fields['module'].queryset = Module.objects.filter(device=device)
- else:
- self.fields['module'].choices = ()
- self.fields['module'].widget.attrs['disabled'] = True
- class ConsolePortBulkEditForm(
- ComponentBulkEditForm,
- form_from_model(ConsolePort, ['label', 'type', 'speed', 'mark_connected', 'description'])
- ):
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- model = ConsolePort
- fieldsets = (
- FieldSet('module', 'type', 'label', 'speed', 'description', 'mark_connected'),
- )
- nullable_fields = ('module', 'label', 'description')
- class ConsoleServerPortBulkEditForm(
- ComponentBulkEditForm,
- form_from_model(ConsoleServerPort, ['label', 'type', 'speed', 'mark_connected', 'description'])
- ):
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- model = ConsoleServerPort
- fieldsets = (
- FieldSet('module', 'type', 'label', 'speed', 'description', 'mark_connected'),
- )
- nullable_fields = ('module', 'label', 'description')
- class PowerPortBulkEditForm(
- ComponentBulkEditForm,
- form_from_model(PowerPort, ['label', 'type', 'maximum_draw', 'allocated_draw', 'mark_connected', 'description'])
- ):
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- model = PowerPort
- fieldsets = (
- FieldSet('module', 'type', 'label', 'description', 'mark_connected'),
- FieldSet('maximum_draw', 'allocated_draw', name=_('Power')),
- )
- nullable_fields = ('module', 'label', 'description', 'maximum_draw', 'allocated_draw')
- class PowerOutletBulkEditForm(
- ComponentBulkEditForm,
- form_from_model(
- PowerOutlet,
- ['label', 'type', 'status', 'color', 'feed_leg', 'power_port', 'mark_connected', 'description']
- )
- ):
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- model = PowerOutlet
- fieldsets = (
- FieldSet('module', 'type', 'label', 'status', 'description', 'mark_connected', 'color'),
- FieldSet('feed_leg', 'power_port', name=_('Power')),
- )
- nullable_fields = ('module', 'label', 'type', 'feed_leg', 'power_port', 'description')
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- # Limit power_port queryset to PowerPorts which belong to the parent Device
- if self.device_id:
- device = Device.objects.filter(pk=self.device_id).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
- class InterfaceBulkEditForm(
- ComponentBulkEditForm,
- form_from_model(Interface, [
- 'label', 'type', 'parent', 'bridge', 'lag', 'speed', 'duplex', 'wwn', 'mtu', 'mgmt_only', 'mark_connected',
- 'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power',
- 'wireless_lans', 'vlan_translation_policy'
- ])
- ):
- enabled = forms.NullBooleanField(
- label=_('Enabled'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- parent = DynamicModelChoiceField(
- label=_('Parent'),
- queryset=Interface.objects.all(),
- required=False,
- query_params={
- 'virtual_chassis_member_id': '$device',
- }
- )
- bridge = DynamicModelChoiceField(
- label=_('Bridge'),
- queryset=Interface.objects.all(),
- required=False,
- query_params={
- 'virtual_chassis_member_id': '$device',
- }
- )
- lag = DynamicModelChoiceField(
- queryset=Interface.objects.all(),
- required=False,
- query_params={
- 'type': 'lag',
- 'virtual_chassis_member_id': '$device',
- },
- label=_('LAG')
- )
- vdcs = DynamicModelMultipleChoiceField(
- queryset=VirtualDeviceContext.objects.all(),
- required=False,
- label=_('Virtual device contexts'),
- query_params={
- 'device_id': '$device',
- }
- )
- speed = forms.IntegerField(
- label=_('Speed'),
- required=False,
- widget=NumberWithOptions(
- options=InterfaceSpeedChoices
- )
- )
- mgmt_only = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect,
- label=_('Management only')
- )
- poe_mode = forms.ChoiceField(
- choices=add_blank_choice(InterfacePoEModeChoices),
- required=False,
- initial='',
- label=_('PoE mode')
- )
- poe_type = forms.ChoiceField(
- choices=add_blank_choice(InterfacePoETypeChoices),
- required=False,
- initial='',
- label=_('PoE type')
- )
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- mode = forms.ChoiceField(
- label=_('Mode'),
- choices=add_blank_choice(InterfaceModeChoices),
- required=False,
- initial=''
- )
- vlan_group = DynamicModelChoiceField(
- queryset=VLANGroup.objects.all(),
- required=False,
- label=_('VLAN group')
- )
- untagged_vlan = DynamicModelChoiceField(
- queryset=VLAN.objects.all(),
- required=False,
- query_params={
- 'group_id': '$vlan_group',
- 'available_on_device': '$device',
- },
- label=_('Untagged VLAN')
- )
- tagged_vlans = DynamicModelMultipleChoiceField(
- queryset=VLAN.objects.all(),
- required=False,
- query_params={
- 'group_id': '$vlan_group',
- 'available_on_device': '$device',
- },
- label=_('Tagged VLANs')
- )
- add_tagged_vlans = DynamicModelMultipleChoiceField(
- label=_('Add tagged VLANs'),
- queryset=VLAN.objects.all(),
- required=False,
- query_params={
- 'group_id': '$vlan_group',
- 'available_on_device': '$device',
- },
- )
- remove_tagged_vlans = DynamicModelMultipleChoiceField(
- label=_('Remove tagged VLANs'),
- queryset=VLAN.objects.all(),
- required=False,
- query_params={
- 'group_id': '$vlan_group',
- 'available_on_device': '$device',
- }
- )
- qinq_svlan = DynamicModelChoiceField(
- queryset=VLAN.objects.all(),
- required=False,
- label=_('Q-in-Q Service VLAN'),
- query_params={
- 'group_id': '$vlan_group',
- 'available_on_device': '$device',
- 'qinq_role': VLANQinQRoleChoices.ROLE_SERVICE,
- }
- )
- vrf = DynamicModelChoiceField(
- queryset=VRF.objects.all(),
- required=False,
- label=_('VRF')
- )
- wireless_lan_group = DynamicModelChoiceField(
- queryset=WirelessLANGroup.objects.all(),
- required=False,
- label=_('Wireless LAN group')
- )
- wireless_lans = DynamicModelMultipleChoiceField(
- queryset=WirelessLAN.objects.all(),
- required=False,
- label=_('Wireless LANs'),
- query_params={
- 'group_id': '$wireless_lan_group',
- }
- )
- model = Interface
- fieldsets = (
- FieldSet('module', 'type', 'label', 'speed', 'duplex', 'description'),
- FieldSet('vrf', 'wwn', name=_('Addressing')),
- FieldSet('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected', name=_('Operation')),
- FieldSet('poe_mode', 'poe_type', name=_('PoE')),
- FieldSet('parent', 'bridge', 'lag', name=_('Related Interfaces')),
- FieldSet(
- 'mode', 'vlan_group', 'untagged_vlan', 'qinq_svlan', 'vlan_translation_policy', name=_('802.1Q Switching')
- ),
- FieldSet(
- TabbedGroups(
- FieldSet('tagged_vlans', name=_('Assignment')),
- FieldSet('add_tagged_vlans', 'remove_tagged_vlans', name=_('Add/Remove')),
- ),
- ),
- FieldSet(
- 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'wireless_lan_group', 'wireless_lans',
- name=_('Wireless')
- ),
- )
- nullable_fields = (
- 'module', 'label', 'parent', 'bridge', 'lag', 'speed', 'duplex', 'wwn', 'vdcs', 'mtu', 'description',
- 'poe_mode', 'poe_type', 'mode', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power',
- 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vrf', 'wireless_lans', 'vlan_translation_policy',
- )
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- if not self.device_id:
- # See #4523
- 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:
- # Query for VLANs assigned to the same site and VLANs with no site assigned (null).
- self.fields['untagged_vlan'].widget.add_query_param(
- 'site_id', [site.pk, settings.FILTERS_NULL_CHOICE_VALUE]
- )
- self.fields['tagged_vlans'].widget.add_query_param(
- 'site_id', [site.pk, settings.FILTERS_NULL_CHOICE_VALUE]
- )
- self.fields['add_tagged_vlans'].widget.add_query_param(
- 'site_id', [site.pk, settings.FILTERS_NULL_CHOICE_VALUE]
- )
- self.fields['remove_tagged_vlans'].widget.add_query_param(
- 'site_id', [site.pk, settings.FILTERS_NULL_CHOICE_VALUE]
- )
- self.fields['parent'].choices = ()
- self.fields['parent'].widget.attrs['disabled'] = True
- self.fields['bridge'].choices = ()
- self.fields['bridge'].widget.attrs['disabled'] = True
- self.fields['lag'].choices = ()
- self.fields['lag'].widget.attrs['disabled'] = True
- def clean(self):
- super().clean()
- if not self.cleaned_data['mode']:
- if self.cleaned_data['untagged_vlan']:
- raise forms.ValidationError({'untagged_vlan': _("Interface mode must be specified to assign VLANs")})
- elif self.cleaned_data['tagged_vlans']:
- raise forms.ValidationError({'tagged_vlans': _("Interface mode must be specified to assign VLANs")})
- # Untagged interfaces cannot be assigned tagged VLANs
- elif 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'] = []
- class FrontPortBulkEditForm(
- ComponentBulkEditForm,
- form_from_model(FrontPort, ['label', 'type', 'color', 'mark_connected', 'description'])
- ):
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- model = FrontPort
- fieldsets = (
- FieldSet('module', 'type', 'label', 'color', 'description', 'mark_connected'),
- )
- nullable_fields = ('module', 'label', 'description', 'color')
- class RearPortBulkEditForm(
- ComponentBulkEditForm,
- form_from_model(RearPort, ['label', 'type', 'color', 'mark_connected', 'description'])
- ):
- mark_connected = forms.NullBooleanField(
- label=_('Mark connected'),
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- model = RearPort
- fieldsets = (
- FieldSet('module', 'type', 'label', 'color', 'description', 'mark_connected'),
- )
- nullable_fields = ('module', 'label', 'description', 'color')
- class ModuleBayBulkEditForm(
- form_from_model(ModuleBay, ['label', 'position', 'description']),
- NetBoxModelBulkEditForm
- ):
- model = ModuleBay
- fieldsets = (
- FieldSet('label', 'position', 'description'),
- )
- nullable_fields = ('label', 'position', 'description')
- class DeviceBayBulkEditForm(
- form_from_model(DeviceBay, ['label', 'description']),
- NetBoxModelBulkEditForm
- ):
- model = DeviceBay
- fieldsets = (
- FieldSet('label', 'description'),
- )
- nullable_fields = ('label', 'description')
- class InventoryItemBulkEditForm(
- form_from_model(InventoryItem, ['label', 'role', 'manufacturer', 'part_id', 'description']),
- NetBoxModelBulkEditForm
- ):
- device = DynamicModelChoiceField(
- label=_('Device'),
- queryset=Device.objects.all(),
- required=False
- )
- role = DynamicModelChoiceField(
- label=_('Role'),
- queryset=InventoryItemRole.objects.all(),
- required=False
- )
- manufacturer = DynamicModelChoiceField(
- label=_('Manufacturer'),
- queryset=Manufacturer.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- label=_('Status'),
- choices=add_blank_choice(InventoryItemStatusChoices),
- required=False,
- initial=''
- )
- model = InventoryItem
- fieldsets = (
- FieldSet('device', 'label', 'role', 'manufacturer', 'part_id', 'status', 'description'),
- )
- nullable_fields = ('label', 'role', 'manufacturer', 'part_id', 'description')
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- # Remove parent device passed as context to avoid conflicts with the actual device field
- # on this form (see bug #19464)
- self.initial.pop('device', None)
- #
- # Device component roles
- #
- class InventoryItemRoleBulkEditForm(OrganizationalModelBulkEditForm):
- color = ColorField(
- label=_('Color'),
- required=False
- )
- model = InventoryItemRole
- fieldsets = (
- FieldSet('color', 'description'),
- )
- nullable_fields = ('color', 'description', 'comments')
- class VirtualDeviceContextBulkEditForm(PrimaryModelBulkEditForm):
- device = DynamicModelChoiceField(
- label=_('Device'),
- queryset=Device.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- label=_('Status'),
- required=False,
- choices=add_blank_choice(VirtualDeviceContextStatusChoices)
- )
- tenant = DynamicModelChoiceField(
- label=_('Tenant'),
- queryset=Tenant.objects.all(),
- required=False
- )
- model = VirtualDeviceContext
- fieldsets = (
- FieldSet('device', 'status', 'tenant'),
- )
- nullable_fields = ('device', 'tenant', )
- #
- # Addressing
- #
- class MACAddressBulkEditForm(PrimaryModelBulkEditForm):
- model = MACAddress
- fieldsets = (
- FieldSet('description'),
- )
- nullable_fields = ('description', 'comments')
|