From 78ec7ac7466ab55da0a3664307b88d431d8e45d0 Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 7 Nov 2019 14:07:57 +0300 Subject: [PATCH] network: Add network pool mac info. dhcp->dhcp4 conversion. --- networks/forms.py | 2 +- networks/templates/create_net_block.html | 4 ++-- networks/templates/network.html | 12 +++++++----- networks/views.py | 5 +++-- vrtManager/network.py | 17 +++++++++++------ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/networks/forms.py b/networks/forms.py index fc94358..7ffe205 100644 --- a/networks/forms.py +++ b/networks/forms.py @@ -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) diff --git a/networks/templates/create_net_block.html b/networks/templates/create_net_block.html index 166dc23..6e2d33a 100644 --- a/networks/templates/create_net_block.html +++ b/networks/templates/create_net_block.html @@ -27,9 +27,9 @@
- +
- +
diff --git a/networks/templates/network.html b/networks/templates/network.html index c5d8cd5..0114a08 100644 --- a/networks/templates/network.html +++ b/networks/templates/network.html @@ -39,14 +39,16 @@
-

{% trans "Network name" %}:

+

{% trans "Network Name" %}:

{% trans "Device" %}:

+

{% trans "MAC" %}:

{% trans "State" %}:

{% trans "Autostart" %}:

{{ pool }}

{{ device }}

+

{{ net_mac }}

{% csrf_token %} {% ifequal state 0 %} @@ -102,8 +104,8 @@

{% trans "IPv4 Forwarding" %}:

{% trans "Network" %}:

+

{% trans "DHCP" %}:

{% if ipv4_dhcp_range_start and ipv4_dhcp_range_end %} -

{% trans "DHCP" %}:

{% trans "Start" %}:

{% trans "End" %}:

{% endif %} @@ -123,7 +125,7 @@ {% trans "ISOLATE" %} {% endif %}

-

{{ ipv4_network }}

+

{{ ipv4_network|default:"-" }}

{% if ipv4_dhcp_range_start and ipv4_dhcp_range_end %} {% trans "ON" %} @@ -227,8 +229,8 @@

{% trans "IPv6 Forwarding" %}:

{% trans "Network" %}:

+

{% trans "DHCP" %}:

{% if ipv6_dhcp_range_start and ipv6_dhcp_range_end %} -

{% trans "DHCP" %}:

{% trans "Start" %}:

{% trans "End" %}:

{% endif %} @@ -241,7 +243,7 @@ {% trans "ROUTE" %} {% endif %}

-

{{ ipv6_network }}

+

{{ ipv6_network|default:"-" }}

{% if ipv6_dhcp_range_start and ipv6_dhcp_range_end %} {% trans "ON" %} diff --git a/networks/views.py b/networks/views.py index 427248a..d0d9886 100644 --- a/networks/views.py +++ b/networks/views.py @@ -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() diff --git a/vrtManager/network.py b/vrtManager/network.py index ded82c3..d077c05 100644 --- a/vrtManager/network.py +++ b/vrtManager/network.py @@ -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 = """ %s""" % name @@ -55,12 +55,12 @@ class wvmNetworks(wvmConnect): if forward != 'bridge': xml += """ """ % (gateway, mask) - if dhcp: + if dhcp4: xml += """ - """ % (dhcp[0], dhcp[1]) + """ % (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 += """""" % (util.randomMAC(), gateway[:-2], ip) xml += """""" @@ -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")