1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

Reconfig to create nat routed network without subnet

This commit is contained in:
catborise 2019-11-07 16:49:40 +03:00
parent 78ec7ac746
commit 8bc316355d
3 changed files with 5 additions and 7 deletions

View file

@ -7,7 +7,7 @@ class AddNetPool(forms.Form):
name = forms.CharField(error_messages={'required': _('No pool name has been entered')}, name = forms.CharField(error_messages={'required': _('No pool name has been entered')},
max_length=20) max_length=20)
subnet = forms.CharField(error_messages={'required': _('No subnet has been entered')}, subnet = forms.CharField(error_messages={'required': _('No subnet has been entered')},
max_length=20) max_length=20, required=False)
forward = forms.CharField(max_length=100) forward = forms.CharField(max_length=100)
dhcp4 = forms.BooleanField(required=False) dhcp4 = forms.BooleanField(required=False)
fixed = forms.BooleanField(required=False) fixed = forms.BooleanField(required=False)
@ -25,7 +25,7 @@ class AddNetPool(forms.Form):
def clean_subnet(self): def clean_subnet(self):
subnet = self.cleaned_data['subnet'] subnet = self.cleaned_data['subnet']
have_symbol = re.match('^[0-9./]+$', subnet) have_symbol = re.match('^[0-9./]+$', subnet if subnet else ".")
if not have_symbol: if not have_symbol:
raise forms.ValidationError(_('The pool subnet must not contain any special characters')) raise forms.ValidationError(_('The pool subnet must not contain any special characters'))
elif len(subnet) > 20: elif len(subnet) > 20:

View file

@ -13,7 +13,7 @@
<h4 class="modal-title">{% trans "Add New Network" %}</h4> <h4 class="modal-title">{% trans "Add New Network" %}</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %} <form class="form-horizontal" method="post" action="" role="form" novalidate>{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label">{% trans "Name" %}</label> <label class="col-sm-4 control-label">{% trans "Name" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">

View file

@ -31,6 +31,7 @@ def networks(request, compute_id):
compute.password, compute.password,
compute.type) compute.type)
networks = conn.get_networks_info() networks = conn.get_networks_info()
dhcp4 = netmask = gateway = ''
if request.method == 'POST': if request.method == 'POST':
if 'create' in request.POST: if 'create' in request.POST:
@ -42,11 +43,8 @@ def networks(request, compute_id):
error_messages.append(msg) error_messages.append(msg)
if data['forward'] == 'bridge' and data['bridge_name'] == '': if data['forward'] == 'bridge' and data['bridge_name'] == '':
error_messages.append('Please enter bridge name') error_messages.append('Please enter bridge name')
try: if data['subnet']:
gateway, netmask, dhcp4 = network_size(data['subnet'], data['dhcp4']) gateway, netmask, dhcp4 = network_size(data['subnet'], data['dhcp4'])
except:
error_msg = _("Input subnet pool error")
error_messages.append(error_msg)
if not error_messages: if not error_messages:
conn.create_network(data['name'], data['forward'], gateway, netmask, conn.create_network(data['name'], data['forward'], gateway, netmask,
dhcp4, data['bridge_name'], data['openvswitch'], data['fixed']) dhcp4, data['bridge_name'], data['openvswitch'], data['fixed'])