コード例 #1
0
class ConnectionBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
    pk = DynamicModelMultipleChoiceField(
        queryset=Connection.objects.all(), widget=forms.MultipleHiddenInput
    )
    state = forms.ChoiceField(
        required=False,
        choices=add_blank_choice(ConnectionState.choices),
        widget=StaticSelect,
    )
    internet_exchange_point = DynamicModelChoiceField(
        required=False,
        queryset=InternetExchange.objects.all(),
        help_text="IXP to which this connection connects",
    )
    router = DynamicModelChoiceField(
        required=False,
        queryset=Router.objects.all(),
        help_text="Router on which this connection is setup",
    )
    config_context = JSONField(
        required=False, label="Config context", widget=SmallTextarea
    )

    class Meta:
        model = Connection
        fields = ("state", "internet_exchange_point", "router", "config_context")
        nullable_fields = ("router",)
コード例 #2
0
class RoutingPolicyForm(BootstrapMixin, forms.ModelForm):
    slug = SlugField(max_length=255)
    type = forms.ChoiceField(choices=RoutingPolicyType.choices,
                             widget=StaticSelect)
    address_family = forms.ChoiceField(choices=IPFamily.choices,
                                       widget=StaticSelect)
    config_context = JSONField(required=False,
                               label="Config context",
                               widget=SmallTextarea)
    comments = CommentField()
    tags = TagField(required=False)

    class Meta:
        model = RoutingPolicy

        fields = (
            "name",
            "slug",
            "type",
            "weight",
            "address_family",
            "config_context",
            "comments",
            "tags",
        )
コード例 #3
0
class PlatformForm(BootstrapMixin, forms.ModelForm):
    slug = SlugField(max_length=255)
    napalm_args = JSONField(
        required=False,
        label="Optional arguments",
        help_text=
        "See NAPALM's <a href='http://napalm.readthedocs.io/en/latest/support/#optional-arguments'>documentation</a> for a complete list of optional arguments",
        widget=SmallTextarea,
    )
    password_algorithm = forms.ChoiceField(
        required=False,
        choices=add_blank_choice(PasswordAlgorithm.choices),
        widget=StaticSelect,
    )

    class Meta:
        model = Platform
        fields = [
            "name",
            "slug",
            "napalm_driver",
            "napalm_args",
            "password_algorithm",
            "description",
        ]
コード例 #4
0
class ConnectionForm(BootstrapMixin, forms.ModelForm):
    state = forms.ChoiceField(choices=ConnectionState.choices, widget=StaticSelect)
    internet_exchange_point = DynamicModelChoiceField(
        required=False,
        queryset=InternetExchange.objects.all(),
        help_text="IXP to which this connection connects",
    )
    router = DynamicModelChoiceField(
        required=False,
        queryset=Router.objects.all(),
        help_text="Router on which this connection is setup",
    )
    config_context = JSONField(
        required=False, label="Config context", widget=SmallTextarea
    )
    comments = CommentField()
    tags = TagField(required=False)

    class Meta:
        model = Connection
        fields = (
            "state",
            "vlan",
            "ipv6_address",
            "ipv4_address",
            "internet_exchange_point",
            "router",
            "interface",
            "description",
            "config_context",
            "comments",
            "tags",
        )
        labels = {
            "vlan": "VLAN",
            "ipv6_address": "IPv6 address",
            "ipv4_address": "IPv4 address",
        }
コード例 #5
0
class RouterForm(BootstrapMixin, forms.ModelForm):
    netbox_device_id = forms.IntegerField(label="NetBox device", initial=0)
    platform = DynamicModelChoiceField(required=False,
                                       queryset=Platform.objects.all())
    configuration_template = DynamicModelChoiceField(
        required=False,
        queryset=Configuration.objects.all(),
        label="Configuration",
        help_text="Template used to generate device configuration",
    )
    local_autonomous_system = DynamicModelChoiceField(
        queryset=AutonomousSystem.objects.defer("prefixes"),
        query_params={"affiliated": True},
    )
    config_context = JSONField(required=False,
                               label="Config context",
                               widget=SmallTextarea)
    napalm_username = forms.CharField(required=False, label="Username")
    napalm_password = PasswordField(required=False,
                                    render_value=True,
                                    label="Password")
    napalm_timeout = forms.IntegerField(
        required=False,
        label="Timeout",
        help_text="The maximum time to wait for a connection in seconds",
    )
    napalm_args = JSONField(
        required=False,
        label="Optional arguments",
        help_text=
        "See NAPALM's <a href='http://napalm.readthedocs.io/en/latest/support/#optional-arguments'>documentation</a> for a complete list of optional arguments",
        widget=SmallTextarea,
    )
    device_state = forms.ChoiceField(
        required=False,
        choices=add_blank_choice(DeviceState.choices),
        widget=StaticSelect,
    )
    comments = CommentField()
    tags = TagField(required=False)

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

        if settings.NETBOX_API:
            choices = []
            for device in NetBox().get_devices():
                try:
                    choices.append((device.id, device.display))
                except AttributeError:
                    # Fallback to hold API attribute
                    choices.append((device.id, device.display_name))

            self.fields["netbox_device_id"] = forms.ChoiceField(
                label="NetBox device",
                choices=[(0, "---------")] + choices,
                widget=StaticSelect,
            )
            self.fields["netbox_device_id"].widget.attrs["class"] = " ".join([
                self.fields["netbox_device_id"].widget.attrs.get("class", ""),
                "form-control",
            ]).strip()
        else:
            self.fields["netbox_device_id"].widget = forms.HiddenInput()

    class Meta:
        model = Router

        fields = (
            "netbox_device_id",
            "use_netbox",
            "name",
            "hostname",
            "platform",
            "encrypt_passwords",
            "device_state",
            "configuration_template",
            "local_autonomous_system",
            "config_context",
            "napalm_username",
            "napalm_password",
            "napalm_timeout",
            "napalm_args",
            "comments",
            "tags",
        )
        help_texts = {
            "hostname": "Router hostname (must be resolvable) or IP address"
        }