Ejemplo n.º 1
0
class ObjectChangeFilterForm(FilterForm):
    model = ObjectChange
    field_groups = [
        ['q'],
        ['time_before', 'time_after', 'action'],
        ['user_id', 'changed_object_type_id'],
    ]
    time_after = forms.DateTimeField(required=False,
                                     label=_('After'),
                                     widget=DateTimePicker())
    time_before = forms.DateTimeField(required=False,
                                      label=_('Before'),
                                      widget=DateTimePicker())
    action = forms.ChoiceField(
        choices=add_blank_choice(ObjectChangeActionChoices),
        required=False,
        widget=StaticSelect())
    user_id = DynamicModelMultipleChoiceField(
        queryset=User.objects.all(),
        required=False,
        label=_('User'),
        widget=APISelectMultiple(api_url='/api/users/users/', ))
    changed_object_type_id = DynamicModelMultipleChoiceField(
        queryset=ContentType.objects.all(),
        required=False,
        label=_('Object Type'),
        widget=APISelectMultiple(api_url='/api/extras/content-types/', ))
Ejemplo n.º 2
0
class BGPSessionFilterForm(BootstrapMixin, forms.ModelForm):
    q = forms.CharField(required=False, label='Search')
    remote_as = DynamicModelMultipleChoiceField(
        queryset=ASN.objects.all(),
        required=False,
        display_field='number',
        widget=APISelectMultiple(api_url='/api/plugins/bgp/asn/', ))
    local_as = DynamicModelMultipleChoiceField(
        queryset=ASN.objects.all(),
        required=False,
        display_field='number',
        widget=APISelectMultiple(api_url='/api/plugins/bgp/asn/', ))
    tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(),
                                     required=False)
    status = forms.MultipleChoiceField(choices=SessionStatusChoices,
                                       required=False,
                                       widget=StaticSelect2Multiple())
    import_policies = DynamicModelMultipleChoiceField(
        queryset=RoutingPolicy.objects.all(),
        required=False,
        widget=APISelectMultiple(api_url='/api/plugins/bgp/routing-policy/'))
    export_policies = DynamicModelMultipleChoiceField(
        queryset=RoutingPolicy.objects.all(),
        required=False,
        widget=APISelectMultiple(api_url='/api/plugins/bgp/routing-policy/'))

    tag = TagFilterField(BGPSession)

    class Meta:
        model = BGPSession
        fields = ['q', 'status', 'tenant', 'remote_as', 'local_as']
Ejemplo n.º 3
0
class ObjectChangeFilterForm(BootstrapMixin, forms.Form):
    model = ObjectChange
    field_groups = [
        ['q'],
        ['time_before', 'time_after', 'action'],
        ['user_id', 'changed_object_type_id'],
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    time_after = forms.DateTimeField(required=False,
                                     label=_('After'),
                                     widget=DateTimePicker())
    time_before = forms.DateTimeField(required=False,
                                      label=_('Before'),
                                      widget=DateTimePicker())
    action = forms.ChoiceField(
        choices=add_blank_choice(ObjectChangeActionChoices),
        required=False,
        widget=StaticSelect())
    user_id = DynamicModelMultipleChoiceField(
        queryset=User.objects.all(),
        required=False,
        label=_('User'),
        widget=APISelectMultiple(api_url='/api/users/users/', ),
        fetch_trigger='open')
    changed_object_type_id = DynamicModelMultipleChoiceField(
        queryset=ContentType.objects.all(),
        required=False,
        label=_('Object Type'),
        widget=APISelectMultiple(api_url='/api/extras/content-types/', ),
        fetch_trigger='open')
Ejemplo n.º 4
0
class VLANFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
    model = VLAN
    field_order = [
        'q', 'site', 'group_id', 'status', 'role', 'tenant_group', 'tenant'
    ]
    q = forms.CharField(required=False, label='Search')
    site = FilterChoiceField(queryset=Site.objects.all(),
                             to_field_name='slug',
                             null_label='-- Global --',
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/sites/",
                                 value_field="slug",
                                 null_option=True,
                             ))
    group_id = FilterChoiceField(queryset=VLANGroup.objects.all(),
                                 label='VLAN group',
                                 null_label='-- None --',
                                 widget=APISelectMultiple(
                                     api_url="/api/ipam/vlan-groups/",
                                     null_option=True,
                                 ))
    status = forms.MultipleChoiceField(choices=VLAN_STATUS_CHOICES,
                                       required=False,
                                       widget=StaticSelect2Multiple())
    role = FilterChoiceField(queryset=Role.objects.all(),
                             to_field_name='slug',
                             null_label='-- None --',
                             widget=APISelectMultiple(
                                 api_url="/api/ipam/roles/",
                                 value_field="slug",
                                 null_option=True,
                             ))
Ejemplo n.º 5
0
class DeviceFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = Device

    q = forms.CharField(required=False, label='Search')

    site = FilterChoiceField(queryset=Site.objects.all(),
                             to_field_name='slug',
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/sites/",
                                 value_field="slug",
                                 filter_for={
                                     'rack_group_id': 'site',
                                     'rack_id': 'site',
                                 }))
    rack_group_id = FilterChoiceField(
        queryset=RackGroup.objects.select_related('site'),
        label='Rack group',
        widget=APISelectMultiple(api_url="/api/dcim/rack-groups/",
                                 filter_for={
                                     'rack_id': 'rack_group_id',
                                 }))
    rack_id = FilterChoiceField(queryset=Rack.objects.all(),
                                label='Rack',
                                null_label='-- None --',
                                widget=APISelectMultiple(
                                    api_url="/api/dcim/racks/",
                                    null_option=True,
                                ))
Ejemplo n.º 6
0
class JournalEntryFilterForm(BootstrapMixin, forms.Form):
    model = JournalEntry
    field_groups = [['q'],
                    ['created_before', 'created_after', 'created_by_id'],
                    ['assigned_object_type_id', 'kind']]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    created_after = forms.DateTimeField(required=False,
                                        label=_('After'),
                                        widget=DateTimePicker())
    created_before = forms.DateTimeField(required=False,
                                         label=_('Before'),
                                         widget=DateTimePicker())
    created_by_id = DynamicModelMultipleChoiceField(
        queryset=User.objects.all(),
        required=False,
        label=_('User'),
        widget=APISelectMultiple(api_url='/api/users/users/', ),
        fetch_trigger='open')
    assigned_object_type_id = DynamicModelMultipleChoiceField(
        queryset=ContentType.objects.all(),
        required=False,
        label=_('Object Type'),
        widget=APISelectMultiple(api_url='/api/extras/content-types/', ),
        fetch_trigger='open')
    kind = forms.ChoiceField(choices=add_blank_choice(JournalEntryKindChoices),
                             required=False,
                             widget=StaticSelect())
Ejemplo n.º 7
0
class ClusterFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = Cluster
    q = forms.CharField(required=False, label='Search')
    type = FilterChoiceField(queryset=ClusterType.objects.all(),
                             to_field_name='slug',
                             required=False,
                             widget=APISelectMultiple(
                                 api_url="/api/virtualization/cluster-types/",
                                 value_field='slug',
                             ))
    group = FilterChoiceField(
        queryset=ClusterGroup.objects.all(),
        to_field_name='slug',
        null_label='-- None --',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/virtualization/cluster-groups/",
            value_field='slug',
            null_option=True,
        ))
    site = FilterChoiceField(queryset=Site.objects.all(),
                             to_field_name='slug',
                             null_label='-- None --',
                             required=False,
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/sites/",
                                 value_field='slug',
                                 null_option=True,
                             ))
class ServiceMappingFilterForm(BootstrapMixin, forms.ModelForm):
    model = Device
    field_order = ['q', 'status', 'role', 'tenant', 'device_type_id', 'tag']
    q = forms.CharField(required=False, label='Search device or service')
    tenant = DynamicModelMultipleChoiceField(
        queryset=Tenant.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            # value_field="slug",
            # null_option=True,
        ))
    role = DynamicModelMultipleChoiceField(
        queryset=DeviceRole.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            # value_field="slug",
        ))
    device_type_id = DynamicModelMultipleChoiceField(
        queryset=DeviceType.objects.all(),
        required=False,
        label='Model',
        display_field="model",
        widget=APISelectMultiple())
    status = forms.MultipleChoiceField(label='Status',
                                       choices=ServiceComplianceChoices,
                                       required=False,
                                       widget=StaticSelect2Multiple())

    tag = TagFilterField(model)

    class Meta:
        model = Device
        fields = ['q', 'status', 'role', 'tenant', 'device_type_id', 'tag']
Ejemplo n.º 9
0
class ClusterFilterForm(BootstrapMixin, TenancyFilterForm,
                        CustomFieldFilterForm):
    model = Cluster
    field_order = [
        'q', 'type', 'region', 'site', 'group', 'tenant_group', 'tenant'
    ]
    q = forms.CharField(required=False, label='Search')
    type = DynamicModelMultipleChoiceField(queryset=ClusterType.objects.all(),
                                           to_field_name='slug',
                                           required=False,
                                           widget=APISelectMultiple(
                                               value_field='slug', ))
    region = DynamicModelMultipleChoiceField(
        queryset=Region.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(value_field="slug",
                                 filter_for={'site': 'region'}))
    site = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                           to_field_name='slug',
                                           required=False,
                                           widget=APISelectMultiple(
                                               value_field='slug',
                                               null_option=True,
                                           ))
    group = DynamicModelMultipleChoiceField(
        queryset=ClusterGroup.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            value_field='slug',
            null_option=True,
        ))
    tag = TagFilterField(model)
Ejemplo n.º 10
0
class ProviderFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = Provider
    q = forms.CharField(
        required=False,
        label='Search'
    )
    region = FilterChoiceField(
        queryset=Region.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/dcim/regions/",
            value_field="slug",
            filter_for={
                'site': 'region'
            }
        )
    )
    site = FilterChoiceField(
        queryset=Site.objects.all(),
        to_field_name='slug',
        widget=APISelectMultiple(
            api_url="/api/dcim/sites/",
            value_field="slug",
        )
    )
    asn = forms.IntegerField(
        required=False,
        label='ASN'
    )
Ejemplo n.º 11
0
class CircuitFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = Circuit
    q = forms.CharField(required=False, label='Search')
    type = FilterChoiceField(queryset=CircuitType.objects.all(),
                             to_field_name='slug',
                             widget=APISelectMultiple(
                                 api_url="/api/circuits/circuit-types/",
                                 value_field="slug",
                             ))
    provider = FilterChoiceField(queryset=Provider.objects.all(),
                                 to_field_name='slug',
                                 widget=APISelectMultiple(
                                     api_url="/api/circuits/providers/",
                                     value_field="slug",
                                 ))
    status = forms.MultipleChoiceField(choices=CIRCUIT_STATUS_CHOICES,
                                       required=False,
                                       widget=StaticSelect2Multiple())
    tenant = FilterChoiceField(queryset=Tenant.objects.all(),
                               to_field_name='slug',
                               null_label='-- None --',
                               widget=APISelectMultiple(
                                   api_url="/api/tenancy/tenants/",
                                   value_field="slug",
                                   null_option=True,
                               ))
    site = FilterChoiceField(queryset=Site.objects.all(),
                             to_field_name='slug',
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/sites/",
                                 value_field="slug",
                             ))
    commit_rate = forms.IntegerField(required=False,
                                     min_value=0,
                                     label='Commit rate (Kbps)')
Ejemplo n.º 12
0
Archivo: forms.py Proyecto: wuwx/netbox
class PrefixFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = Prefix
    q = forms.CharField(required=False, label='Search')
    within_include = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={
            'placeholder': 'Prefix',
        }),
        label='Search within')
    family = forms.ChoiceField(required=False,
                               choices=IP_FAMILY_CHOICES,
                               label='Address family',
                               widget=StaticSelect2())
    mask_length = forms.ChoiceField(required=False,
                                    choices=PREFIX_MASK_LENGTH_CHOICES,
                                    label='Mask length',
                                    widget=StaticSelect2())
    vrf = FilterChoiceField(queryset=VRF.objects.all(),
                            to_field_name='rd',
                            label='VRF',
                            null_label='-- Global --',
                            widget=APISelectMultiple(
                                api_url="/api/ipam/vrfs/",
                                value_field="rd",
                                null_option=True,
                            ))
    tenant = FilterChoiceField(queryset=Tenant.objects.all(),
                               to_field_name='slug',
                               null_label='-- None --',
                               widget=APISelectMultiple(
                                   api_url="/api/tenancy/tenants/",
                                   value_field="slug",
                                   null_option=True,
                               ))
    status = forms.MultipleChoiceField(choices=PREFIX_STATUS_CHOICES,
                                       required=False,
                                       widget=StaticSelect2Multiple())
    site = FilterChoiceField(queryset=Site.objects.all(),
                             to_field_name='slug',
                             null_label='-- None --',
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/sites/",
                                 value_field="slug",
                                 null_option=True,
                             ))
    role = FilterChoiceField(queryset=Role.objects.all(),
                             to_field_name='slug',
                             null_label='-- None --',
                             widget=APISelectMultiple(
                                 api_url="/api/ipam/roles/",
                                 value_field="slug",
                                 null_option=True,
                             ))
    is_pool = forms.NullBooleanField(
        required=False,
        label='Is a pool',
        widget=StaticSelect2(choices=BOOLEAN_WITH_BLANK_CHOICES))
    expand = forms.BooleanField(required=False,
                                label='Expand prefix hierarchy')
Ejemplo n.º 13
0
class IPAddressFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = IPAddress
    q = forms.CharField(
        required=False,
        label='Search'
    )
    parent = forms.CharField(
        required=False,
        widget=forms.TextInput(
            attrs={
                'placeholder': 'Prefix',
            }
        ),
        label='Parent Prefix'
    )
    family = forms.ChoiceField(
        required=False,
        choices=IP_FAMILY_CHOICES,
        label='Address family',
        widget=StaticSelect2()
    )
    mask_length = forms.ChoiceField(
        required=False,
        choices=IPADDRESS_MASK_LENGTH_CHOICES,
        label='Mask length',
        widget=StaticSelect2()
    )
    vrf = FilterChoiceField(
        queryset=VRF.objects.all(),
        to_field_name='rd',
        label='VRF',
        null_label='-- Global --',
        widget=APISelectMultiple(
            api_url="/api/ipam/vrfs/",
            value_field="slug",
            null_option=True,
        )
    )
    tenant = FilterChoiceField(
        queryset=Tenant.objects.all(),
        to_field_name='slug',
        null_label='-- None --',
        widget=APISelectMultiple(
            api_url="/api/tenancy/tenants/",
            value_field="slug",
            null_option=True,
        )
    )
    status = forms.MultipleChoiceField(
        choices=IPADDRESS_STATUS_CHOICES,
        required=False,
        widget=StaticSelect2Multiple()
    )
    role = forms.MultipleChoiceField(
        choices=IPADDRESS_ROLE_CHOICES,
        required=False,
        widget=StaticSelect2Multiple()
    )
Ejemplo n.º 14
0
class CircuitFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
    model = Circuit
    field_order = [
        'q', 'type', 'provider', 'status', 'region', 'site', 'tenant_group', 'tenant', 'commit_rate',
    ]
    q = forms.CharField(
        required=False,
        label='Search'
    )
    type = FilterChoiceField(
        queryset=CircuitType.objects.all(),
        to_field_name='slug',
        widget=APISelectMultiple(
            api_url="/api/circuits/circuit-types/",
            value_field="slug",
        )
    )
    provider = FilterChoiceField(
        queryset=Provider.objects.all(),
        to_field_name='slug',
        widget=APISelectMultiple(
            api_url="/api/circuits/providers/",
            value_field="slug",
        )
    )
    status = forms.MultipleChoiceField(
        choices=CircuitStatusChoices,
        required=False,
        widget=StaticSelect2Multiple()
    )
    region = forms.ModelMultipleChoiceField(
        queryset=Region.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/dcim/regions/",
            value_field="slug",
            filter_for={
                'site': 'region'
            }
        )
    )
    site = FilterChoiceField(
        queryset=Site.objects.all(),
        to_field_name='slug',
        widget=APISelectMultiple(
            api_url="/api/dcim/sites/",
            value_field="slug",
        )
    )
    commit_rate = forms.IntegerField(
        required=False,
        min_value=0,
        label='Commit rate (Kbps)'
    )
    tag = TagFilterField(model)
Ejemplo n.º 15
0
class VLANFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
    model = VLAN
    field_order = ['q', 'region', 'site', 'group_id', 'status', 'role', 'tenant_group', 'tenant']
    q = forms.CharField(
        required=False,
        label='Search'
    )
    region = DynamicModelMultipleChoiceField(
        queryset=Region.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/dcim/regions/",
            value_field="slug",
            filter_for={
                'site': 'region',
                'group_id': 'region'
            }
        )
    )
    site = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/dcim/sites/",
            value_field="slug",
            null_option=True,
        )
    )
    group_id = DynamicModelMultipleChoiceField(
        queryset=VLANGroup.objects.all(),
        required=False,
        label='VLAN group',
        widget=APISelectMultiple(
            api_url="/api/ipam/vlan-groups/",
            null_option=True,
        )
    )
    status = forms.MultipleChoiceField(
        choices=VLANStatusChoices,
        required=False,
        widget=StaticSelect2Multiple()
    )
    role = DynamicModelMultipleChoiceField(
        queryset=Role.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/ipam/roles/",
            value_field="slug",
            null_option=True,
        )
    )
    tag = TagFilterField(model)
Ejemplo n.º 16
0
class ConfigContextFilterForm(BootstrapMixin, forms.Form):
    q = forms.CharField(required=False, label='Search')
    region = FilterChoiceField(queryset=Region.objects.all(),
                               to_field_name='slug',
                               widget=APISelectMultiple(
                                   api_url="/api/dcim/regions/",
                                   value_field="slug",
                               ))
    site = FilterChoiceField(queryset=Site.objects.all(),
                             to_field_name='slug',
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/sites/",
                                 value_field="slug",
                             ))
    role = FilterChoiceField(queryset=DeviceRole.objects.all(),
                             to_field_name='slug',
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/device-roles/",
                                 value_field="slug",
                             ))
    platform = FilterChoiceField(queryset=Platform.objects.all(),
                                 to_field_name='slug',
                                 widget=APISelectMultiple(
                                     api_url="/api/dcim/platforms/",
                                     value_field="slug",
                                 ))
    cluster_group = FilterChoiceField(
        queryset=ClusterGroup.objects.all(),
        to_field_name='slug',
        widget=APISelectMultiple(
            api_url="/api/virtualization/cluster-groups/",
            value_field="slug",
        ))
    cluster_id = FilterChoiceField(
        queryset=Cluster.objects.all(),
        label='Cluster',
        widget=APISelectMultiple(api_url="/api/virtualization/clusters/", ))
    tenant_group = FilterChoiceField(queryset=TenantGroup.objects.all(),
                                     to_field_name='slug',
                                     widget=APISelectMultiple(
                                         api_url="/api/tenancy/tenant-groups/",
                                         value_field="slug",
                                     ))
    tenant = FilterChoiceField(queryset=Tenant.objects.all(),
                               to_field_name='slug',
                               widget=APISelectMultiple(
                                   api_url="/api/tenancy/tenants/",
                                   value_field="slug",
                               ))
    tag = FilterChoiceField(queryset=Tag.objects.all(),
                            to_field_name='slug',
                            widget=APISelectMultiple(
                                api_url="/api/extras/tags/",
                                value_field="slug",
                            ))
Ejemplo n.º 17
0
class ClusterFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
    model = Cluster
    field_order = [
        'q', 'type', 'region', 'site', 'group', 'tenant_group', 'tenant'
    ]
    q = forms.CharField(required=False, label='Search')
    type = FilterChoiceField(
        queryset=ClusterType.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/virtualization/cluster-types/",
            value_field='slug',
        )
    )
    region = FilterChoiceField(
        queryset=Region.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/dcim/regions/",
            value_field="slug",
            filter_for={
                'site': 'region'
            }
        )
    )
    site = FilterChoiceField(
        queryset=Site.objects.all(),
        to_field_name='slug',
        null_label='-- None --',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/dcim/sites/",
            value_field='slug',
            null_option=True,
        )
    )
    group = FilterChoiceField(
        queryset=ClusterGroup.objects.all(),
        to_field_name='slug',
        null_label='-- None --',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/virtualization/cluster-groups/",
            value_field='slug',
            null_option=True,
        )
    )
    tag = TagFilterField(model)
Ejemplo n.º 18
0
class TenancyFilterForm(forms.Form):
    tenant_group = DynamicModelMultipleChoiceField(
        queryset=TenantGroup.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(value_field="slug",
                                 null_option=True,
                                 filter_for={'tenant': 'group'}))
    tenant = DynamicModelMultipleChoiceField(queryset=Tenant.objects.all(),
                                             to_field_name='slug',
                                             required=False,
                                             widget=APISelectMultiple(
                                                 value_field="slug",
                                                 null_option=True,
                                             ))
Ejemplo n.º 19
0
class VLANGroupFilterForm(BootstrapMixin, forms.Form):
    region = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                             to_field_name='slug',
                                             required=False,
                                             widget=APISelectMultiple(
                                                 value_field="slug",
                                                 filter_for={
                                                     'site': 'region',
                                                 }))
    site = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                           to_field_name='slug',
                                           required=False,
                                           widget=APISelectMultiple(
                                               value_field="slug",
                                               null_option=True,
                                           ))
Ejemplo n.º 20
0
class RackReservationFilterForm(TenancyFilterForm, CustomFieldModelFilterForm):
    model = RackReservation
    field_groups = [
        ['q', 'tag'],
        ['user_id'],
        ['region_id', 'site_id', 'location_id'],
        ['tenant_group_id', 'tenant_id'],
    ]
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label=_('Region'))
    site_id = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
        query_params={'region_id': '$region_id'},
        label=_('Site'))
    location_id = DynamicModelMultipleChoiceField(
        queryset=Location.objects.prefetch_related('site'),
        required=False,
        label=_('Location'),
        null_option='None')
    user_id = DynamicModelMultipleChoiceField(
        queryset=User.objects.all(),
        required=False,
        label=_('User'),
        widget=APISelectMultiple(api_url='/api/users/users/', ))
    tag = TagFilterField(model)
Ejemplo n.º 21
0
class LicencesFilterForm(BootstrapMixin, forms.ModelForm):
    q = forms.CharField(required=False, label="Search")

    software = DynamicModelMultipleChoiceField(
        queryset=Software.objects.all(),
        required=False,
        widget=APISelectMultiple(api_url="/api/plugins/licences/software/", ))

    site = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
    )

    date_valid_after = forms.DateField(required=False,
                                       input_formats='%Y,%m,%d',
                                       widget=DatePicker())

    date_valid_before = forms.DateField(required=False,
                                        input_formats='%Y,%m,%d',
                                        widget=DatePicker())

    class Meta:
        model = Licence
        fields = [
            "q",
            "site",
            "software",
        ]
Ejemplo n.º 22
0
class ServiceRuleForm(BootstrapMixin, forms.ModelForm):
    service = forms.ModelChoiceField(queryset=Service.objects.all(),
                                     widget=StaticSelect2())

    description = forms.CharField(
        required=False,
        label="Description",
    )

    device_role = DynamicModelMultipleChoiceField(
        queryset=DeviceRole.objects.all(),
        required=True,
    )

    device_type = DynamicModelMultipleChoiceField(
        queryset=DeviceType.objects.all(),
        required=False,
        label='Model',
        display_field="model",
        widget=APISelectMultiple())

    template = forms.ModelChoiceField(
        queryset=Template.objects.order_by('name'), widget=StaticSelect2())

    class Meta:
        model = Template
        fields = [
            'service', 'device_role', 'device_type', 'template', 'description'
        ]
Ejemplo n.º 23
0
class ProviderFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = Provider
    q = forms.CharField(required=False, label='Search')
    region = DynamicModelMultipleChoiceField(
        queryset=Region.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(value_field="slug",
                                 filter_for={'site': 'region'}))
    site = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                           to_field_name='slug',
                                           required=False,
                                           widget=APISelectMultiple(
                                               value_field="slug", ))
    asn = forms.IntegerField(required=False, label='ASN')
    tag = TagFilterField(model)
Ejemplo n.º 24
0
class ClusterAddDevicesForm(BootstrapMixin, forms.Form):
    region = DynamicModelChoiceField(queryset=Region.objects.all(),
                                     required=False,
                                     widget=APISelect(
                                         api_url="/api/dcim/regions/",
                                         filter_for={
                                             "site": "region_id",
                                         },
                                         attrs={
                                             'nullable': 'true',
                                         }))
    site = DynamicModelChoiceField(queryset=Site.objects.all(),
                                   required=False,
                                   widget=APISelect(api_url='/api/dcim/sites/',
                                                    filter_for={
                                                        "rack": "site_id",
                                                        "devices": "site_id",
                                                    }))
    rack = DynamicModelChoiceField(queryset=Rack.objects.all(),
                                   required=False,
                                   widget=APISelect(
                                       api_url='/api/dcim/racks/',
                                       filter_for={"devices": "rack_id"},
                                       attrs={
                                           'nullable': 'true',
                                       }))
    devices = DynamicModelMultipleChoiceField(
        queryset=Device.objects.filter(cluster__isnull=True),
        widget=APISelectMultiple(api_url='/api/dcim/devices/',
                                 display_field='display_name',
                                 disabled_indicator='cluster'))

    class Meta:
        fields = [
            'region',
            'site',
            'rack',
            'devices',
        ]

    def __init__(self, cluster, *args, **kwargs):

        self.cluster = cluster

        super().__init__(*args, **kwargs)

        self.fields['devices'].choices = []

    def clean(self):
        super().clean()

        # If the Cluster is assigned to a Site, all Devices must be assigned to that Site.
        if self.cluster.site is not None:
            for device in self.cleaned_data.get('devices', []):
                if device.site != self.cluster.site:
                    raise ValidationError({
                        'devices':
                        "{} belongs to a different site ({}) than the cluster ({})"
                        .format(device, device.site, self.cluster.site)
                    })
Ejemplo n.º 25
0
class IPAddressFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
    model = IPAddress
    field_order = [
        'q', 'parent', 'family', 'mask_length', 'vrf_id', 'status', 'role', 'assigned_to_interface', 'tenant_group',
        'tenant',
    ]
    q = forms.CharField(
        required=False,
        label='Search'
    )
    parent = forms.CharField(
        required=False,
        widget=forms.TextInput(
            attrs={
                'placeholder': 'Prefix',
            }
        ),
        label='Parent Prefix'
    )
    family = forms.ChoiceField(
        required=False,
        choices=add_blank_choice(IPAddressFamilyChoices),
        label='Address family',
        widget=StaticSelect2()
    )
    mask_length = forms.ChoiceField(
        required=False,
        choices=IPADDRESS_MASK_LENGTH_CHOICES,
        label='Mask length',
        widget=StaticSelect2()
    )
    vrf_id = DynamicModelMultipleChoiceField(
        queryset=VRF.objects.all(),
        required=False,
        label='VRF',
        widget=APISelectMultiple(
            api_url="/api/ipam/vrfs/",
            null_option=True,
        )
    )
    status = forms.MultipleChoiceField(
        choices=IPAddressStatusChoices,
        required=False,
        widget=StaticSelect2Multiple()
    )
    role = forms.MultipleChoiceField(
        choices=IPAddressRoleChoices,
        required=False,
        widget=StaticSelect2Multiple()
    )
    assigned_to_interface = forms.NullBooleanField(
        required=False,
        label='Assigned to an interface',
        widget=StaticSelect2(
            choices=BOOLEAN_WITH_BLANK_CHOICES
        )
    )
    tag = TagFilterField(model)
Ejemplo n.º 26
0
class InterfaceBulkEditForm(BootstrapMixin, BulkEditForm):
    pk = forms.ModelMultipleChoiceField(queryset=Interface.objects.all(),
                                        widget=forms.MultipleHiddenInput())
    virtual_machine = forms.ModelChoiceField(
        queryset=VirtualMachine.objects.all(), widget=forms.HiddenInput())
    enabled = forms.NullBooleanField(required=False,
                                     widget=BulkEditNullBooleanSelect())
    mtu = forms.IntegerField(required=False,
                             min_value=INTERFACE_MTU_MIN,
                             max_value=INTERFACE_MTU_MAX,
                             label='MTU')
    description = forms.CharField(max_length=100, required=False)
    mode = forms.ChoiceField(choices=add_blank_choice(InterfaceModeChoices),
                             required=False,
                             widget=StaticSelect2())
    untagged_vlan = DynamicModelChoiceField(queryset=VLAN.objects.all(),
                                            required=False,
                                            widget=APISelect(
                                                api_url="/api/ipam/vlans/",
                                                display_field='display_name',
                                                full=True,
                                                additional_query_params={
                                                    'site_id': 'null',
                                                },
                                            ))
    tagged_vlans = DynamicModelMultipleChoiceField(
        queryset=VLAN.objects.all(),
        required=False,
        widget=APISelectMultiple(
            api_url="/api/ipam/vlans/",
            display_field='display_name',
            full=True,
            additional_query_params={
                'site_id': 'null',
            },
        ))

    class Meta:
        nullable_fields = [
            'mtu',
            'description',
        ]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # Limit available VLANs based on the parent VirtualMachine
        if 'virtual_machine' in self.initial:
            parent_obj = VirtualMachine.objects.filter(
                pk=self.initial['virtual_machine']).first()

            site = getattr(parent_obj.cluster, 'site', None)
            if site is not None:
                # Add current site to VLANs query params
                self.fields['untagged_vlan'].widget.add_additional_query_param(
                    'site_id', site.pk)
                self.fields['tagged_vlans'].widget.add_additional_query_param(
                    'site_id', site.pk)
Ejemplo n.º 27
0
class BGPSessionForm(BootstrapMixin, forms.ModelForm):
    name = forms.CharField(max_length=64, required=True)
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)
    site = DynamicModelChoiceField(queryset=Site.objects.all(), required=False)
    device = DynamicModelChoiceField(queryset=Device.objects.all(),
                                     required=False,
                                     query_params={'site_id': '$site'})
    tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(),
                                     required=False)
    local_as = DynamicModelChoiceField(queryset=ASN.objects.all(),
                                       query_params={'site_id': '$site'},
                                       display_field='number',
                                       widget=APISelect(
                                           api_url='/api/plugins/bgp/asn/', ))
    remote_as = DynamicModelChoiceField(queryset=ASN.objects.all(),
                                        query_params={'site_id': '$site'},
                                        display_field='number',
                                        widget=APISelect(
                                            api_url='/api/plugins/bgp/asn/', ))
    local_address = DynamicModelChoiceField(
        queryset=IPAddress.objects.all(),
        display_field='address',
        query_params={'device_id': '$device'})
    import_policies = DynamicModelMultipleChoiceField(
        queryset=RoutingPolicy.objects.all(),
        required=False,
        widget=APISelectMultiple(api_url='/api/plugins/bgp/routing-policy/'))
    export_policies = DynamicModelMultipleChoiceField(
        queryset=RoutingPolicy.objects.all(),
        required=False,
        widget=APISelectMultiple(api_url='/api/plugins/bgp/routing-policy/'))

    class Meta:
        model = BGPSession
        fields = [
            'name', 'site', 'device', 'local_as', 'remote_as', 'local_address',
            'remote_address', 'description', 'status', 'tenant', 'tags',
            'import_policies', 'export_policies'
        ]
        fieldsets = (('Session', ('name', 'site', 'device', 'description',
                                  'status', 'tenant', 'tags')),
                     ('Remote', ('remote_as', 'remote_address')),
                     ('Local', ('local_as', 'local_address')),
                     ('Policies', ('import_policies', 'export_policies')))
Ejemplo n.º 28
0
class VLANGroupFilterForm(BootstrapMixin, forms.Form):
    region = FilterChoiceField(queryset=Region.objects.all(),
                               to_field_name='slug',
                               required=False,
                               widget=APISelectMultiple(
                                   api_url="/api/dcim/regions/",
                                   value_field="slug",
                                   filter_for={
                                       'site': 'region',
                                   }))
    site = FilterChoiceField(queryset=Site.objects.all(),
                             to_field_name='slug',
                             null_label='-- Global --',
                             widget=APISelectMultiple(
                                 api_url="/api/dcim/sites/",
                                 value_field="slug",
                                 null_option=True,
                             ))
Ejemplo n.º 29
0
class ClusterAddDevicesForm(BootstrapMixin, ChainedFieldsMixin, forms.Form):
    region = TreeNodeChoiceField(queryset=Region.objects.all(),
                                 required=False,
                                 widget=forms.Select(attrs={
                                     'filter-for': 'site',
                                     'nullable': 'true'
                                 }))
    site = ChainedModelChoiceField(
        queryset=Site.objects.all(),
        chains=(('region', 'region'), ),
        required=False,
        widget=APISelect(api_url='/api/dcim/sites/?region_id={{region}}',
                         attrs={'filter-for': 'rack'}))
    rack = ChainedModelChoiceField(
        queryset=Rack.objects.all(),
        chains=(('site', 'site'), ),
        required=False,
        widget=APISelect(api_url='/api/dcim/racks/?site_id={{site}}',
                         attrs={
                             'filter-for': 'devices',
                             'nullable': 'true'
                         }))
    devices = ChainedModelMultipleChoiceField(
        queryset=Device.objects.filter(cluster__isnull=True),
        chains=(
            ('site', 'site'),
            ('rack', 'rack'),
        ),
        widget=APISelectMultiple(
            api_url='/api/dcim/devices/?site_id={{site}}&rack_id={{rack}}',
            display_field='display_name',
            disabled_indicator='cluster'))

    class Meta:
        fields = ['region', 'site', 'rack', 'devices']

    def __init__(self, cluster, *args, **kwargs):

        self.cluster = cluster

        super(ClusterAddDevicesForm, self).__init__(*args, **kwargs)

        self.fields['devices'].choices = []

    def clean(self):

        super(ClusterAddDevicesForm, self).clean()

        # If the Cluster is assigned to a Site, all Devices must be assigned to that Site.
        if self.cluster.site is not None:
            for device in self.cleaned_data.get('devices', []):
                if device.site != self.cluster.site:
                    raise ValidationError({
                        'devices':
                        "{} belongs to a different site ({}) than the cluster ({})"
                        .format(device, device.site, self.cluster.site)
                    })
Ejemplo n.º 30
0
class SecretFilterForm(BootstrapMixin, CustomFieldFilterForm):
    model = Secret
    q = forms.CharField(required=False, label='Search')
    role = FilterChoiceField(queryset=SecretRole.objects.all(),
                             to_field_name='slug',
                             widget=APISelectMultiple(
                                 api_url="/api/secrets/secret-roles/",
                                 value_field="slug",
                             ))