Use MultiIPField for access form to avoid need for custom validation
Change-Id: If3314e94319056fe45499e83ff1bb15c4d19c64c
This commit is contained in:
parent
e8d81f17d3
commit
42d6638d3b
@ -7,4 +7,3 @@ oslo.log>=3.30.0 # Apache-2.0
|
||||
python-swiftclient>=2.2.0
|
||||
python-troveclient>=1.2.0
|
||||
horizon>=17.1.0 # Apache-2.0
|
||||
netaddr>=0.7.18 # BSD
|
||||
|
@ -15,7 +15,6 @@
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import netaddr
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
@ -293,8 +292,11 @@ class AddAccessAction(workflows.Action):
|
||||
"""
|
||||
is_public = forms.BooleanField(label=_("Is Public"),
|
||||
required=False)
|
||||
allowed_cidrs = forms.CharField(label=_("Allowed CIDRs"),
|
||||
allowed_cidrs = forms.MultiIPField(label=_("Allowed CIDRs"),
|
||||
required=False,
|
||||
version=forms.IPv4 | forms.IPv6,
|
||||
mask=True,
|
||||
widget=forms.TextInput(),
|
||||
help_text=_("Comma-separated CIDRs "
|
||||
"to connect through."))
|
||||
|
||||
@ -303,19 +305,6 @@ class AddAccessAction(workflows.Action):
|
||||
permissions = TROVE_ADD_PERMS
|
||||
help_text_template = "project/databases/_launch_access_help.html"
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(AddAccessAction, self).clean()
|
||||
if cleaned_data.get('allowed_cidrs'):
|
||||
cidrs = cleaned_data.get('allowed_cidrs').split(',')
|
||||
for cidr in cidrs:
|
||||
try:
|
||||
netaddr.IPNetwork(cidr)
|
||||
except netaddr.AddrFormatError:
|
||||
msg = _('Invalid Allowed CIDR provided.')
|
||||
self._errors["allowed_cidrs"] = self.error_class([msg])
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class DatabaseAccess(workflows.Step):
|
||||
action_class = AddAccessAction
|
||||
|
Loading…
Reference in New Issue
Block a user