Beispiel #1
0
class ClusterFilterForm(BootstrapMixin, TenancyFilterForm,
                        CustomFieldModelFilterForm):
    model = Cluster
    field_order = [
        'q',
        'type_id',
        'region_id',
        'site_id',
        'group_id',
        'tenant_group_id',
        'tenant_id',
    ]
    field_groups = [
        ['q', 'tag'],
        ['group_id', 'type_id'],
        ['region_id', 'site_group_id', 'site_id'],
        ['tenant_group_id', 'tenant_id'],
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    type_id = DynamicModelMultipleChoiceField(
        queryset=ClusterType.objects.all(),
        required=False,
        label=_('Type'),
        fetch_trigger='open')
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label=_('Region'),
                                                fetch_trigger='open')
    site_group_id = DynamicModelMultipleChoiceField(
        queryset=SiteGroup.objects.all(),
        required=False,
        label=_('Site group'),
        fetch_trigger='open')
    site_id = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                              required=False,
                                              null_option='None',
                                              query_params={
                                                  'region_id':
                                                  '$region_id',
                                                  'site_group_id':
                                                  '$site_group_id',
                                              },
                                              label=_('Site'),
                                              fetch_trigger='open')
    group_id = DynamicModelMultipleChoiceField(
        queryset=ClusterGroup.objects.all(),
        required=False,
        null_option='None',
        label=_('Group'),
        fetch_trigger='open')
    tag = TagFilterField(model)
Beispiel #2
0
class VMInterfaceForm(BootstrapMixin, InterfaceCommonForm,
                      CustomFieldModelForm):
    parent = DynamicModelChoiceField(queryset=VMInterface.objects.all(),
                                     required=False,
                                     label='Parent interface')
    untagged_vlan = DynamicModelChoiceField(queryset=VLAN.objects.all(),
                                            required=False,
                                            label='Untagged VLAN')
    tagged_vlans = DynamicModelMultipleChoiceField(queryset=VLAN.objects.all(),
                                                   required=False,
                                                   label='Tagged VLANs')
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = VMInterface
        fields = [
            'virtual_machine',
            'name',
            'enabled',
            'parent',
            'mac_address',
            'mtu',
            'description',
            'mode',
            'tags',
            'untagged_vlan',
            'tagged_vlans',
        ]
        widgets = {
            'virtual_machine': forms.HiddenInput(),
            'mode': StaticSelect2()
        }
        labels = {
            'mode': '802.1Q Mode',
        }
        help_texts = {
            'mode': INTERFACE_MODE_HELP_TEXT,
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        vm_id = self.initial.get('virtual_machine') or self.data.get(
            'virtual_machine')

        # Restrict parent interface assignment by VM
        self.fields['parent'].widget.add_query_param('virtualmachine_id',
                                                     vm_id)

        # Limit VLAN choices by virtual machine
        self.fields['untagged_vlan'].widget.add_query_param(
            'available_on_virtualmachine', vm_id)
        self.fields['tagged_vlans'].widget.add_query_param(
            'available_on_virtualmachine', vm_id)
Beispiel #3
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)
    site = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                           to_field_name='slug',
                                           required=False,
                                           query_params={'region': '$region'})
    asn = forms.IntegerField(required=False, label='ASN')
    tag = TagFilterField(model)
Beispiel #4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # Add add/remove tags fields
        self.fields['add_tags'] = DynamicModelMultipleChoiceField(
            queryset=Tag.objects.all(),
            required=False
        )
        self.fields['remove_tags'] = DynamicModelMultipleChoiceField(
            queryset=Tag.objects.all(),
            required=False
        )
Beispiel #5
0
class RouteTargetFilterForm(TenancyFilterForm, CustomFieldModelFilterForm):
    model = RouteTarget
    field_groups = [
        ['q', 'tag'],
        ['importing_vrf_id', 'exporting_vrf_id'],
        ['tenant_group_id', 'tenant_id'],
    ]
    importing_vrf_id = DynamicModelMultipleChoiceField(
        queryset=VRF.objects.all(), required=False, label=_('Imported by VRF'))
    exporting_vrf_id = DynamicModelMultipleChoiceField(
        queryset=VRF.objects.all(), required=False, label=_('Exported by VRF'))
    tag = TagFilterField(model)
Beispiel #6
0
class TenancyFilterForm(forms.Form):
    tenant_group = DynamicModelMultipleChoiceField(
        queryset=TenantGroup.objects.all(),
        to_field_name='slug',
        required=False,
        null_option='None')
    tenant = DynamicModelMultipleChoiceField(
        queryset=Tenant.objects.all(),
        to_field_name='slug',
        required=False,
        null_option='None',
        query_params={'group': '$tenant_group'})
Beispiel #7
0
class PowerFeedFilterForm(CustomFieldModelFilterForm):
    model = PowerFeed
    field_groups = [
        ['q', 'tag'],
        ['region_id', 'site_group_id', 'site_id'],
        ['power_panel_id', 'rack_id'],
        [
            'status', 'type', 'supply', 'phase', 'voltage', 'amperage',
            'max_utilization'
        ],
    ]
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label=_('Region'))
    site_group_id = DynamicModelMultipleChoiceField(
        queryset=SiteGroup.objects.all(),
        required=False,
        label=_('Site group'))
    site_id = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
        query_params={'region_id': '$region_id'},
        label=_('Site'))
    power_panel_id = DynamicModelMultipleChoiceField(
        queryset=PowerPanel.objects.all(),
        required=False,
        null_option='None',
        query_params={'site_id': '$site_id'},
        label=_('Power panel'))
    rack_id = DynamicModelMultipleChoiceField(
        queryset=Rack.objects.all(),
        required=False,
        null_option='None',
        query_params={'site_id': '$site_id'},
        label=_('Rack'))
    status = forms.MultipleChoiceField(choices=PowerFeedStatusChoices,
                                       required=False,
                                       widget=StaticSelectMultiple())
    type = forms.ChoiceField(choices=add_blank_choice(PowerFeedTypeChoices),
                             required=False,
                             widget=StaticSelect())
    supply = forms.ChoiceField(
        choices=add_blank_choice(PowerFeedSupplyChoices),
        required=False,
        widget=StaticSelect())
    phase = forms.ChoiceField(choices=add_blank_choice(PowerFeedPhaseChoices),
                              required=False,
                              widget=StaticSelect())
    voltage = forms.IntegerField(required=False)
    amperage = forms.IntegerField(required=False)
    max_utilization = forms.IntegerField(required=False)
    tag = TagFilterField(model)
Beispiel #8
0
class RackFilterForm(BootstrapMixin, TenancyFilterForm,
                     CustomFieldModelFilterForm):
    model = Rack
    field_order = [
        'q', 'region_id', 'site_id', 'location_id', 'status', 'role_id',
        'tenant_group_id', 'tenant_id'
    ]
    field_groups = [
        ['q', 'tag'],
        ['region_id', 'site_id', 'location_id'],
        ['status', 'role_id'],
        ['type', 'width', 'serial', 'asset_tag'],
        ['tenant_group_id', 'tenant_id'],
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label=_('Region'),
                                                fetch_trigger='open')
    site_id = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
        query_params={'region_id': '$region_id'},
        label=_('Site'),
        fetch_trigger='open')
    location_id = DynamicModelMultipleChoiceField(
        queryset=Location.objects.all(),
        required=False,
        null_option='None',
        query_params={'site_id': '$site_id'},
        label=_('Location'),
        fetch_trigger='open')
    status = forms.MultipleChoiceField(choices=RackStatusChoices,
                                       required=False,
                                       widget=StaticSelectMultiple())
    type = forms.MultipleChoiceField(choices=RackTypeChoices,
                                     required=False,
                                     widget=StaticSelectMultiple())
    width = forms.MultipleChoiceField(choices=RackWidthChoices,
                                      required=False,
                                      widget=StaticSelectMultiple())
    role_id = DynamicModelMultipleChoiceField(queryset=RackRole.objects.all(),
                                              required=False,
                                              null_option='None',
                                              label=_('Role'),
                                              fetch_trigger='open')
    serial = forms.CharField(required=False)
    asset_tag = forms.CharField(required=False)
    tag = TagFilterField(model)
Beispiel #9
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 = DynamicModelMultipleChoiceField(
        queryset=CircuitType.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/circuits/circuit-types/",
            value_field="slug",
        ))
    provider = DynamicModelMultipleChoiceField(
        queryset=Provider.objects.all(),
        to_field_name='slug',
        required=False,
        widget=APISelectMultiple(
            api_url="/api/circuits/providers/",
            value_field="slug",
        ))
    status = forms.MultipleChoiceField(choices=CircuitStatusChoices,
                                       required=False,
                                       widget=StaticSelect2Multiple())
    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'}))
    site = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                           to_field_name='slug',
                                           required=False,
                                           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)
Beispiel #10
0
class RouteTargetFilterForm(BootstrapMixin, TenancyFilterForm,
                            CustomFieldFilterForm):
    model = RouteTarget
    field_order = [
        'q', 'name', 'tenant_group', 'tenant', 'importing_vrfs',
        'exporting_vrfs'
    ]
    q = forms.CharField(required=False, label='Search')
    importing_vrf_id = DynamicModelMultipleChoiceField(
        queryset=VRF.objects.all(), required=False, label='Imported by VRF')
    exporting_vrf_id = DynamicModelMultipleChoiceField(
        queryset=VRF.objects.all(), required=False, label='Exported by VRF')
    tag = TagFilterField(model)
Beispiel #11
0
class VMInterfaceFilterForm(forms.Form):
    model = VMInterface
    cluster_id = DynamicModelMultipleChoiceField(
        queryset=Cluster.objects.all(), required=False, label='Cluster')
    virtual_machine_id = DynamicModelMultipleChoiceField(
        queryset=VirtualMachine.objects.all(),
        required=False,
        label='Virtual machine',
        query_params={'cluster_id': '$cluster_id'})
    enabled = forms.NullBooleanField(
        required=False,
        widget=StaticSelect2(choices=BOOLEAN_WITH_BLANK_CHOICES))
    tag = TagFilterField(model)
Beispiel #12
0
class CableFilterForm(BootstrapMixin, CustomFieldModelFilterForm):
    model = Cable
    field_groups = [
        ['q', 'tag'],
        ['site_id', 'rack_id', 'device_id'],
        ['type', 'status', 'color'],
        ['tenant_id'],
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label=_('Region'),
                                                fetch_trigger='open')
    site_id = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
        query_params={'region_id': '$region_id'},
        label=_('Site'),
        fetch_trigger='open')
    tenant_id = DynamicModelMultipleChoiceField(queryset=Tenant.objects.all(),
                                                required=False,
                                                label=_('Tenant'),
                                                fetch_trigger='open')
    rack_id = DynamicModelMultipleChoiceField(
        queryset=Rack.objects.all(),
        required=False,
        label=_('Rack'),
        null_option='None',
        query_params={'site_id': '$site_id'},
        fetch_trigger='open')
    type = forms.MultipleChoiceField(
        choices=add_blank_choice(CableTypeChoices),
        required=False,
        widget=StaticSelect())
    status = forms.ChoiceField(required=False,
                               choices=add_blank_choice(CableStatusChoices),
                               widget=StaticSelect())
    color = ColorField(required=False)
    device_id = DynamicModelMultipleChoiceField(queryset=Device.objects.all(),
                                                required=False,
                                                query_params={
                                                    'site_id': '$site_id',
                                                    'tenant_id': '$tenant_id',
                                                    'rack_id': '$rack_id',
                                                },
                                                label=_('Device'),
                                                fetch_trigger='open')
    tag = TagFilterField(model)
Beispiel #13
0
class VLANFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
    model = VLAN
    field_order = [
        'q', 'region_id', 'site_group_id', 'site_id', 'group_id', 'status', 'role_id', 'tenant_group_id', 'tenant_id',
    ]
    q = forms.CharField(
        required=False,
        label='Поиск'
    )
    region_id = DynamicModelMultipleChoiceField(
        queryset=Region.objects.all(),
        required=False,
        label=_('Region')
    )
    site_group_id = DynamicModelMultipleChoiceField(
        queryset=SiteGroup.objects.all(),
        required=False,
        label=_('Site group')
    )
    site_id = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
        null_option='None',
        query_params={
            'region': '$region'
        },
        label=_('Site')
    )
    group_id = DynamicModelMultipleChoiceField(
        queryset=VLANGroup.objects.all(),
        required=False,
        null_option='None',
        query_params={
            'region': '$region'
        },
        label=_('VLAN group')
    )
    status = forms.MultipleChoiceField(
        label='Статус',
        choices=VLANStatusChoices,
        required=False,
        widget=StaticSelect2Multiple()
    )
    role_id = DynamicModelMultipleChoiceField(
        queryset=Role.objects.all(),
        required=False,
        null_option='None',
        label=_('Role')
    )
    tag = TagFilterField(model)
Beispiel #14
0
class TenancyFilterForm(forms.Form):
    tenant_group_id = DynamicModelMultipleChoiceField(
        queryset=TenantGroup.objects.all(),
        required=False,
        null_option='None',
        label=_('Tenant group'),
        fetch_trigger='open')
    tenant_id = DynamicModelMultipleChoiceField(
        queryset=Tenant.objects.all(),
        required=False,
        null_option='None',
        query_params={'group_id': '$tenant_group_id'},
        label=_('Tenant'),
        fetch_trigger='open')
Beispiel #15
0
class ASNFilterForm(TenancyFilterForm, CustomFieldModelFilterForm):
    model = ASN
    field_groups = [
        ['q'],
        ['rir_id'],
        ['tenant_group_id', 'tenant_id'],
        ['site_id'],
    ]
    rir_id = DynamicModelMultipleChoiceField(queryset=RIR.objects.all(),
                                             required=False,
                                             label=_('RIR'))
    site_id = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                              required=False,
                                              label=_('Site'))
Beispiel #16
0
class InterfaceConnectionFilterForm(FilterForm):
    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'))
    device_id = DynamicModelMultipleChoiceField(
        queryset=Device.objects.all(),
        required=False,
        query_params={'site_id': '$site_id'},
        label=_('Device'))
Beispiel #17
0
class DeviceComponentFilterForm(BootstrapMixin, CustomFieldModelFilterForm):
    field_order = [
        'q',
        'name',
        'label',
        'region_id',
        'site_group_id',
        'site_id',
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    name = forms.CharField(required=False)
    label = forms.CharField(required=False)
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label=_('Region'),
                                                fetch_trigger='open')
    site_group_id = DynamicModelMultipleChoiceField(
        queryset=SiteGroup.objects.all(),
        required=False,
        label=_('Site group'),
        fetch_trigger='open')
    site_id = DynamicModelMultipleChoiceField(queryset=Site.objects.all(),
                                              required=False,
                                              query_params={
                                                  'region_id': '$region_id',
                                                  'group_id': '$site_group_id',
                                              },
                                              label=_('Site'),
                                              fetch_trigger='open')
    location_id = DynamicModelMultipleChoiceField(
        queryset=Location.objects.all(),
        required=False,
        query_params={
            'site_id': '$site_id',
        },
        label=_('Location'),
        fetch_trigger='open')
    device_id = DynamicModelMultipleChoiceField(queryset=Device.objects.all(),
                                                required=False,
                                                query_params={
                                                    'site_id': '$site_id',
                                                    'location_id':
                                                    '$location_id',
                                                },
                                                label=_('Device'),
                                                fetch_trigger='open')
Beispiel #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,
                                             ))
Beispiel #19
0
class VRFFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
    model = VRF
    field_order = [
        'q', 'import_target', 'export_target', 'tenant_group', 'tenant'
    ]
    q = forms.CharField(required=False, label='Search')
    import_target = DynamicModelMultipleChoiceField(
        queryset=RouteTarget.objects.all(),
        to_field_name='name',
        required=False)
    export_target = DynamicModelMultipleChoiceField(
        queryset=RouteTarget.objects.all(),
        to_field_name='name',
        required=False)
    tag = TagFilterField(model)
Beispiel #20
0
class VLANGroupFilterForm(BootstrapMixin, forms.Form):
    region = DynamicModelMultipleChoiceField(
        queryset=Region.objects.all(),
        to_field_name='slug',
        required=False
    )
    site = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        to_field_name='slug',
        required=False,
        null_option='None',
        query_params={
            'region': '$region'
        }
    )
Beispiel #21
0
class VMInterfaceCreateForm(BootstrapMixin, forms.Form):
    virtual_machine = DynamicModelChoiceField(
        queryset=VirtualMachine.objects.all())
    name_pattern = ExpandableNameField(label='Name')
    enabled = forms.BooleanField(required=False, initial=True)
    mtu = forms.IntegerField(required=False,
                             min_value=INTERFACE_MTU_MIN,
                             max_value=INTERFACE_MTU_MAX,
                             label='MTU')
    mac_address = forms.CharField(required=False, label='MAC Address')
    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,
                                            display_field='display_name',
                                            brief_mode=False,
                                            query_params={
                                                'site_id': 'null',
                                            })
    tagged_vlans = DynamicModelMultipleChoiceField(
        queryset=VLAN.objects.all(),
        required=False,
        display_field='display_name',
        brief_mode=False,
        query_params={
            'site_id': 'null',
        })
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

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

        virtual_machine = VirtualMachine.objects.get(
            pk=self.initial.get('virtual_machine')
            or self.data.get('virtual_machine'))

        # Add current site to VLANs query params
        site = virtual_machine.site
        if site:
            self.fields['untagged_vlan'].widget.add_query_param(
                'site_id', site.pk)
            self.fields['tagged_vlans'].widget.add_query_param(
                'site_id', site.pk)
Beispiel #22
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,
                                           ))
Beispiel #23
0
class VirtualChassisForm(CustomFieldModelForm):
    master = forms.ModelChoiceField(
        queryset=Device.objects.all(),
        required=False,
    )
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = VirtualChassis
        fields = [
            'name',
            'domain',
            'master',
            'tags',
        ]
        widgets = {
            'master': SelectWithPK(),
        }

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

        self.fields['master'].queryset = Device.objects.filter(
            virtual_chassis=self.instance)
Beispiel #24
0
class PowerPanelForm(CustomFieldModelForm):
    region = DynamicModelChoiceField(queryset=Region.objects.all(),
                                     required=False,
                                     initial_params={'sites': '$site'})
    site_group = DynamicModelChoiceField(queryset=SiteGroup.objects.all(),
                                         required=False,
                                         initial_params={'sites': '$site'})
    site = DynamicModelChoiceField(queryset=Site.objects.all(),
                                   query_params={
                                       'region_id': '$region',
                                       'group_id': '$site_group',
                                   })
    location = DynamicModelChoiceField(queryset=Location.objects.all(),
                                       required=False,
                                       query_params={'site_id': '$site'})
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = PowerPanel
        fields = [
            'region',
            'site_group',
            'site',
            'location',
            'name',
            'tags',
        ]
        fieldsets = (('Power Panel', ('region', 'site_group', 'site',
                                      'location', 'name', 'tags')), )
Beispiel #25
0
class CableForm(TenancyForm, CustomFieldModelForm):
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = Cable
        fields = [
            'type',
            'status',
            'tenant_group',
            'tenant',
            'label',
            'color',
            'length',
            'length_unit',
            'tags',
        ]
        widgets = {
            'status': StaticSelect,
            'type': StaticSelect,
            'length_unit': StaticSelect,
        }
        error_messages = {
            'length': {
                'max_value': 'Maximum length is 32767 (any unit)'
            }
        }
Beispiel #26
0
class FrontPortForm(CustomFieldModelForm):
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = FrontPort
        fields = [
            'device',
            'name',
            'label',
            'type',
            'color',
            'rear_port',
            'rear_port_position',
            'mark_connected',
            'description',
            'tags',
        ]
        widgets = {
            'device': forms.HiddenInput(),
            'type': StaticSelect(),
            'rear_port': StaticSelect(),
        }

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

        # Limit RearPort choices to the local device
        if hasattr(self.instance, 'device'):
            self.fields['rear_port'].queryset = self.fields[
                'rear_port'].queryset.filter(device=self.instance.device)
Beispiel #27
0
class PowerOutletForm(CustomFieldModelForm):
    power_port = forms.ModelChoiceField(queryset=PowerPort.objects.all(),
                                        required=False)
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = PowerOutlet
        fields = [
            'device',
            'name',
            'label',
            'type',
            'power_port',
            'feed_leg',
            'mark_connected',
            'description',
            'tags',
        ]
        widgets = {
            'device': forms.HiddenInput(),
        }

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

        # Limit power_port choices to the local device
        if hasattr(self.instance, 'device'):
            self.fields['power_port'].queryset = PowerPort.objects.filter(
                device=self.instance.device)
Beispiel #28
0
class IPAddressBulkAddForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
    vrf = DynamicModelChoiceField(queryset=VRF.objects.all(),
                                  required=False,
                                  label='VRF',
                                  display_field='display_name')
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = IPAddress
        fields = [
            'address',
            'vrf',
            'status',
            'role',
            'dns_name',
            'description',
            'tenant_group',
            'tenant',
            'tags',
        ]
        widgets = {
            'status': StaticSelect2(),
            'role': StaticSelect2(),
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['vrf'].empty_label = 'Global'
Beispiel #29
0
class ClusterForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
    type = DynamicModelChoiceField(
        queryset=ClusterType.objects.all()
    )
    group = DynamicModelChoiceField(
        queryset=ClusterGroup.objects.all(),
        required=False
    )
    region = DynamicModelChoiceField(
        queryset=Region.objects.all(),
        required=False,
        initial_params={
            'sites': '$site'
        }
    )
    site = DynamicModelChoiceField(
        queryset=Site.objects.all(),
        required=False,
        query_params={
            'region_id': '$region'
        }
    )
    comments = CommentField()
    tags = DynamicModelMultipleChoiceField(
        queryset=Tag.objects.all(),
        required=False
    )

    class Meta:
        model = Cluster
        fields = (
            'name', 'type', 'group', 'tenant', 'region', 'site', 'comments', 'tags',
        )
Beispiel #30
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)