Esempio n. 1
0
class VLANCSVForm(CustomFieldModelCSVForm):
    site = CSVModelChoiceField(queryset=Site.objects.all(),
                               required=False,
                               to_field_name='name',
                               help_text='Assigned site')
    group = CSVModelChoiceField(queryset=VLANGroup.objects.all(),
                                required=False,
                                to_field_name='name',
                                help_text='Assigned VLAN group')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 to_field_name='name',
                                 required=False,
                                 help_text='Assigned tenant')
    status = CSVChoiceField(choices=VLANStatusChoices,
                            help_text='Operational status')
    role = CSVModelChoiceField(queryset=Role.objects.all(),
                               required=False,
                               to_field_name='name',
                               help_text='Functional role')

    class Meta:
        model = VLAN
        fields = ('site', 'group', 'vid', 'name', 'tenant', 'status', 'role',
                  'description')
        help_texts = {
            'vid': 'Numeric VLAN ID (1-4095)',
            'name': 'VLAN name',
        }
Esempio n. 2
0
class VirtualMachineCSVForm(CustomFieldModelCSVForm):
    status = CSVChoiceField(choices=VirtualMachineStatusChoices,
                            help_text='Operational status of device')
    cluster = CSVModelChoiceField(queryset=Cluster.objects.all(),
                                  to_field_name='name',
                                  help_text='Assigned cluster')
    role = CSVModelChoiceField(
        queryset=DeviceRole.objects.filter(vm_role=True),
        required=False,
        to_field_name='name',
        help_text='Functional role')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')
    platform = CSVModelChoiceField(queryset=Platform.objects.all(),
                                   required=False,
                                   to_field_name='name',
                                   help_text='Assigned platform')

    class Meta:
        model = VirtualMachine
        fields = (
            'name',
            'status',
            'role',
            'cluster',
            'tenant',
            'platform',
            'vcpus',
            'memory',
            'disk',
            'comments',
        )
Esempio n. 3
0
class ClusterCSVForm(CustomFieldModelCSVForm):
    type = CSVModelChoiceField(
        queryset=ClusterType.objects.all(),
        to_field_name='name',
        help_text='Type of cluster'
    )
    group = CSVModelChoiceField(
        queryset=ClusterGroup.objects.all(),
        to_field_name='name',
        required=False,
        help_text='Assigned cluster group'
    )
    site = CSVModelChoiceField(
        queryset=Site.objects.all(),
        to_field_name='name',
        required=False,
        help_text='Assigned site'
    )
    tenant = CSVModelChoiceField(
        queryset=Tenant.objects.all(),
        to_field_name='name',
        required=False,
        help_text='Assigned tenant'
    )

    class Meta:
        model = Cluster
        fields = Cluster.csv_headers
Esempio n. 4
0
class DeviceCSVForm(BaseDeviceCSVForm):
    site = CSVModelChoiceField(queryset=Site.objects.all(),
                               to_field_name='name',
                               help_text='Assigned site')
    location = CSVModelChoiceField(queryset=Location.objects.all(),
                                   to_field_name='name',
                                   required=False,
                                   help_text="Assigned location (if any)")
    rack = CSVModelChoiceField(queryset=Rack.objects.all(),
                               to_field_name='name',
                               required=False,
                               help_text="Assigned rack (if any)")
    face = CSVChoiceField(choices=DeviceFaceChoices,
                          required=False,
                          help_text='Mounted rack face')

    class Meta(BaseDeviceCSVForm.Meta):
        fields = [
            'name',
            'device_role',
            'tenant',
            'manufacturer',
            'device_type',
            'platform',
            'serial',
            'asset_tag',
            'status',
            'site',
            'location',
            'rack',
            'position',
            'face',
            'virtual_chassis',
            'vc_position',
            'vc_priority',
            'cluster',
            'comments',
        ]

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

        if data:

            # Limit location queryset by assigned site
            params = {
                f"site__{self.fields['site'].to_field_name}": data.get('site')
            }
            self.fields['location'].queryset = self.fields[
                'location'].queryset.filter(**params)

            # Limit rack queryset by assigned site and group
            params = {
                f"site__{self.fields['site'].to_field_name}":
                data.get('site'),
                f"location__{self.fields['location'].to_field_name}":
                data.get('location'),
            }
            self.fields['rack'].queryset = self.fields['rack'].queryset.filter(
                **params)
Esempio n. 5
0
class SecretCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(
        queryset=Device.objects.all(),
        to_field_name='name',
        help_text='Assigned device'
    )
    role = CSVModelChoiceField(
        queryset=SecretRole.objects.all(),
        to_field_name='name',
        help_text='Assigned role'
    )
    plaintext = forms.CharField(
        help_text='Plaintext secret data'
    )

    class Meta:
        model = Secret
        fields = Secret.csv_headers
        help_texts = {
            'name': 'Name or username',
        }

    def save(self, *args, **kwargs):
        s = super().save(*args, **kwargs)
        s.plaintext = str(self.cleaned_data['plaintext'])
        return s
Esempio n. 6
0
class CircuitCSVForm(CustomFieldModelCSVForm):
    provider = CSVModelChoiceField(queryset=Provider.objects.all(),
                                   to_field_name='name',
                                   help_text='Assigned provider')
    type = CSVModelChoiceField(queryset=CircuitType.objects.all(),
                               to_field_name='name',
                               help_text='Type of circuit')
    status = CSVChoiceField(choices=CircuitStatusChoices,
                            required=False,
                            help_text='Operational status')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = Circuit
        fields = [
            'cid',
            'provider',
            'type',
            'status',
            'tenant',
            'install_date',
            'commit_rate',
            'description',
            'comments',
        ]
Esempio n. 7
0
class IPRangeCSVForm(CustomFieldModelCSVForm):
    vrf = CSVModelChoiceField(queryset=VRF.objects.all(),
                              to_field_name='name',
                              required=False,
                              help_text='Assigned VRF')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')
    status = CSVChoiceField(choices=IPRangeStatusChoices,
                            help_text='Operational status')
    role = CSVModelChoiceField(queryset=Role.objects.all(),
                               required=False,
                               to_field_name='name',
                               help_text='Functional role')

    class Meta:
        model = IPRange
        fields = (
            'start_address',
            'end_address',
            'vrf',
            'tenant',
            'status',
            'role',
            'description',
        )
Esempio n. 8
0
class VMInterfaceCSVForm(CustomFieldModelCSVForm):
    virtual_machine = CSVModelChoiceField(
        queryset=VirtualMachine.objects.all(),
        to_field_name='name'
    )
    parent = CSVModelChoiceField(
        queryset=VMInterface.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Parent interface'
    )
    bridge = CSVModelChoiceField(
        queryset=VMInterface.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Bridged interface'
    )
    mode = CSVChoiceField(
        choices=InterfaceModeChoices,
        required=False,
        help_text='IEEE 802.1Q operational mode (for L2 interfaces)'
    )

    class Meta:
        model = VMInterface
        fields = (
            'virtual_machine', 'name', 'parent', 'bridge', 'enabled', 'mac_address', 'mtu', 'description', 'mode',
        )

    def clean_enabled(self):
        # Make sure enabled is True when it's not included in the uploaded data
        if 'enabled' not in self.data:
            return True
        else:
            return self.cleaned_data['enabled']
Esempio n. 9
0
class RackCSVForm(CustomFieldModelCSVForm):
    site = CSVModelChoiceField(queryset=Site.objects.all(),
                               to_field_name='name')
    location = CSVModelChoiceField(queryset=Location.objects.all(),
                                   required=False,
                                   to_field_name='name')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Name of assigned tenant')
    status = CSVChoiceField(choices=RackStatusChoices,
                            help_text='Operational status')
    role = CSVModelChoiceField(queryset=RackRole.objects.all(),
                               required=False,
                               to_field_name='name',
                               help_text='Name of assigned role')
    type = CSVChoiceField(choices=RackTypeChoices,
                          required=False,
                          help_text='Rack type')
    width = forms.ChoiceField(choices=RackWidthChoices,
                              help_text='Rail-to-rail width (in inches)')
    outer_unit = CSVChoiceField(choices=RackDimensionUnitChoices,
                                required=False,
                                help_text='Unit for outer dimensions')

    class Meta:
        model = Rack
        fields = (
            'site',
            'location',
            'name',
            'facility_id',
            'tenant',
            'status',
            'role',
            'type',
            'serial',
            'asset_tag',
            'width',
            'u_height',
            'desc_units',
            'outer_width',
            'outer_depth',
            'outer_unit',
            'comments',
        )

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

        if data:

            # Limit location queryset by assigned site
            params = {
                f"site__{self.fields['site'].to_field_name}": data.get('site')
            }
            self.fields['location'].queryset = self.fields[
                'location'].queryset.filter(**params)
Esempio n. 10
0
class ChildDeviceCSVForm(BaseDeviceCSVForm):
    parent = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name',
                                 help_text='Parent device')
    device_bay = CSVModelChoiceField(
        queryset=DeviceBay.objects.all(),
        to_field_name='name',
        help_text='Device bay in which this device is installed')

    class Meta(BaseDeviceCSVForm.Meta):
        fields = [
            'name',
            'device_role',
            'tenant',
            'manufacturer',
            'device_type',
            'platform',
            'serial',
            'asset_tag',
            'status',
            'parent',
            'device_bay',
            'virtual_chassis',
            'vc_position',
            'vc_priority',
            'cluster',
            'comments',
        ]

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

        if data:

            # Limit device bay queryset by parent device
            params = {
                f"device__{self.fields['parent'].to_field_name}":
                data.get('parent')
            }
            self.fields['device_bay'].queryset = self.fields[
                'device_bay'].queryset.filter(**params)

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

        # Set parent_bay reverse relationship
        device_bay = self.cleaned_data.get('device_bay')
        if device_bay:
            self.instance.parent_bay = device_bay

        # Inherit site and rack from parent device
        parent = self.cleaned_data.get('parent')
        if parent:
            self.instance.site = parent.site
            self.instance.rack = parent.rack
Esempio n. 11
0
class AggregateCSVForm(CustomFieldModelCSVForm):
    rir = CSVModelChoiceField(queryset=RIR.objects.all(),
                              to_field_name='name',
                              help_text='Assigned RIR')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = Aggregate
        fields = ('prefix', 'rir', 'tenant', 'date_added', 'description')
Esempio n. 12
0
class AggregateCSVForm(CustomFieldModelCSVForm):
    rir = CSVModelChoiceField(queryset=RIR.objects.all(),
                              to_field_name='name',
                              help_text='Assigned RIR')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = Aggregate
        fields = Aggregate.csv_headers
Esempio n. 13
0
class ASNCSVForm(CustomFieldModelCSVForm):
    rir = CSVModelChoiceField(queryset=RIR.objects.all(),
                              to_field_name='name',
                              help_text='Assigned RIR')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = ASN
        fields = ('asn', 'rir', 'tenant', 'description')
        help_texts = {}
Esempio n. 14
0
class SecretCSVForm(CustomFieldModelCSVForm):
    role = CSVModelChoiceField(queryset=SecretRole.objects.all(),
                               to_field_name='name',
                               help_text='Assigned role')
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned device')
    virtual_machine = CSVModelChoiceField(
        queryset=VirtualMachine.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Assigned VM')
    plaintext = forms.CharField(help_text='Plaintext secret data')

    class Meta:
        model = Secret
        fields = ['role', 'name', 'plaintext', 'device', 'virtual_machine']
        help_texts = {
            'name': 'Name or username',
        }

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

        device = self.cleaned_data.get('device')
        virtual_machine = self.cleaned_data.get('virtual_machine')

        # Validate device OR VM is assigned
        if not device and not virtual_machine:
            raise forms.ValidationError(
                "Secret must be assigned to a device or a virtual machine")
        if device and virtual_machine:
            raise forms.ValidationError(
                "Secret cannot be assigned to both a device and a virtual machine"
            )

    def save(self, *args, **kwargs):

        # Set device/VM assignment
        self.instance.assigned_object = self.cleaned_data[
            'device'] or self.cleaned_data['virtual_machine']

        s = super().save(*args, **kwargs)

        # Set plaintext on instance
        s.plaintext = str(self.cleaned_data['plaintext'])

        return s
Esempio n. 15
0
class LocationCSVForm(CustomFieldModelCSVForm):
    site = CSVModelChoiceField(queryset=Site.objects.all(),
                               to_field_name='name',
                               help_text='Assigned site')
    parent = CSVModelChoiceField(queryset=Location.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Parent location',
                                 error_messages={
                                     'invalid_choice': 'Location not found.',
                                 })

    class Meta:
        model = Location
        fields = ('site', 'parent', 'name', 'slug', 'description')
Esempio n. 16
0
class DomainServCSVForm(CSVModelForm):
    service = CSVModelChoiceField(
        queryset=Service.objects.all(),
        required=False,
        to_field_name='Serviço',
        help_text="Serviço do modulo ipam")

    dominio = CSVModelChoiceField(
        queryset=Domain.objects.all(),
        required=False,
        to_field_name='name',
        help_text="Dominio Dns")

    class Meta:
        model = DomainServ
        fields = DomainServ.csv_headers
Esempio n. 17
0
class MxCSVForm(CSVModelForm):
    mx = CSVModelChoiceField(
        queryset=IPAddress.objects.all(),
        required=False,
        to_field_name='IP',
        help_text="Registro A/AAAA)")

    dom = CSVModelChoiceField(
        queryset=Domain.objects.all(),
        required=False,
        to_field_name='name',
        help_text="Dominio Dns)")

    class Meta:
        model = Mx
        fields = Mx.csv_headers
Esempio n. 18
0
class WirelessLinkCSVForm(CustomFieldModelCSVForm):
    status = CSVChoiceField(choices=LinkStatusChoices,
                            help_text='Connection status')
    interface_a = CSVModelChoiceField(queryset=Interface.objects.all())
    interface_b = CSVModelChoiceField(queryset=Interface.objects.all())
    auth_type = CSVChoiceField(choices=WirelessAuthTypeChoices,
                               required=False,
                               help_text='Authentication type')
    auth_cipher = CSVChoiceField(choices=WirelessAuthCipherChoices,
                                 required=False,
                                 help_text='Authentication cipher')

    class Meta:
        model = WirelessLink
        fields = ('interface_a', 'interface_b', 'ssid', 'description',
                  'auth_type', 'auth_cipher', 'auth_psk')
Esempio n. 19
0
class ServiceCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Required if not assigned to a VM')
    virtual_machine = CSVModelChoiceField(
        queryset=VirtualMachine.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Required if not assigned to a device')
    protocol = CSVChoiceField(choices=ServiceProtocolChoices,
                              help_text='IP protocol')

    class Meta:
        model = Service
        fields = Service.csv_headers
Esempio n. 20
0
class VLANCSVForm(CustomFieldModelCSVForm):
    site = CSVModelChoiceField(
        queryset=Site.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Assigned site'
    )
    group = CSVModelChoiceField(
        queryset=VLANGroup.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Assigned VLAN group'
    )
    tenant = CSVModelChoiceField(
        queryset=Tenant.objects.all(),
        to_field_name='name',
        required=False,
        help_text='Assigned tenant'
    )
    status = CSVChoiceField(
        choices=VLANStatusChoices,
        help_text='Operational status'
    )
    role = CSVModelChoiceField(
        queryset=Role.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Functional role'
    )

    class Meta:
        model = VLAN
        fields = VLAN.csv_headers
        help_texts = {
            'vid': 'Numeric VLAN ID (1-4095)',
            'name': 'VLAN name',
        }

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

        if data:

            # Limit vlan queryset by assigned group
            params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
            self.fields['group'].queryset = self.fields['group'].queryset.filter(**params)
Esempio n. 21
0
class FrontPortCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name')
    rear_port = CSVModelChoiceField(queryset=RearPort.objects.all(),
                                    to_field_name='name',
                                    help_text='Corresponding rear port')
    type = CSVChoiceField(choices=PortTypeChoices,
                          help_text='Physical medium classification')

    class Meta:
        model = FrontPort
        fields = (
            'device',
            'name',
            'label',
            'type',
            'color',
            'mark_connected',
            'rear_port',
            'rear_port_position',
            'description',
        )
        help_texts = {
            'rear_port_position': 'Mapped position on corresponding rear port',
        }

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

        # Limit RearPort choices to those belonging to this device (or VC master)
        if self.is_bound:
            try:
                device = self.fields['device'].to_python(self.data['device'])
            except forms.ValidationError:
                device = None
        else:
            try:
                device = self.instance.device
            except Device.DoesNotExist:
                device = None

        if device:
            self.fields['rear_port'].queryset = RearPort.objects.filter(
                device__in=[device, device.get_vc_master()])
        else:
            self.fields['rear_port'].queryset = RearPort.objects.none()
Esempio n. 22
0
class RackReservationCSVForm(CustomFieldModelCSVForm):
    site = CSVModelChoiceField(queryset=Site.objects.all(),
                               to_field_name='name',
                               help_text='Parent site')
    location = CSVModelChoiceField(queryset=Location.objects.all(),
                                   to_field_name='name',
                                   required=False,
                                   help_text="Rack's location (if any)")
    rack = CSVModelChoiceField(queryset=Rack.objects.all(),
                               to_field_name='name',
                               help_text='Rack')
    units = SimpleArrayField(
        base_field=forms.IntegerField(),
        required=True,
        help_text='Comma-separated list of individual unit numbers')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = RackReservation
        fields = ('site', 'location', 'rack', 'units', 'tenant', 'description')

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

        if data:

            # Limit location queryset by assigned site
            params = {
                f"site__{self.fields['site'].to_field_name}": data.get('site')
            }
            self.fields['location'].queryset = self.fields[
                'location'].queryset.filter(**params)

            # Limit rack queryset by assigned site and group
            params = {
                f"site__{self.fields['site'].to_field_name}":
                data.get('site'),
                f"location__{self.fields['location'].to_field_name}":
                data.get('location'),
            }
            self.fields['rack'].queryset = self.fields['rack'].queryset.filter(
                **params)
Esempio n. 23
0
class RegionCSVForm(CustomFieldModelCSVForm):
    parent = CSVModelChoiceField(queryset=Region.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Name of parent region')

    class Meta:
        model = Region
        fields = ('name', 'slug', 'parent', 'description')
Esempio n. 24
0
class SiteGroupCSVForm(CustomFieldModelCSVForm):
    parent = CSVModelChoiceField(queryset=SiteGroup.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Name of parent site group')

    class Meta:
        model = SiteGroup
        fields = ('name', 'slug', 'parent', 'description')
Esempio n. 25
0
class VRFCSVForm(CustomFieldModelCSVForm):
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = VRF
        fields = ('name', 'rd', 'tenant', 'enforce_unique', 'description')
Esempio n. 26
0
class RouteTargetCSVForm(CustomFieldModelCSVForm):
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = RouteTarget
        fields = ('name', 'description', 'tenant')
Esempio n. 27
0
class VirtualChassisCSVForm(CustomFieldModelCSVForm):
    master = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name',
                                 required=False,
                                 help_text='Master device')

    class Meta:
        model = VirtualChassis
        fields = ('name', 'domain', 'master')
Esempio n. 28
0
class VRFCSVForm(CustomFieldModelCSVForm):
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = VRF
        fields = VRF.csv_headers
Esempio n. 29
0
class SiteCSVForm(CustomFieldModelCSVForm):
    status = CSVChoiceField(choices=SiteStatusChoices,
                            help_text='Operational status')
    region = CSVModelChoiceField(queryset=Region.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned region')
    group = CSVModelChoiceField(queryset=SiteGroup.objects.all(),
                                required=False,
                                to_field_name='name',
                                help_text='Assigned group')
    tenant = CSVModelChoiceField(queryset=Tenant.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Assigned tenant')

    class Meta:
        model = Site
        fields = (
            'name',
            'slug',
            'status',
            'region',
            'group',
            'tenant',
            'facility',
            'asn',
            'time_zone',
            'description',
            'physical_address',
            'shipping_address',
            'latitude',
            'longitude',
            'contact_name',
            'contact_phone',
            'contact_email',
            'comments',
        )
        help_texts = {
            'time_zone':
            mark_safe(
                'Time zone (<a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">available options</a>)'
            )
        }
Esempio n. 30
0
class VLANGroupCSVForm(CSVModelForm):
    site = CSVModelChoiceField(queryset=Site.objects.all(),
                               required=False,
                               to_field_name='name',
                               help_text='Assigned site')
    slug = SlugField()

    class Meta:
        model = VLANGroup
        fields = VLANGroup.csv_headers