Example #1
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>)'
            )
        }
Example #2
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
Example #3
0
class WirelessLANGroupCSVForm(CustomFieldModelCSVForm):
    parent = CSVModelChoiceField(queryset=WirelessLANGroup.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Parent group')
    slug = SlugField()

    class Meta:
        model = WirelessLANGroup
        fields = ('name', 'slug', 'parent', 'description')
Example #4
0
class ContactCSVForm(CustomFieldModelCSVForm):
    group = CSVModelChoiceField(queryset=ContactGroup.objects.all(),
                                required=False,
                                to_field_name='name',
                                help_text='Assigned group')

    class Meta:
        model = Contact
        fields = ('name', 'title', 'phone', 'email', 'address', 'group',
                  'comments')
Example #5
0
class TenantCSVForm(CustomFieldModelCSVForm):
    slug = SlugField()
    group = CSVModelChoiceField(queryset=TenantGroup.objects.all(),
                                required=False,
                                to_field_name='name',
                                help_text='Assigned group')

    class Meta:
        model = Tenant
        fields = ('name', 'slug', 'group', 'description', 'comments')
Example #6
0
class TenantGroupCSVForm(CSVModelForm):
    parent = CSVModelChoiceField(queryset=TenantGroup.objects.all(),
                                 required=False,
                                 to_field_name='name',
                                 help_text='Parent group')
    slug = SlugField()

    class Meta:
        model = TenantGroup
        fields = TenantGroup.csv_headers
Example #7
0
class TenantCSVForm(CustomFieldModelCSVForm):
    slug = SlugField()
    group = CSVModelChoiceField(queryset=TenantGroup.objects.all(),
                                required=False,
                                to_field_name='name',
                                help_text='Assigned group')

    class Meta:
        model = Tenant
        fields = Tenant.csv_headers
Example #8
0
class CtsCSVForm(CSVModelForm):
    registro = CSVModelChoiceField(
        queryset=IPAddress.objects.all(),
        required=False,
        to_field_name='IP',
        help_text="Registro A/AAAA")

    class Meta:
        model = Cts
        fields = Cts.csv_headers
Example #9
0
class AggregateCSVForm(CustomFieldModelCSVForm):
    rir = CSVModelChoiceField(
        queryset=RIR.objects.all(),
        to_field_name='name',
        help_text='Assigned RIR'
    )

    class Meta:
        model = Aggregate
        fields = Aggregate.csv_headers
Example #10
0
class VLANCSVForm(CustomFieldModelCSVForm):
    site = CSVModelChoiceField(
        label='Адрес',
        queryset=Site.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Assigned site'
    )
    group = CSVModelChoiceField(
        label='Группа',
        queryset=VLANGroup.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Assigned VLAN group'
    )
    tenant = CSVModelChoiceField(
        label='Учреждение',
        queryset=Tenant.objects.all(),
        to_field_name='name',
        required=False,
        help_text='Assigned tenant'
    )
    status = CSVChoiceField(
        label='Статус',
        choices=VLANStatusChoices,
        help_text='Operational status'
    )
    role = CSVModelChoiceField(
        label='Роль',
        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',
        }
Example #11
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 = ('name', 'type', 'group', 'site', 'comments')
Example #12
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
Example #13
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
Example #14
0
class WirelessLANCSVForm(CustomFieldModelCSVForm):
    group = CSVModelChoiceField(queryset=WirelessLANGroup.objects.all(),
                                required=False,
                                to_field_name='name',
                                help_text='Assigned group')
    vlan = CSVModelChoiceField(queryset=VLAN.objects.all(),
                               required=False,
                               to_field_name='name',
                               help_text='Bridged VLAN')
    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 = WirelessLAN
        fields = ('ssid', 'group', 'description', 'vlan', 'auth_type',
                  'auth_cipher', 'auth_psk')
Example #15
0
class RespCSVForm(CSVModelForm):
    dom = CSVModelChoiceField(
        queryset=Domain.objects.all(),
        required=False,
        to_field_name='name',
        help_text="Dominio Dns)"
    )

    class Meta:
        model = Resp
        fields = Resp.csv_headers
Example #16
0
class DeviceBayCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name')
    installed_device = CSVModelChoiceField(
        queryset=Device.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Child device installed within this bay',
        error_messages={
            'invalid_choice': 'Child device not found.',
        })

    class Meta:
        model = DeviceBay
        fields = ('device', 'name', 'label', 'installed_device', 'description')

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

        # Limit installed device choices to devices of the correct type and location
        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['installed_device'].queryset = Device.objects.filter(
                site=device.site,
                rack=device.rack,
                parent_bay__isnull=True,
                device_type__u_height=0,
                device_type__subdevice_role=SubdeviceRoleChoices.ROLE_CHILD
            ).exclude(pk=device.pk)
        else:
            self.fields['installed_device'].queryset = Interface.objects.none()
Example #17
0
class PowerOutletCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name')
    type = CSVChoiceField(choices=PowerOutletTypeChoices,
                          required=False,
                          help_text='Outlet type')
    power_port = CSVModelChoiceField(
        queryset=PowerPort.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Local power port which feeds this outlet')
    feed_leg = CSVChoiceField(
        choices=PowerOutletFeedLegChoices,
        required=False,
        help_text='Electrical phase (for three-phase circuits)')

    class Meta:
        model = PowerOutlet
        fields = ('device', 'name', 'label', 'type', 'mark_connected',
                  'power_port', 'feed_leg', 'description')

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

        # Limit PowerPort 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['power_port'].queryset = PowerPort.objects.filter(
                device__in=[device, device.get_vc_master()])
        else:
            self.fields['power_port'].queryset = PowerPort.objects.none()
Example #18
0
class PlatformCSVForm(CustomFieldModelCSVForm):
    slug = SlugField()
    manufacturer = CSVModelChoiceField(
        queryset=Manufacturer.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Limit platform assignments to this manufacturer')

    class Meta:
        model = Platform
        fields = ('name', 'slug', 'manufacturer', 'napalm_driver',
                  'napalm_args', 'description')
Example #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
Example #20
0
class RouteTargetCSVForm(CustomFieldModelCSVForm):
    tenant = CSVModelChoiceField(
        label='Учреждение',
        queryset=Tenant.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Assigned tenant'
    )

    class Meta:
        model = RouteTarget
        fields = RouteTarget.csv_headers
Example #21
0
class ProviderNetworkCSVForm(CustomFieldModelCSVForm):
    provider = CSVModelChoiceField(
        queryset=Provider.objects.all(),
        to_field_name='name',
        help_text='Assigned provider'
    )

    class Meta:
        model = ProviderNetwork
        fields = [
            'provider', 'name', 'description', 'comments',
        ]
Example #22
0
class InventoryItemCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name')
    manufacturer = CSVModelChoiceField(queryset=Manufacturer.objects.all(),
                                       to_field_name='name',
                                       required=False)
    parent = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name',
                                 required=False,
                                 help_text='Parent inventory item')

    class Meta:
        model = InventoryItem
        fields = (
            'device',
            'name',
            'label',
            'manufacturer',
            'part_id',
            'serial',
            'asset_tag',
            'discovered',
            'description',
        )

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

        # Limit parent choices to inventory items belonging to this device
        device = None
        if self.is_bound and 'device' in self.data:
            try:
                device = self.fields['device'].to_python(self.data['device'])
            except forms.ValidationError:
                pass
        if device:
            self.fields['parent'].queryset = InventoryItem.objects.filter(
                device=device)
        else:
            self.fields['parent'].queryset = InventoryItem.objects.none()
Example #23
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)
Example #24
0
class RearPortCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name')
    type = CSVChoiceField(
        help_text='Physical medium classification',
        choices=PortTypeChoices,
    )

    class Meta:
        model = RearPort
        fields = ('device', 'name', 'label', 'type', 'color', 'mark_connected',
                  'positions', 'description')
        help_texts = {'positions': 'Number of front ports which may be mapped'}
Example #25
0
class PrefixCSVForm(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'
    )
    site = CSVModelChoiceField(
        queryset=Site.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Assigned site'
    )
    vlan_group = CSVModelChoiceField(
        queryset=VLANGroup.objects.all(),
        required=False,
        to_field_name='name',
        help_text="VLAN's group (if any)"
    )
    vlan = CSVModelChoiceField(
        queryset=VLAN.objects.all(),
        required=False,
        to_field_name='vid',
        help_text="Assigned VLAN"
    )
    status = CSVChoiceField(
        choices=PrefixStatusChoices,
        help_text='Operational status'
    )
    role = CSVModelChoiceField(
        queryset=Role.objects.all(),
        required=False,
        to_field_name='name',
        help_text='Functional role'
    )

    class Meta:
        model = Prefix
        fields = Prefix.csv_headers

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

        if data:

            # Limit VLAN queryset by assigned site and/or group (if specified)
            params = {}
            if data.get('site'):
                params[f"site__{self.fields['site'].to_field_name}"] = data.get('site')
            if data.get('vlan_group'):
                params[f"group__{self.fields['vlan_group'].to_field_name}"] = data.get('vlan_group')
            if params:
                self.fields['vlan'].queryset = self.fields['vlan'].queryset.filter(**params)
Example #26
0
class PowerPanelCSVForm(CustomFieldModelCSVForm):
    site = CSVModelChoiceField(queryset=Site.objects.all(),
                               to_field_name='name',
                               help_text='Name of parent site')
    location = CSVModelChoiceField(queryset=Location.objects.all(),
                                   required=False,
                                   to_field_name='name')

    class Meta:
        model = PowerPanel
        fields = ('site', 'location', 'name')

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

        if data:

            # Limit group 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)
Example #27
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']
Example #28
0
class VirtualMachineCSVForm(CustomFieldModelCSVForm):
    status = CSVChoiceField(
        choices=VirtualMachineStatusChoices,
        help_text='Operational status'
    )
    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',
        )
Example #29
0
class VirtualMachineCSVForm(CustomFieldModelCSVForm):
    status = CSVChoiceField(choices=VirtualMachineStatusChoices,
                            required=False,
                            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 = VirtualMachine.csv_headers
Example #30
0
class ConsoleServerPortCSVForm(CustomFieldModelCSVForm):
    device = CSVModelChoiceField(queryset=Device.objects.all(),
                                 to_field_name='name')
    type = CSVChoiceField(choices=ConsolePortTypeChoices,
                          required=False,
                          help_text='Port type')
    speed = CSVTypedChoiceField(choices=ConsolePortSpeedChoices,
                                coerce=int,
                                empty_value=None,
                                required=False,
                                help_text='Port speed in bps')

    class Meta:
        model = ConsoleServerPort
        fields = ('device', 'name', 'label', 'type', 'speed', 'mark_connected',
                  'description')