From a3be93874c13f6a585dae2569e13b53af69af9b0 Mon Sep 17 00:00:00 2001 From: catborise Date: Wed, 23 Jan 2019 09:14:54 +0300 Subject: [PATCH 01/11] Handle empty name for fixed networks --- vrtManager/network.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vrtManager/network.py b/vrtManager/network.py index 32b0819..8b430c6 100644 --- a/vrtManager/network.py +++ b/vrtManager/network.py @@ -178,7 +178,9 @@ class wvmNetwork(wvmConnect): for net in doc.xpath('/network/ip/dhcp/host'): ip = net.xpath('@ip')[0] mac = net.xpath('@mac')[0] - name = net.xpath('@name')[0] + name = net.xpath('@name') + name = name[0] if name else "" + result.append({'ip': ip, 'mac': mac, 'name': name}) return result @@ -186,7 +188,10 @@ class wvmNetwork(wvmConnect): def modify_fixed_address(self, name, address, mac): util.validate_macaddr(mac) - new_xml = ''.format(mac, name, IP(address)) + if name: + new_xml = ''.format(mac, name, IP(address)) + else: + new_xml = ''.format(mac, IP(address)) new_host_xml = ElementTree.fromstring(new_xml) tree = ElementTree.fromstring(self._XMLDesc(0)) From b757c62d4f06e20f560e51b4f560872e5dbce257 Mon Sep 17 00:00:00 2001 From: catborise Date: Wed, 23 Jan 2019 14:30:33 +0300 Subject: [PATCH 02/11] Add forcibly power off option to suspended instance --- instances/templates/instance.html | 45 +++++++++++++++++++------------ 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index bd6bb78..4631120 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -136,12 +136,11 @@ {% trans "Resume" %} - {% else %} - +
  • + + {% trans "Force Off" %} + +
  • {% endif %} {% endifequal %} {% ifequal status 5 %} @@ -186,19 +185,31 @@ {% endif %} {% endifequal %} - {% ifequal status 3 %} -
    -
    {% csrf_token %} - {% if request.user.is_superuser %} + {% ifequal status 3 %} + {% if request.user.is_superuser %} +

    {% trans "This action restore the instance after suspend." %}

    - - {% else %} + {% csrf_token %} + +
    + +
    +
    +

    {% trans "This action forcibly powers off the instance and may cause data corruption." %}

    +
    {% csrf_token %} + +
    +
    +
    + {% else %} +

    {% trans "Administrator blocked your instance." %}

    - - {% endif %} -
    - -
    +
    {% csrf_token %} + +
    +
    +
    + {% endif %} {% endifequal %} {% ifequal status 5 %}
    From 8d2b3e3024e0a35e6899dc0c1cf34bb9f69b84cf Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 24 Jan 2019 08:41:45 +0300 Subject: [PATCH 03/11] Add explanation for boot menu changes. Minor cosmetic fixes --- instances/templates/instance.html | 4 +++- instances/views.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 4631120..59fcc40 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -616,7 +616,9 @@ {% endifequal %} {% else %} -

    {% trans "**** Please shutdown instance to modify boot menu ****" %} + {% ifequal bootmenu 0 %} +

    {% trans "**** Please shutdown instance to modify boot menu ****" %} + {% endifequal %} {% endifequal %}

    diff --git a/instances/views.py b/instances/views.py index e3c7628..36b7327 100644 --- a/instances/views.py +++ b/instances/views.py @@ -622,6 +622,11 @@ def instance(request, compute_id, vname): order_list[idx] = {"type": type, "dev": dev} conn.set_bootorder(order_list) msg = _("Set boot order") + + if not conn.get_status() == 5: + messages.success(request, _("Boot menu changes applied. But it will be activated after shutdown")) + else: + messages.success(request, _("Boot order changed successfully.")) addlogmsg(request.user.username, instance.name, msg) return HttpResponseRedirect(request.get_full_path() + '#boot_opt') From 573df2acaa3adfeba6e208a8ea601f426bed7cbb Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 24 Jan 2019 15:00:45 +0300 Subject: [PATCH 04/11] Add XML Config to collapsible accordion --- nwfilters/templates/add_nwf_rule.html | 33 ++++ nwfilters/templates/nwfilter.html | 239 ++++++++++++-------------- 2 files changed, 140 insertions(+), 132 deletions(-) create mode 100644 nwfilters/templates/add_nwf_rule.html diff --git a/nwfilters/templates/add_nwf_rule.html b/nwfilters/templates/add_nwf_rule.html new file mode 100644 index 0000000..bd124e4 --- /dev/null +++ b/nwfilters/templates/add_nwf_rule.html @@ -0,0 +1,33 @@ +{% load i18n %} +{% if request.user.is_superuser %} + + + + + + +{% endif %} \ No newline at end of file diff --git a/nwfilters/templates/nwfilter.html b/nwfilters/templates/nwfilter.html index 377190d..db4b0dd 100644 --- a/nwfilters/templates/nwfilter.html +++ b/nwfilters/templates/nwfilter.html @@ -38,152 +38,127 @@ {% include 'errors_block.html' %} {% include 'messages_block.html' %} -
    -
    -

    {% trans "UUID:" %}

    -

    {% trans "Name:" %}

    -
    - -
    -

    {{ uuid }}

    -

    {{ name }}

    -
    - -
    -

    {% trans "XML:" %}

    -
    {% csrf_token %} -
    - - -
    - -
    +
    +

    {% trans "UUID:" %}

    +

    {% trans "Name:" %}

    +
    +
    +

    {{ uuid }}

    +

    {{ name }}

    +
    +
    +
    + +
    +
    +
    + +
    +
    + +
    {% csrf_token %} +
    + + +
    + +
    +
    +
    +
    +
    +
    +
    -

    {% trans "Filter References:" %}

    {% csrf_token %} -
    - - + {% for nwf in nwfilters_all %} {% endfor %} - - +
    -
    + +
    + + + + + + + + {% for ref in refs %} + + + + + + {% endfor %} + +
    #{% trans "Reference" %}{% trans "Action" %}
    {{ forloop.counter }}{{ ref }} +
    {% csrf_token %} + + +
    +
    +
    +
    -
    - - - - - - - - - - {% for ref in refs %} - - - - - - {% endfor %} - -
    #{% trans "Reference" %}{% trans "Action" %}
    {{ forloop.counter }}{{ ref }} -
    {% csrf_token %} - - -
    -
    -
    + {% include 'add_nwf_rule.html' %} +
    -
    -

    {% trans "Rules:" %}

    - - - - - - +
    + + + + + + + + + + + + {% for rule in rules %} + + + + + + + + + + {% endfor %} + +
    {% trans "Rule" %}{% trans "ActionType" %}{% trans "Direction" %}{% trans "Priority" %}{% trans "Statematch" %}{% trans "Directives" %}{% trans "Action" %}
    {{ forloop.counter }}{{ rule.action }}{{ rule.direction }}{{ rule.priority }}{{ rule.statematch }}{{ rule.directives }} +
    {% csrf_token %} + + + + +
    +
    -
    -
    - - - - - - - - - - - - - - {% for rule in rules %} - - - - - - - - - - {% endfor %} - -
    {% trans "Rule" %}{% trans "ActionType" %}{% trans "Direction" %}{% trans "Priority" %}{% trans "Statematch" %}{% trans "Directives" %}{% trans "Action" %}
    {{ forloop.counter }}{{ rule.action }}{{ rule.direction }}{{ rule.priority }}{{ rule.statematch }}{{ rule.directives }} -
    {% csrf_token %} - - - - -
    -
    -
    -
    - - {% endblock %} {% block script %} @@ -209,7 +184,7 @@ var edit_input = $('input[name="edit_xml"]'); editor.getSession().on("change",function () { edit_input.val(editor.getSession().getValue()); - }) + }); var rule_editor = ace.edit("rule_editor"); rule_editor.getSession().setMode("ace/mode/xml"); @@ -217,7 +192,7 @@ var rule_input = $('input[name="nwfilterrule_xml"]'); rule_editor.getSession().on("change",function () { rule_input.val(rule_editor.getSession().getValue()); - }) + }); {% endblock %} From ead0414a4d276dc4ab9a72878062082613222a7e Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 24 Jan 2019 15:02:19 +0300 Subject: [PATCH 05/11] Add XML config editing option for a network --- networks/templates/network.html | 172 +++++++++++++++++++------------- networks/views.py | 18 +++- vrtManager/network.py | 2 +- 3 files changed, 121 insertions(+), 71 deletions(-) diff --git a/networks/templates/network.html b/networks/templates/network.html index 450c393..e3af02c 100644 --- a/networks/templates/network.html +++ b/networks/templates/network.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load i18n %} +{% load staticfiles %} {% block title %}{% trans "Network" %} - {{ pool }}{% endblock %} {% block content %} @@ -38,10 +39,10 @@
    -

    {% trans "Network name:" %}

    -

    {% trans "Device:" %}

    -

    {% trans "State" %}

    -

    {% trans "Autostart" %}

    +

    {% trans "Network name" %}:

    +

    {% trans "Device" %}:

    +

    {% trans "State" %}:

    +

    {% trans "Autostart" %}:

    {{ pool }}

    @@ -67,11 +68,35 @@

    - {#{% if state %}#} -
    - +
    + +
    +
    +
    + +
    +
    +
    {% csrf_token %} +
    + + +
    + +
    +
    +
    -
    +
    +
    + +
    +

    {% trans "IPv4 Forwarding:" %}

    {% trans "Network:" %}

    @@ -122,75 +147,74 @@ {% endif %}
    - {% ifequal ipv4_forward.0 'nat' %} - {% if state %} - {% include 'modify_fixed_address.html' %} - {% endif %} -
    - -
    - {% endifequal %} - {% if fixed_address %} -
    -
    -
    -
    - -
    -
    + {% ifequal ipv4_forward.0 'nat' %} + {% if state %} + {% include 'modify_fixed_address.html' %} + {% endif %} +
    + +
    + {% endifequal %} + {% if fixed_address %} +
    +
    +
    +
    + +
    +
    -
    -
    - -
    - - +
    +
    +
    - - - - - - - - - - - {% for fix in fixed_address %} - - {% csrf_token %} - - - - - - - {% endfor %} - -
    {% trans "MAC" %}{% trans "Address" %}{% trans "Name" %}{% trans "Action" %}
    - - - -
    + +
    + + + + + + + + + + + {% for fix in fixed_address %} + + {% csrf_token %} + + + + + + + {% endfor %} + +
    {% trans "MAC" %}{% trans "Address" %}{% trans "Name" %}{% trans "Action" %}
    + + + +
    - {#{% endif %}#} +
    {% endif %} {% endblock %} {% block script %} @@ -230,4 +254,14 @@ }); }); + + {% endblock %} \ No newline at end of file diff --git a/networks/views.py b/networks/views.py index ee61043..29fb802 100644 --- a/networks/views.py +++ b/networks/views.py @@ -88,6 +88,7 @@ def network(request, compute_id, pool): ipv4_dhcp_range_end = conn.get_ipv4_dhcp_range_end() ipv4_network = conn.get_ipv4_network() fixed_address = conn.get_mac_ipaddr() + xml = conn._XMLDesc(0) except libvirtError as lib_err: error_messages.append(lib_err) @@ -139,7 +140,6 @@ def network(request, compute_id, pool): conn.delete_fixed_address(mac) messages.success(request, "Fixed Address is Deleted.") return HttpResponseRedirect(request.get_full_path()) - if 'modify_dhcp_range' in request.POST: range_start = request.POST.get('range_start', '') range_end = request.POST.get('range_end', '') @@ -149,6 +149,22 @@ def network(request, compute_id, pool): return HttpResponseRedirect(request.get_full_path()) except libvirtError as lib_err: error_messages.append(lib_err.message) + if 'edit_network' in request.POST: + edit_xml = request.POST.get('edit_xml', '') + if edit_xml: + try: + new_conn = wvmNetworks(compute.hostname, + compute.login, + compute.password, + compute.type) + conn.define_network(edit_xml) + if conn.is_active(): + messages.success(request, _("Network XML is changed. Stop and start network to activate new config.")) + else: + messages.success(request, _("Network XML is changed.")) + return HttpResponseRedirect(request.get_full_path()) + except libvirtError as lib_err: + error_messages.append(lib_err.message) conn.close() diff --git a/vrtManager/network.py b/vrtManager/network.py index 8b430c6..d3c67f3 100644 --- a/vrtManager/network.py +++ b/vrtManager/network.py @@ -2,7 +2,7 @@ from vrtManager import util from vrtManager.IPy import IP from vrtManager.connection import wvmConnect from xml.etree import ElementTree -from libvirt import VIR_NETWORK_SECTION_IP_DHCP_HOST, VIR_NETWORK_SECTION_IP_DHCP_RANGE +from libvirt import VIR_NETWORK_SECTION_IP_DHCP_HOST from libvirt import VIR_NETWORK_UPDATE_COMMAND_ADD_LAST, VIR_NETWORK_UPDATE_COMMAND_DELETE, VIR_NETWORK_UPDATE_COMMAND_MODIFY from libvirt import VIR_NETWORK_UPDATE_AFFECT_LIVE, VIR_NETWORK_UPDATE_AFFECT_CONFIG From cba5147cd130a6f6518a984ea74bfb2c2fd060ef Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 25 Jan 2019 08:49:00 +0300 Subject: [PATCH 06/11] Arrange CSS for tables. Remove unnecessary add nwfilter button. --- nwfilters/templates/nwfilter.html | 48 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/nwfilters/templates/nwfilter.html b/nwfilters/templates/nwfilter.html index db4b0dd..18e04c6 100644 --- a/nwfilters/templates/nwfilter.html +++ b/nwfilters/templates/nwfilter.html @@ -6,7 +6,6 @@
    - {% include 'create_nwfilter_block.html' %}

    {% trans "NWFilter:" %} {{ name }}

    + +
    {% csrf_token %} +
    + + + +
    +
    -
    -
    {% csrf_token %} -
    - - - -
    -
    -
    -
    - +
    +
    @@ -107,7 +105,7 @@
    # {% trans "Reference" %}{{ forloop.counter }} {{ ref }} -
    {% csrf_token %} + {% csrf_token %}
    + {% include 'add_nwf_rule.html' %}
    - {% include 'add_nwf_rule.html' %}
    -
    - +
    +
    - + @@ -145,7 +143,7 @@ {% for fix in fixed_address %} - {% csrf_token %} - - - + {% csrf_token %} + + +
    {% trans "Rule" %}{% trans "Rule" %} {% trans "ActionType" %} {% trans "Direction" %} {% trans "Priority" %}{{ rule.statematch }} {{ rule.directives }} - {% csrf_token %} + {% csrf_token %} From 1f005e90e1cc8a59b10656e4b270a8dcc7b1f2b8 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 25 Jan 2019 08:51:52 +0300 Subject: [PATCH 07/11] Arrange search component placement --- nwfilters/templates/nwfilters.html | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nwfilters/templates/nwfilters.html b/nwfilters/templates/nwfilters.html index dba8377..28c7372 100644 --- a/nwfilters/templates/nwfilters.html +++ b/nwfilters/templates/nwfilters.html @@ -40,12 +40,12 @@
    -
    -
    - -
    - +
    + +
    +
    +
    {% if nwfilters %}
    @@ -166,6 +166,4 @@ input.val(editor.getSession().getValue()); }) - - {% endblock %} From 5c3a9e2a812f75ba76e0558dafa22c249ebdd53b Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 25 Jan 2019 13:42:48 +0300 Subject: [PATCH 08/11] Fix network change operation: add interface type network config --- vrtManager/instance.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vrtManager/instance.py b/vrtManager/instance.py index 143465b..76f9360 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -986,6 +986,21 @@ class wvmInstance(wvmConnect): source.set('bridge', bridge_name) source = interface.find('filterref') + if net_filter: + if source is not None: source.set('filter', net_filter) + else: + element = ElementTree.Element("filterref") + element.attrib['filter'] = net_filter + interface.append(element) + else: + if source is not None: interface.remove(source) + elif interface.get('type') == 'network': + source = interface.find('mac') + source.set('address', net_mac) + source = interface.find('source') + source.set('network', net_source) + source = interface.find('filterref') + if net_filter: if source is not None: source.set('filter', net_filter) else: From d3cc19b4f8177d819e3a588d3f01474a693affe0 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 25 Jan 2019 13:57:32 +0300 Subject: [PATCH 09/11] Change network devices visual style to prevent erroneous delete --- instances/templates/instance.html | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 59fcc40..72117da 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -809,6 +809,7 @@
    +
    @@ -841,18 +842,13 @@ {% endfor %}
    -
    - -
    {% endfor %}
    -

    {% trans "For migration both host servers must have equal settings and OS type" %}

    From 8d90bc13723754291c80c583c5058c1c67d13fc1 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 25 Jan 2019 15:06:51 +0300 Subject: [PATCH 10/11] Change collabsible panels id to differentiate. --- networks/templates/network.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networks/templates/network.html b/networks/templates/network.html index e3af02c..cf9bbbd 100644 --- a/networks/templates/network.html +++ b/networks/templates/network.html @@ -161,11 +161,11 @@
    -
    +
    From 3dc44662a0dc2680cbc0b2c0b1fd598441291185 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 28 Jan 2019 11:58:55 +0300 Subject: [PATCH 11/11] Add trans tag some text. Add a text for empty cdrom and fix aligment. --- instances/templates/instance.html | 16 ++++++++++------ networks/templates/network.html | 8 ++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 72117da..de572df 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -726,8 +726,12 @@ {% endif %}
    + {% empty %} +
    +
    {% trans 'There is not any CD-ROM device.' %}
    +
    {% endfor %} - +

    {% trans "Instance Volume" %} {% include 'add_instance_volume.html' %} @@ -824,10 +828,10 @@

    @@ -1210,7 +1214,7 @@
    -

    {% trans "CPU usage" %}

    +

    {% trans "CPU Usage" %}

    @@ -1223,7 +1227,7 @@ {% for net in networks %}
    -

    {% trans "Bandwidth device:" %} eth{{ forloop.counter0 }}

    +

    {% trans "Bandwidth Device" %}: eth{{ forloop.counter0 }}

    @@ -1237,7 +1241,7 @@ {% for disk in disks %}
    -

    {% trans "Disk I/O device:" %} {{ disk.dev }}

    +

    {% trans "Disk I/O device" %}: {{ disk.dev }}

    diff --git a/networks/templates/network.html b/networks/templates/network.html index cf9bbbd..5f2949a 100644 --- a/networks/templates/network.html +++ b/networks/templates/network.html @@ -187,10 +187,10 @@