| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528 |
- from django import forms
- from django.utils.translation import gettext as _
- from dcim.models import Region, Site, SiteGroup
- from ipam.choices import *
- from ipam.constants import *
- from ipam.models import *
- from ipam.models import ASN
- from netbox.forms import NetBoxModelBulkEditForm
- from tenancy.models import Tenant
- from utilities.forms import add_blank_choice
- from utilities.forms.fields import (
- CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, NumericArrayField,
- )
- from utilities.forms.widgets import BulkEditNullBooleanSelect
- __all__ = (
- 'AggregateBulkEditForm',
- 'ASNBulkEditForm',
- 'ASNRangeBulkEditForm',
- 'FHRPGroupBulkEditForm',
- 'IPAddressBulkEditForm',
- 'IPRangeBulkEditForm',
- 'L2VPNBulkEditForm',
- 'L2VPNTerminationBulkEditForm',
- 'PrefixBulkEditForm',
- 'RIRBulkEditForm',
- 'RoleBulkEditForm',
- 'RouteTargetBulkEditForm',
- 'ServiceBulkEditForm',
- 'ServiceTemplateBulkEditForm',
- 'VLANBulkEditForm',
- 'VLANGroupBulkEditForm',
- 'VRFBulkEditForm',
- )
- class VRFBulkEditForm(NetBoxModelBulkEditForm):
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- enforce_unique = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect(),
- label=_('Enforce unique space')
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = VRF
- fieldsets = (
- (None, ('tenant', 'enforce_unique', 'description')),
- )
- nullable_fields = ('tenant', 'description', 'comments')
- class RouteTargetBulkEditForm(NetBoxModelBulkEditForm):
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = RouteTarget
- fieldsets = (
- (None, ('tenant', 'description')),
- )
- nullable_fields = ('tenant', 'description', 'comments')
- class RIRBulkEditForm(NetBoxModelBulkEditForm):
- is_private = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- model = RIR
- fieldsets = (
- (None, ('is_private', 'description')),
- )
- nullable_fields = ('is_private', 'description')
- class ASNRangeBulkEditForm(NetBoxModelBulkEditForm):
- rir = DynamicModelChoiceField(
- queryset=RIR.objects.all(),
- required=False,
- label=_('RIR')
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- model = ASNRange
- fieldsets = (
- (None, ('rir', 'tenant', 'description')),
- )
- nullable_fields = ('description',)
- class ASNBulkEditForm(NetBoxModelBulkEditForm):
- sites = DynamicModelMultipleChoiceField(
- queryset=Site.objects.all(),
- required=False
- )
- rir = DynamicModelChoiceField(
- queryset=RIR.objects.all(),
- required=False,
- label=_('RIR')
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = ASN
- fieldsets = (
- (None, ('sites', 'rir', 'tenant', 'description')),
- )
- nullable_fields = ('tenant', 'description', 'comments')
- class AggregateBulkEditForm(NetBoxModelBulkEditForm):
- rir = DynamicModelChoiceField(
- queryset=RIR.objects.all(),
- required=False,
- label=_('RIR')
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- date_added = forms.DateField(
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = Aggregate
- fieldsets = (
- (None, ('rir', 'tenant', 'date_added', 'description')),
- )
- nullable_fields = ('date_added', 'description', 'comments')
- class RoleBulkEditForm(NetBoxModelBulkEditForm):
- weight = forms.IntegerField(
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- model = Role
- fieldsets = (
- (None, ('weight', 'description')),
- )
- nullable_fields = ('description',)
- class PrefixBulkEditForm(NetBoxModelBulkEditForm):
- region = DynamicModelChoiceField(
- queryset=Region.objects.all(),
- required=False
- )
- site_group = DynamicModelChoiceField(
- queryset=SiteGroup.objects.all(),
- required=False
- )
- site = DynamicModelChoiceField(
- queryset=Site.objects.all(),
- required=False,
- query_params={
- 'region_id': '$region',
- 'group_id': '$site_group',
- }
- )
- vrf = DynamicModelChoiceField(
- queryset=VRF.objects.all(),
- required=False,
- label=_('VRF')
- )
- prefix_length = forms.IntegerField(
- min_value=PREFIX_LENGTH_MIN,
- max_value=PREFIX_LENGTH_MAX,
- required=False
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- choices=add_blank_choice(PrefixStatusChoices),
- required=False
- )
- role = DynamicModelChoiceField(
- queryset=Role.objects.all(),
- required=False
- )
- is_pool = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect(),
- label=_('Is a pool')
- )
- mark_utilized = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect(),
- label=_('Treat as 100% utilized')
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = Prefix
- fieldsets = (
- (None, ('tenant', 'status', 'role', 'description')),
- ('Site', ('region', 'site_group', 'site')),
- ('Addressing', ('vrf', 'prefix_length', 'is_pool', 'mark_utilized')),
- )
- nullable_fields = (
- 'site', 'vrf', 'tenant', 'role', 'description', 'comments',
- )
- class IPRangeBulkEditForm(NetBoxModelBulkEditForm):
- vrf = DynamicModelChoiceField(
- queryset=VRF.objects.all(),
- required=False,
- label=_('VRF')
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- choices=add_blank_choice(IPRangeStatusChoices),
- required=False
- )
- role = DynamicModelChoiceField(
- queryset=Role.objects.all(),
- required=False
- )
- mark_utilized = forms.NullBooleanField(
- required=False,
- widget=BulkEditNullBooleanSelect(),
- label=_('Treat as 100% utilized')
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = IPRange
- fieldsets = (
- (None, ('status', 'role', 'vrf', 'tenant', 'mark_utilized', 'description')),
- )
- nullable_fields = (
- 'vrf', 'tenant', 'role', 'description', 'comments',
- )
- class IPAddressBulkEditForm(NetBoxModelBulkEditForm):
- vrf = DynamicModelChoiceField(
- queryset=VRF.objects.all(),
- required=False,
- label=_('VRF')
- )
- mask_length = forms.IntegerField(
- min_value=IPADDRESS_MASK_LENGTH_MIN,
- max_value=IPADDRESS_MASK_LENGTH_MAX,
- required=False
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- choices=add_blank_choice(IPAddressStatusChoices),
- required=False
- )
- role = forms.ChoiceField(
- choices=add_blank_choice(IPAddressRoleChoices),
- required=False
- )
- dns_name = forms.CharField(
- max_length=255,
- required=False,
- label=_('DNS name')
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = IPAddress
- fieldsets = (
- (None, ('status', 'role', 'tenant', 'description')),
- ('Addressing', ('vrf', 'mask_length', 'dns_name')),
- )
- nullable_fields = (
- 'vrf', 'role', 'tenant', 'dns_name', 'description', 'comments',
- )
- class FHRPGroupBulkEditForm(NetBoxModelBulkEditForm):
- protocol = forms.ChoiceField(
- choices=add_blank_choice(FHRPGroupProtocolChoices),
- required=False
- )
- group_id = forms.IntegerField(
- min_value=0,
- required=False,
- label=_('Group ID')
- )
- auth_type = forms.ChoiceField(
- choices=add_blank_choice(FHRPGroupAuthTypeChoices),
- required=False,
- label=_('Authentication type')
- )
- auth_key = forms.CharField(
- max_length=255,
- required=False,
- label=_('Authentication key')
- )
- name = forms.CharField(
- max_length=100,
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = FHRPGroup
- fieldsets = (
- (None, ('protocol', 'group_id', 'name', 'description')),
- ('Authentication', ('auth_type', 'auth_key')),
- )
- nullable_fields = ('auth_type', 'auth_key', 'name', 'description', 'comments')
- class VLANGroupBulkEditForm(NetBoxModelBulkEditForm):
- site = DynamicModelChoiceField(
- queryset=Site.objects.all(),
- required=False
- )
- min_vid = forms.IntegerField(
- min_value=VLAN_VID_MIN,
- max_value=VLAN_VID_MAX,
- required=False,
- label=_('Minimum child VLAN VID')
- )
- max_vid = forms.IntegerField(
- min_value=VLAN_VID_MIN,
- max_value=VLAN_VID_MAX,
- required=False,
- label=_('Maximum child VLAN VID')
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- model = VLANGroup
- fieldsets = (
- (None, ('site', 'min_vid', 'max_vid', 'description')),
- )
- nullable_fields = ('site', 'description')
- class VLANBulkEditForm(NetBoxModelBulkEditForm):
- region = DynamicModelChoiceField(
- queryset=Region.objects.all(),
- required=False
- )
- site_group = DynamicModelChoiceField(
- queryset=SiteGroup.objects.all(),
- required=False
- )
- site = DynamicModelChoiceField(
- queryset=Site.objects.all(),
- required=False,
- query_params={
- 'region_id': '$region',
- 'group_id': '$site_group',
- }
- )
- group = DynamicModelChoiceField(
- queryset=VLANGroup.objects.all(),
- required=False,
- query_params={
- 'site_id': '$site'
- }
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- status = forms.ChoiceField(
- choices=add_blank_choice(VLANStatusChoices),
- required=False
- )
- role = DynamicModelChoiceField(
- queryset=Role.objects.all(),
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = VLAN
- fieldsets = (
- (None, ('status', 'role', 'tenant', 'description')),
- ('Site & Group', ('region', 'site_group', 'site', 'group')),
- )
- nullable_fields = (
- 'site', 'group', 'tenant', 'role', 'description', 'comments',
- )
- class ServiceTemplateBulkEditForm(NetBoxModelBulkEditForm):
- protocol = forms.ChoiceField(
- choices=add_blank_choice(ServiceProtocolChoices),
- required=False
- )
- ports = NumericArrayField(
- base_field=forms.IntegerField(
- min_value=SERVICE_PORT_MIN,
- max_value=SERVICE_PORT_MAX
- ),
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = ServiceTemplate
- fieldsets = (
- (None, ('protocol', 'ports', 'description')),
- )
- nullable_fields = ('description', 'comments')
- class ServiceBulkEditForm(ServiceTemplateBulkEditForm):
- model = Service
- class L2VPNBulkEditForm(NetBoxModelBulkEditForm):
- type = forms.ChoiceField(
- choices=add_blank_choice(L2VPNTypeChoices),
- required=False
- )
- tenant = DynamicModelChoiceField(
- queryset=Tenant.objects.all(),
- required=False
- )
- description = forms.CharField(
- max_length=200,
- required=False
- )
- comments = CommentField(
- label='Comments'
- )
- model = L2VPN
- fieldsets = (
- (None, ('type', 'tenant', 'description')),
- )
- nullable_fields = ('tenant', 'description', 'comments')
- class L2VPNTerminationBulkEditForm(NetBoxModelBulkEditForm):
- model = L2VPN
|