mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 15:15:22 +00:00
network: Add network pool mac info. dhcp->dhcp4 conversion.
This commit is contained in:
parent
c5a96b7662
commit
78ec7ac746
5 changed files with 24 additions and 16 deletions
|
@ -9,7 +9,7 @@ class AddNetPool(forms.Form):
|
|||
subnet = forms.CharField(error_messages={'required': _('No subnet has been entered')},
|
||||
max_length=20)
|
||||
forward = forms.CharField(max_length=100)
|
||||
dhcp = forms.BooleanField(required=False)
|
||||
dhcp4 = forms.BooleanField(required=False)
|
||||
fixed = forms.BooleanField(required=False)
|
||||
bridge_name = forms.CharField(max_length=20, required=False)
|
||||
openvswitch = forms.BooleanField(required=False)
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group bridge_name_form_group_dhcp">
|
||||
<label class="col-sm-4 control-label">{% trans "DHCP" %}</label>
|
||||
<label class="col-sm-4 control-label">{% trans "DHCPv4" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="checkbox" name="dhcp" value="true" checked>
|
||||
<input type="checkbox" name="dhcp4" value="true" checked>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group bridge_name_form_group_dhcp">
|
||||
|
|
|
@ -39,14 +39,16 @@
|
|||
|
||||
<div class="row">
|
||||
<div class="col-xs-6 col-sm-4">
|
||||
<p>{% trans "Network name" %}:</p>
|
||||
<p>{% trans "Network Name" %}:</p>
|
||||
<p>{% trans "Device" %}:</p>
|
||||
<p>{% trans "MAC" %}:</p>
|
||||
<p>{% trans "State" %}:</p>
|
||||
<p>{% trans "Autostart" %}:</p>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6">
|
||||
<p>{{ pool }}</p>
|
||||
<p>{{ device }}</p>
|
||||
<p>{{ net_mac }}</p>
|
||||
<p>
|
||||
<form action="" method="post" role="form">{% csrf_token %}
|
||||
{% ifequal state 0 %}
|
||||
|
@ -102,8 +104,8 @@
|
|||
<div class="col-xs-6 col-sm-4">
|
||||
<p>{% trans "IPv4 Forwarding" %}:</p>
|
||||
<p>{% trans "Network" %}:</p>
|
||||
<p>{% trans "DHCP" %}:</p>
|
||||
{% if ipv4_dhcp_range_start and ipv4_dhcp_range_end %}
|
||||
<p>{% trans "DHCP" %}:</p>
|
||||
<p>{% trans "Start" %}:</p>
|
||||
<p>{% trans "End" %}:</p>
|
||||
{% endif %}
|
||||
|
@ -123,7 +125,7 @@
|
|||
{% trans "ISOLATE" %}
|
||||
{% endif %}
|
||||
</p>
|
||||
<p>{{ ipv4_network }}</p>
|
||||
<p>{{ ipv4_network|default:"-" }}</p>
|
||||
<p>
|
||||
{% if ipv4_dhcp_range_start and ipv4_dhcp_range_end %}
|
||||
<span class="text-success">{% trans "ON" %}</span>
|
||||
|
@ -227,8 +229,8 @@
|
|||
<div class="col-xs-6 col-sm-4">
|
||||
<p>{% trans "IPv6 Forwarding" %}:</p>
|
||||
<p>{% trans "Network" %}:</p>
|
||||
<p>{% trans "DHCP" %}:</p>
|
||||
{% if ipv6_dhcp_range_start and ipv6_dhcp_range_end %}
|
||||
<p>{% trans "DHCP" %}:</p>
|
||||
<p>{% trans "Start" %}:</p>
|
||||
<p>{% trans "End" %}:</p>
|
||||
{% endif %}
|
||||
|
@ -241,7 +243,7 @@
|
|||
{% trans "ROUTE" %}
|
||||
{% endif %}
|
||||
</p>
|
||||
<p>{{ ipv6_network }}</p>
|
||||
<p>{{ ipv6_network|default:"-" }}</p>
|
||||
<p>
|
||||
{% if ipv6_dhcp_range_start and ipv6_dhcp_range_end %}
|
||||
<span class="text-success">{% trans "ON" %}</span>
|
||||
|
|
|
@ -43,13 +43,13 @@ def networks(request, compute_id):
|
|||
if data['forward'] == 'bridge' and data['bridge_name'] == '':
|
||||
error_messages.append('Please enter bridge name')
|
||||
try:
|
||||
gateway, netmask, dhcp = network_size(data['subnet'], data['dhcp'])
|
||||
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:
|
||||
conn.create_network(data['name'], data['forward'], gateway, netmask,
|
||||
dhcp, data['bridge_name'], data['openvswitch'], data['fixed'])
|
||||
dhcp4, data['bridge_name'], data['openvswitch'], data['fixed'])
|
||||
return HttpResponseRedirect(reverse('network', args=[compute_id, data['name']]))
|
||||
else:
|
||||
for msg_err in form.errors.values():
|
||||
|
@ -86,6 +86,7 @@ def network(request, compute_id, pool):
|
|||
state = conn.is_active()
|
||||
device = conn.get_bridge_device()
|
||||
autostart = conn.get_autostart()
|
||||
net_mac = conn.get_network_mac()
|
||||
net_forward = conn.get_network_forward()
|
||||
dhcp_range_start = ipv4_dhcp_range_end = dict()
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class wvmNetworks(wvmConnect):
|
|||
def define_network(self, xml):
|
||||
self.wvm.networkDefineXML(xml)
|
||||
|
||||
def create_network(self, name, forward, gateway, mask, dhcp, bridge, openvswitch, fixed=False):
|
||||
def create_network(self, name, forward, gateway, mask, dhcp4, bridge, openvswitch, fixed=False):
|
||||
xml = """
|
||||
<network>
|
||||
<name>%s</name>""" % name
|
||||
|
@ -55,12 +55,12 @@ class wvmNetworks(wvmConnect):
|
|||
if forward != 'bridge':
|
||||
xml += """
|
||||
<ip address='%s' netmask='%s'>""" % (gateway, mask)
|
||||
if dhcp:
|
||||
if dhcp4:
|
||||
xml += """<dhcp>
|
||||
<range start='%s' end='%s' />""" % (dhcp[0], dhcp[1])
|
||||
<range start='%s' end='%s' />""" % (dhcp4[0], dhcp4[1])
|
||||
if fixed:
|
||||
fist_oct = int(dhcp[0].strip().split('.')[3])
|
||||
last_oct = int(dhcp[1].strip().split('.')[3])
|
||||
fist_oct = int(dhcp4[0].strip().split('.')[3])
|
||||
last_oct = int(dhcp4[1].strip().split('.')[3])
|
||||
for ip in range(fist_oct, last_oct + 1):
|
||||
xml += """<host mac='%s' ip='%s.%s' />""" % (util.randomMAC(), gateway[:-2], ip)
|
||||
xml += """</dhcp>"""
|
||||
|
@ -119,7 +119,7 @@ class wvmNetwork(wvmConnect):
|
|||
ip_networks = dict()
|
||||
xml = self._XMLDesc(0)
|
||||
if util.get_xml_path(xml, "/network/ip") is None:
|
||||
return None
|
||||
return ip_networks
|
||||
tree = etree.fromstring(xml)
|
||||
ips = tree.findall('.ip')
|
||||
for ip in ips:
|
||||
|
@ -144,6 +144,11 @@ class wvmNetwork(wvmConnect):
|
|||
ip_networks[family] = ret
|
||||
return ip_networks
|
||||
|
||||
def get_network_mac(self):
|
||||
xml = self._XMLDesc(0)
|
||||
mac = util.get_xml_path(xml, "/network/mac/@address")
|
||||
return mac
|
||||
|
||||
def get_network_forward(self):
|
||||
xml = self._XMLDesc(0)
|
||||
fw = util.get_xml_path(xml, "/network/forward/@mode")
|
||||
|
|
Loading…
Reference in a new issue