class InternetExchangeFilterForm(BootstrapMixin, forms.Form): model = InternetExchange q = forms.CharField(required=False, label="Search") import_routing_policies = FilterChoiceField( queryset=RoutingPolicy.objects.all(), to_field_name="pk", null_label=True, widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, null_option=True, ), ) export_routing_policies = FilterChoiceField( queryset=RoutingPolicy.objects.all(), to_field_name="pk", null_label=True, widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, null_option=True, ), ) router = FilterChoiceField( queryset=Router.objects.all(), to_field_name="pk", null_label=True, widget=APISelectMultiple(api_url="/api/peering/routers/", null_option=True), )
class DirectPeeringSessionBulkEditForm(BootstrapMixin, BulkEditForm): pk = FilterChoiceField( queryset=DirectPeeringSession.objects.all(), widget=forms.MultipleHiddenInput ) enabled = forms.NullBooleanField( required=False, label="Enable", widget=CustomNullBooleanSelect ) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) router = forms.ModelChoiceField( required=False, queryset=Router.objects.all(), widget=APISelect(api_url="/api/peering/routers/"), ) comment = CommentField() class Meta: nullable_fields = ["router", "comment"]
class InternetExchangePeeringSessionFilterForm(BootstrapMixin, forms.Form): model = InternetExchangePeeringSession q = forms.CharField(required=False, label="Search") autonomous_system__id = FilterChoiceField( queryset=AutonomousSystem.objects.all(), to_field_name="pk", label="Autonomous System", null_label=True, widget=APISelectMultiple(api_url="/api/peering/autonomous-systems/"), ) internet_exchange__id = FilterChoiceField( queryset=InternetExchange.objects.all(), to_field_name="pk", label="Internet Exchange", null_label=True, widget=APISelectMultiple(api_url="/api/peering/internet-exchanges/"), ) address_family = forms.ChoiceField(required=False, choices=IP_FAMILY_CHOICES, widget=StaticSelect) is_route_server = forms.NullBooleanField(required=False, label="Route Server", widget=CustomNullBooleanSelect) enabled = forms.NullBooleanField(required=False, label="Enabled", widget=CustomNullBooleanSelect)
class DirectPeeringSessionFilterForm(BootstrapMixin, forms.Form): model = DirectPeeringSession q = forms.CharField(required=False, label="Search") local_asn = forms.IntegerField(required=False, label="Local ASN") bgp_group = FilterChoiceField( queryset=BGPGroup.objects.all(), to_field_name="pk", null_label=True, label="BGP Group", widget=APISelectMultiple(api_url="/api/peering/bgp-groups/", null_option=True), ) address_family = forms.ChoiceField(required=False, choices=IP_FAMILY_CHOICES, widget=StaticSelect) enabled = forms.NullBooleanField(required=False, label="Enabled", widget=CustomNullBooleanSelect) relationship = forms.MultipleChoiceField(required=False, choices=BGP_RELATIONSHIP_CHOICES, widget=StaticSelectMultiple) router = FilterChoiceField( queryset=Router.objects.all(), to_field_name="pk", null_label=True, widget=APISelectMultiple(api_url="/api/peering/routers/", null_option=True), )
class BGPGroupBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm): pk = FilterChoiceField(queryset=BGPGroup.objects.all(), widget=forms.MultipleHiddenInput) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) communities = FilterChoiceField( required=False, queryset=Community.objects.all(), widget=APISelectMultiple(api_url="/api/peering/communities/"), ) comments = CommentField(widget=SmallTextarea) class Meta: nullable_fields = [ "import_routing_policies", "export_routing_policies", "communities", "comments", ]
class InternetExchangePeeringSessionBulkEditForm(BootstrapMixin, BulkEditForm): pk = FilterChoiceField( queryset=InternetExchangePeeringSession.objects.all(), widget=forms.MultipleHiddenInput, ) is_route_server = forms.NullBooleanField( required=False, label="Route Server", widget=CustomNullBooleanSelect ) enabled = forms.NullBooleanField( required=False, label="Enable", widget=CustomNullBooleanSelect ) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) comment = CommentField(widget=SmallTextarea) class Meta: nullable_fields = ["comment"]
class InternetExchangeBulkEditForm(BootstrapMixin, BulkEditForm): pk = FilterChoiceField( queryset=InternetExchange.objects.all(), widget=forms.MultipleHiddenInput ) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) configuration_template = forms.ModelChoiceField( required=False, queryset=Template.objects.all(), widget=APISelect(api_url="/api/peering/templates/"), ) router = forms.ModelChoiceField( required=False, queryset=Router.objects.all(), widget=APISelect(api_url="/api/peering/routers/"), ) comment = CommentField(widget=SmallTextarea) class Meta: nullable_fields = ["configuration_template", "router", "comment"]
class InternetExchangePeeringSessionForm(BootstrapMixin, forms.ModelForm): autonomous_system = forms.ModelChoiceField( queryset=AutonomousSystem.objects.all(), widget=APISelect(api_url="/api/peering/autonomous-systems/"), ) password = PasswordField(required=False, render_value=True) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) comments = CommentField() tags = TagField(required=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) class Meta: model = InternetExchangePeeringSession fields = ( "autonomous_system", "internet_exchange", "ip_address", "password", "multihop_ttl", "is_route_server", "enabled", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = { "autonomous_system": "AS", "internet_exchange": "IX", "ip_address": "IP Address", "is_route_server": "Route Server", } help_texts = { "ip_address": "IPv6 or IPv4 address", "is_route_server": "Define if this session is with a route server", } widgets = { "autonomous_system": APISelect(api_url="/api/peering/autonomous-systems/"), "internet_exchange": APISelect(api_url="/api/peering/internet-exchanges/"), }
class InternetExchangeForm(BootstrapMixin, forms.ModelForm): slug = SlugField(max_length=255) import_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "import-policy"}), ) export_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "export-policy"}), ) communities = DynamicModelMultipleChoiceField( required=False, queryset=Community.objects.all()) router = DynamicModelChoiceField( required=False, queryset=Router.objects.all(), help_text="Router connected to the Internet Exchange point", ) comments = CommentField() tags = TagField(required=False) class Meta: model = InternetExchange fields = ( "peeringdb_id", "name", "slug", "ipv6_address", "ipv4_address", "communities", "import_routing_policies", "export_routing_policies", "router", "check_bgp_session_states", "comments", "tags", ) labels = { "peeringdb_id": "PeeringDB ID", "ipv6_address": "IPv6 Address", "ipv4_address": "IPv4 Address", "check_bgp_session_states": "Poll Peering Session States", } help_texts = { "peeringdb_id": "The PeeringDB ID for the IX connection (can be left empty)", "name": "Full name of the Internet Exchange point", "ipv6_address": "IPv6 Address used to peer", "ipv4_address": "IPv4 Address used to peer", "check_bgp_session_states": "If enabled, with a usable router, the state of peering sessions will be polled.", }
class AutonomousSystemForm(BootstrapMixin, forms.ModelForm): import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) comments = CommentField() tags = TagField(required=False) class Meta: model = AutonomousSystem fields = ( "asn", "name", "contact_name", "contact_phone", "contact_email", "irr_as_set", "irr_as_set_peeringdb_sync", "ipv6_max_prefixes", "ipv6_max_prefixes_peeringdb_sync", "ipv4_max_prefixes", "ipv4_max_prefixes_peeringdb_sync", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = { "asn": "ASN", "irr_as_set": "IRR AS-SET", "ipv6_max_prefixes": "IPv6 Max Prefixes", "ipv4_max_prefixes": "IPv4 Max Prefixes", "irr_as_set_peeringdb_sync": "IRR AS-SET", "ipv6_max_prefixes_peeringdb_sync": "IPv6 Max Prefixes", "ipv4_max_prefixes_peeringdb_sync": "IPv4 Max Prefixes", } help_texts = { "asn": "BGP autonomous system number (32-bit capable)", "name": "Full name of the AS", }
class DirectPeeringSessionBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm): pk = FilterChoiceField(queryset=DirectPeeringSession.objects.all(), widget=forms.MultipleHiddenInput) enabled = forms.NullBooleanField(required=False, label="Enable", widget=CustomNullBooleanSelect) relationship = forms.ChoiceField( required=False, choices=add_blank_choice(BGP_RELATIONSHIP_CHOICES), widget=StaticSelect, ) bgp_group = forms.ModelChoiceField( required=False, queryset=BGPGroup.objects.all(), label="BGP Group", widget=APISelect(api_url="/api/peering/bgp-groups/"), ) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) router = forms.ModelChoiceField( required=False, queryset=Router.objects.all(), widget=APISelect(api_url="/api/peering/routers/"), ) comments = CommentField() class Meta: nullable_fields = [ "import_routing_policies", "export_routing_policies", "router", "comments", ]
class BGPGroupForm(BootstrapMixin, forms.ModelForm): slug = SlugField(max_length=255) comments = CommentField() import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) communities = FilterChoiceField( required=False, queryset=Community.objects.all(), widget=APISelectMultiple(api_url="/api/peering/communities/"), ) tags = TagField(required=False) class Meta: model = BGPGroup fields = ( "name", "slug", "comments", "import_routing_policies", "export_routing_policies", "communities", "check_bgp_session_states", "tags", ) labels = {"check_bgp_session_states": "Poll Peering Session States"} help_texts = { "name": "Full name of the BGP group", "check_bgp_session_states": "If enabled, the state of peering sessions will be polled.", }
class InternetExchangePeeringSessionForm(BootstrapMixin, forms.ModelForm): autonomous_system = DynamicModelChoiceField( queryset=AutonomousSystem.objects.all(), label="Autonomous System") internet_exchange = DynamicModelChoiceField( queryset=InternetExchange.objects.all(), label="Internet Exchange") password = PasswordField(required=False, render_value=True) import_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "import-policy"}), ) export_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "export-policy"}), ) comments = CommentField() tags = TagField(required=False) class Meta: model = InternetExchangePeeringSession fields = ( "autonomous_system", "internet_exchange", "ip_address", "password", "multihop_ttl", "is_route_server", "enabled", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = { "ip_address": "IP Address", "is_route_server": "Route Server" } help_texts = { "ip_address": "IPv6 or IPv4 address", "is_route_server": "Define if this session is with a route server", }
class InternetExchangeBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm): pk = FilterChoiceField(queryset=InternetExchange.objects.all(), widget=forms.MultipleHiddenInput) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) communities = FilterChoiceField( required=False, queryset=Community.objects.all(), widget=APISelectMultiple(api_url="/api/peering/communities/"), ) router = forms.ModelChoiceField( required=False, queryset=Router.objects.all(), widget=APISelect(api_url="/api/peering/routers/"), ) check_bgp_session_states = forms.NullBooleanField( required=False, label="Poll BGP State", widget=CustomNullBooleanSelect) comments = CommentField(widget=SmallTextarea) class Meta: nullable_fields = [ "import_routing_policies", "export_routing_policies", "communities", "router", "comments", ]
class DirectPeeringSessionBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm): pk = DynamicModelMultipleChoiceField( queryset=DirectPeeringSession.objects.all(), widget=forms.MultipleHiddenInput) enabled = forms.NullBooleanField(required=False, label="Enable", widget=CustomNullBooleanSelect) relationship = forms.ChoiceField( required=False, choices=add_blank_choice(BGPRelationship.choices), widget=StaticSelect, ) bgp_group = DynamicModelChoiceField(required=False, queryset=BGPGroup.objects.all(), label="BGP Group") import_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "import-policy"}), ) export_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "export-policy"}), ) router = DynamicModelChoiceField(required=False, queryset=Router.objects.all()) comments = CommentField() class Meta: nullable_fields = [ "import_routing_policies", "export_routing_policies", "router", "comments", ]
class RouterFilterForm(BootstrapMixin, forms.Form): model = Router q = forms.CharField(required=False, label="Search") platform = forms.MultipleChoiceField( required=False, choices=PLATFORM_CHOICES, widget=StaticSelectMultiple ) encrypt_passwords = forms.NullBooleanField( required=False, label="Encrypt Passwords", widget=CustomNullBooleanSelect ) configuration_template = FilterChoiceField( queryset=Template.objects.all(), to_field_name="pk", null_label=True, widget=APISelectMultiple(api_url="/api/peering/templates/", null_option=True), )
class JobResultFilterForm(BootstrapMixin, forms.Form): model = JobResult q = forms.CharField(required=False, label="Search") name = forms.CharField(required=False) user_id = DynamicModelMultipleChoiceField( queryset=User.objects.all(), required=False, display_field="username", label="User", widget=APISelectMultiple(api_url="/api/users/users/"), ) status = forms.ChoiceField( required=False, choices=add_blank_choice(JobResultStatus.choices), widget=StaticSelect(), )
class RouterFilterForm(BootstrapMixin, forms.Form): model = Router q = forms.CharField(required=False, label="Search") platform = forms.MultipleChoiceField(required=False, choices=Platform.choices, widget=StaticSelectMultiple) encrypt_passwords = forms.NullBooleanField(required=False, label="Encrypt Passwords", widget=CustomNullBooleanSelect) configuration_template = DynamicModelMultipleChoiceField( required=False, queryset=Configuration.objects.all(), to_field_name="pk", widget=APISelectMultiple(null_option=True), ) tag = TagFilterField(model)
class DirectPeeringSessionForm(BootstrapMixin, forms.ModelForm): autonomous_system = forms.ModelChoiceField( queryset=AutonomousSystem.objects.all(), widget=APISelect(api_url="/api/peering/autonomous-systems/"), ) bgp_group = forms.ModelChoiceField( required=False, queryset=BGPGroup.objects.all(), label="BGP Group", widget=APISelect(api_url="/api/peering/bgp-groups/"), ) relationship = forms.ChoiceField(choices=BGP_RELATIONSHIP_CHOICES, widget=StaticSelect) router = forms.ModelChoiceField( required=False, queryset=Router.objects.all(), widget=APISelect(api_url="/api/peering/routers/"), ) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) password = PasswordField(required=False, render_value=True) comments = CommentField() tags = TagField(required=False) class Meta: model = DirectPeeringSession fields = ( "local_asn", "local_ip_address", "autonomous_system", "bgp_group", "relationship", "ip_address", "password", "multihop_ttl", "enabled", "router", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = { "local_asn": "Local ASN", "local_ip_address": "Local IP Address", "autonomous_system": "AS", "ip_address": "IP Address", } help_texts = { "local_asn": "ASN to be used locally, defaults to {}".format(settings.MY_ASN), "local_ip_address": "IPv6 or IPv4 address", "ip_address": "IPv6 or IPv4 address", "enabled": "Should this session be enabled?", "router": "Router on which this session is configured", }
class InternetExchangeForm(BootstrapMixin, forms.ModelForm): slug = SlugField(max_length=255) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) communities = FilterChoiceField( required=False, queryset=Community.objects.all(), widget=APISelectMultiple(api_url="/api/peering/communities/"), ) comment = CommentField() class Meta: model = InternetExchange fields = ( "peeringdb_id", "name", "slug", "ipv6_address", "ipv4_address", "communities", "import_routing_policies", "export_routing_policies", "configuration_template", "router", "check_bgp_session_states", "comment", ) labels = { "peeringdb_id": "PeeringDB ID", "ipv6_address": "IPv6 Address", "ipv4_address": "IPv4 Address", "check_bgp_session_states": "Poll Peering Session States", "comment": "Comments", } help_texts = { "peeringdb_id": "The PeeringDB ID for the IX connection (can be left empty)", "name": "Full name of the Internet Exchange point", "ipv6_address": "IPv6 Address used to peer", "ipv4_address": "IPv4 Address used to peer", "configuration_template": "Template for configuration generation", "router": "Router connected to the Internet Exchange point", "check_bgp_session_states": "If enabled, with a usable router, the state of peering sessions will be polled.", } widgets = { "configuration_template": APISelect(api_url="/api/peering/templates/"), "router": APISelect(api_url="/api/peering/routers/"), }
class DirectPeeringSessionForm(BootstrapMixin, forms.ModelForm): local_asn = forms.IntegerField( min_value=ASN_MIN, max_value=ASN_MAX, label="Local ASN", help_text=f"ASN to be used locally, defaults to {settings.MY_ASN}", ) autonomous_system = forms.ModelChoiceField( queryset=AutonomousSystem.objects.all(), label="Autonomous System", widget=APISelect(api_url="/api/peering/autonomous-systems/"), ) bgp_group = forms.ModelChoiceField( required=False, queryset=BGPGroup.objects.all(), label="BGP Group", widget=APISelect(api_url="/api/peering/bgp-groups/"), ) relationship = forms.ChoiceField( choices=BGP_RELATIONSHIP_CHOICES, widget=StaticSelect ) router = forms.ModelChoiceField( required=False, queryset=Router.objects.all(), widget=APISelect(api_url="/api/peering/routers/"), ) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) password = PasswordField(required=False, render_value=True) comments = CommentField() tags = TagField(required=False) class Meta: model = DirectPeeringSession fields = ( "local_asn", "local_ip_address", "autonomous_system", "bgp_group", "relationship", "ip_address", "password", "multihop_ttl", "enabled", "router", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = {"local_ip_address": "Local IP Address", "ip_address": "IP Address"} help_texts = { "local_ip_address": "IPv6 or IPv4 address", "ip_address": "IPv6 or IPv4 address", "enabled": "Should this session be enabled?", "router": "Router on which this session is configured", } def __init__(self, *args, **kwargs): initial = kwargs.get("initial", None) updated = {} if initial: updated["autonomous_system"] = initial.get("autonomous_system", None) updated["local_asn"] = settings.MY_ASN kwargs.update(initial=updated) super().__init__(*args, **kwargs)
class DirectPeeringSessionForm(BootstrapMixin, forms.ModelForm): autonomous_system = forms.ModelChoiceField( queryset=AutonomousSystem.objects.all(), widget=APISelect(api_url="/api/peering/autonomous-systems/"), ) bgp_group = forms.ModelChoiceField( required=False, queryset=BGPGroup.objects.all(), label="BGP Group", widget=APISelect(api_url="/api/peering/bgp-groups/"), ) relationship = forms.ChoiceField(choices=BGP_RELATIONSHIP_CHOICES, widget=StaticSelect) router = forms.ModelChoiceField( required=False, queryset=Router.objects.all(), widget=APISelect(api_url="/api/peering/routers/"), ) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) password = PasswordField(required=False, render_value=True) comments = CommentField() tags = TagField(required=False) def clean(self): # Do the regular cleanup cleaned_data = super().clean() # This should be cleaned up, ready to be used password = cleaned_data["password"] router = cleaned_data["router"] # Process to password check/encryption if we have what we need if router and password: # Encrypt the password only if it is not already cleaned_data["password"] = router.encrypt_string(password) return cleaned_data class Meta: model = DirectPeeringSession fields = ( "local_asn", "local_ip_address", "autonomous_system", "bgp_group", "relationship", "ip_address", "password", "multihop_ttl", "enabled", "router", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = { "local_asn": "Local ASN", "local_ip_address": "Local IP Address", "autonomous_system": "AS", "ip_address": "IP Address", } help_texts = { "local_asn": "ASN to be used locally, defaults to {}".format(settings.MY_ASN), "local_ip_address": "IPv6 or IPv4 address", "ip_address": "IPv6 or IPv4 address", "enabled": "Should this session be enabled?", "router": "Router on which this session is configured", }
class DirectPeeringSessionForm(BootstrapMixin, forms.ModelForm): local_asn = forms.IntegerField( min_value=ASN_MIN, max_value=ASN_MAX, label="Local ASN", help_text=f"ASN to be used locally, defaults to {settings.MY_ASN}", ) autonomous_system = DynamicModelChoiceField( queryset=AutonomousSystem.objects.all(), label="Autonomous System") bgp_group = DynamicModelChoiceField(required=False, queryset=BGPGroup.objects.all(), label="BGP Group") relationship = forms.ChoiceField(choices=BGPRelationship.choices, widget=StaticSelect) router = DynamicModelChoiceField( required=False, queryset=Router.objects.all(), help_text="Router on which this session is configured", ) import_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "import-policy"}), ) export_routing_policies = DynamicModelMultipleChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( additional_query_params={"type": "export-policy"}), ) password = PasswordField(required=False, render_value=True) comments = CommentField() tags = TagField(required=False) class Meta: model = DirectPeeringSession fields = ( "local_asn", "local_ip_address", "autonomous_system", "bgp_group", "relationship", "ip_address", "password", "multihop_ttl", "enabled", "router", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = { "local_ip_address": "Local IP Address", "ip_address": "IP Address" } help_texts = { "local_ip_address": "IPv6 or IPv4 address", "ip_address": "IPv6 or IPv4 address", "enabled": "Should this session be enabled?", } def __init__(self, *args, **kwargs): initial = kwargs.get("initial", {}) # Set local ASN according to the one found in the settings initial.update({"local_asn": settings.MY_ASN}) super().__init__(*args, **kwargs)
class InternetExchangePeeringSessionForm(BootstrapMixin, forms.ModelForm): password = PasswordField(required=False, render_value=True) import_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "import-policy"}, ), ) export_routing_policies = FilterChoiceField( required=False, queryset=RoutingPolicy.objects.all(), widget=APISelectMultiple( api_url="/api/peering/routing-policies/", query_filters={"type": "export-policy"}, ), ) comments = CommentField() tags = TagField(required=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["autonomous_system"].widget.attrs[ "data-live-search"] = "true" def clean(self): # Do the regular cleanup cleaned_data = super().clean() # This should be cleaned up, ready to be used password = cleaned_data["password"] internet_exchange = cleaned_data["internet_exchange"] # Process to password check/encryption if we have what we need if internet_exchange.router and password: # Encrypt the password only if it is not already cleaned_data["password"] = internet_exchange.router.encrypt_string( password) return cleaned_data class Meta: model = InternetExchangePeeringSession fields = ( "autonomous_system", "internet_exchange", "ip_address", "password", "multihop_ttl", "is_route_server", "enabled", "import_routing_policies", "export_routing_policies", "comments", "tags", ) labels = { "autonomous_system": "AS", "internet_exchange": "IX", "ip_address": "IP Address", "is_route_server": "Route Server", } help_texts = { "ip_address": "IPv6 or IPv4 address", "is_route_server": "Define if this session is with a route server", } widgets = { "autonomous_system": APISelect(api_url="/api/peering/autonomous-systems/"), "internet_exchange": APISelect(api_url="/api/peering/internet-exchanges/"), }