From 64b43f13858df043a014eb19a3951b20beba8e93 Mon Sep 17 00:00:00 2001 From: Retspen Date: Fri, 13 Mar 2015 11:06:34 +0200 Subject: [PATCH] Added some funcitons --- instances/views.py | 50 ++-- templates/instance.html | 495 ++++++++++++++++++++++++++++++++++++---- vrtManager/instance.py | 10 +- 3 files changed, 468 insertions(+), 87 deletions(-) diff --git a/instances/views.py b/instances/views.py index 911a9e5..1c8a650 100644 --- a/instances/views.py +++ b/instances/views.py @@ -120,7 +120,7 @@ def instance(request, compute_id, vname): {'dev': disk['dev'], 'storage': disk['storage'], 'image': image, 'format': disk['format']}) return clone_disk - errors = [] + error_messages = [] messages = [] compute = Compute.objects.get(id=compute_id) computes = Compute.objects.all() @@ -164,8 +164,8 @@ def instance(request, compute_id, vname): has_managed_save_image = conn.get_managed_save_image() clone_disks = show_clone_disk(disks) console_passwd = conn.get_console_passwd() - except libvirtError as err: - errors.append(err) + except libvirtError as lib_err: + error_messages.append(lib_err) try: instance = Instance.objects.get(compute_id=compute_id, name=vname) @@ -178,25 +178,19 @@ def instance(request, compute_id, vname): try: if request.method == 'POST': - if 'start' in request.POST: + if 'poweron' in request.POST: conn.start() - return HttpResponseRedirect(request.get_full_path() + '#shutdown') - if 'power' in request.POST: - if 'shutdown' == request.POST.get('power', ''): - conn.shutdown() - return HttpResponseRedirect(request.get_full_path() + '#shutdown') - if 'destroy' == request.POST.get('power', ''): - conn.force_shutdown() - return HttpResponseRedirect(request.get_full_path() + '#forceshutdown') - if 'managedsave' == request.POST.get('power', ''): - conn.managedsave() - return HttpResponseRedirect(request.get_full_path() + '#managedsave') - if 'deletesaveimage' in request.POST: - conn.managed_save_remove() - return HttpResponseRedirect(request.get_full_path() + '#managedsave') + return HttpResponseRedirect(request.get_full_path() + '#poweron') + if 'powercycle' in request.POST: + conn.force_shutdown() + conn.start() + return HttpResponseRedirect(request.get_full_path() + '#powercycle') + if 'poweroff' == request.POST.get('power', ''): + conn.shutdown() + return HttpResponseRedirect(request.get_full_path() + '#poweroff') if 'suspend' in request.POST: conn.suspend() - return HttpResponseRedirect(request.get_full_path() + '#suspend') + return HttpResponseRedirect(request.get_full_path() + '#resume') if 'resume' in request.POST: conn.resume() return HttpResponseRedirect(request.get_full_path() + '#suspend') @@ -204,13 +198,13 @@ def instance(request, compute_id, vname): if conn.get_status() == 1: conn.force_shutdown() try: - instance = Instance.objects.get(compute_id=host_id, name=vname) + instance = Instance.objects.get(compute_id=compute_id, name=vname) instance.delete() if request.POST.get('delete_disk', ''): conn.delete_disk() finally: conn.delete() - return HttpResponseRedirect(reverse('instances', args=[host_id])) + return HttpResponseRedirect(reverse('instances', args=[compute_id])) if 'snapshot' in request.POST: name = request.POST.get('name', '') conn.create_snapshot(name) @@ -231,7 +225,7 @@ def instance(request, compute_id, vname): if 'unset_autostart' in request.POST: conn.set_autostart(0) return HttpResponseRedirect(request.get_full_path() + '#instancesettings') - if 'change_settings' in request.POST: + if 'resize' in request.POST: description = request.POST.get('description', '') vcpu = request.POST.get('vcpu', '') cur_vcpu = request.POST.get('cur_vcpu', '') @@ -243,7 +237,7 @@ def instance(request, compute_id, vname): cur_memory_custom = request.POST.get('cur_memory_custom', '') if cur_memory_custom: cur_memory = cur_memory_custom - conn.change_settings(description, cur_memory, memory, cur_vcpu, vcpu) + conn.resize(cur_memory, memory, cur_vcpu, vcpu) return HttpResponseRedirect(request.get_full_path() + '#instancesettings') if 'change_xml' in request.POST: xml = request.POST.get('inst_xml', '') @@ -260,11 +254,11 @@ def instance(request, compute_id, vname): passwd = '' if not passwd and not clear: msg = _("Enter the console password or select Generate") - errors.append(msg) - if not errors: + error_messages.append(msg) + if not error_messages: if not conn.set_console_passwd(passwd): msg = _("Error setting console password. You should check that your instance have an graphic device.") - errors.append(msg) + error_messages.append(msg) else: return HttpResponseRedirect(request.get_full_path() + '#console_pass') @@ -315,11 +309,11 @@ def instance(request, compute_id, vname): clone_data[post] = request.POST.get(post, '') conn.clone_instance(clone_data) - return HttpResponseRedirect(reverse('instance', args=[host_id, clone_data['name']])) + return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']])) conn.close() except libvirtError as err: - errors.append(err) + error_messages.append(err) return render(request, 'instance.html', locals()) \ No newline at end of file diff --git a/templates/instance.html b/templates/instance.html index 8dd0e58..bce8855 100644 --- a/templates/instance.html +++ b/templates/instance.html @@ -109,14 +109,14 @@ {% ifequal status 3 %} {% endifequal %} {% ifequal status 5 %} {% endifequal %} @@ -159,7 +159,7 @@

{% trans "Click on Boot button to start this instance." %}

{% csrf_token %} - +
@@ -204,7 +204,68 @@
-

Resize Instance

+
{% csrf_token %} +

{% trans "Logical host CPUs:" %} {{ vcpu_host }}

+
+ +
+ +
+
+
+ +
+ +
+
+

{% trans "Total host memory:" %} {{ memory_host|filesizeformat }}

+
+ +
+ + + {% trans "Custom value" %} +
+
+
+ + +
+ + + {% trans "Custom value" %} +
+
+ {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+
@@ -231,8 +292,8 @@

{% trans "This may take more than an hour, depending on how much content is on your droplet and how large the disk is." %}

{% csrf_token %}
-
- +
+
{% ifequal status 5 %} @@ -249,45 +310,48 @@
{% ifequal status 5 %} {% if snapshots %} - - - - - - - - - - {% for snap in snapshots %} +

{% trans "Choose a snapshot for restore" %}

+
+
{% trans "Name" %}{% trans "Date" %}{% trans "Action" %}
+ - - - - + + + - {% endfor %} - -
{{ snap.name }}{{ snap.date|date:"M d H:i:s" }} - {% csrf_token %} - - {% ifequal status 5 %} - - {% else %} - - {% endifequal %} - - -
{% csrf_token %} - - -
-
{% trans "Name" %}{% trans "Date" %}{% trans "Action" %}
+ + + {% for snap in snapshots %} + + {{ snap.name }} + {{ snap.date|date:"M d H:i:s" }} + +
{% csrf_token %} + + {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+ + +
{% csrf_token %} + + +
+ + + {% endfor %} + + +
{% else %}

{% trans "You do not have any snapshots" %}

{% endif %} @@ -303,23 +367,275 @@
-
-

Autostart

+
+
{% csrf_token %} + {% for cd in media %} +
+ + {% if not cd.image %} +
+ +
+
+ {% if media_iso %} + + {% else %} + + {% endif %} +
+ {% else %} +
+

{{ cd.image }}

+
+
+ + +
+ {% endif %} +
+ {% endfor %} +
+
-
-

Cdrome

+
+

{% trans "Autostart your instance when host server is power on" %}

+
{% csrf_token %} + {% ifequal autostart 0 %} + + {% else %} + + {% endifequal %} +
+
+
+
+

{% trans "To set console's type, shutdown the instance." %}

+
{% csrf_token %} +
+ +
+ +
+
+ {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+
+
+

{% trans "To create console password, shutdown the instance." %}

+
{% csrf_token %} +
+
+
+ +
+
+ +
+
+
+
+ +
+ +
+ {% if console_passwd %} + {% trans "Show" %} + {% endif %} +
+ {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+
+
+

{% trans "To set console's keymap, shutdown the instance." %}

+
{% csrf_token %} +
+
+
+ +
+
+
+
+ +
+ +
+
+ {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+
+
+
+
+
+

{% trans "Create a clone" %}

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

{% trans "Network devices" %}

+ {% for network in networks %} +
+ +
+ +
+
+ +
+
+ {% endfor %} +

{% trans "Storage devices" %}

+ {% for disk in clone_disks %} +
+ +
+ +
+ {% ifequal disk.format 'qcow2' %} + +
+ +
+ {% endifequal %} +
+ {% endfor %} + {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+
+
+
+

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

+
{% csrf_token %} +
+ +
+

{{ compute.name }}

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ {% if computes_count != 1 %} + + {% else %} + + {% endif %} +
+

+
+
+

XML

@@ -355,7 +671,17 @@
-

Destroy Instance

+

{% trans "Delete storage for instance?" %}

+
{% csrf_token %} +
+ +
+ +
+
@@ -371,4 +697,73 @@ window.open('{% url 'console' %}?token={{ compute_id }}-{{ uuid }}', '', 'width=850,height=485') } + + + + {% endblock %} \ No newline at end of file diff --git a/vrtManager/instance.py b/vrtManager/instance.py index ceeb3f4..814eb92 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -470,7 +470,7 @@ class wvmInstance(wvmConnect): return util.get_xml_path(self._XMLDesc(VIR_DOMAIN_XML_SECURE), "/domain/devices/graphics/@keymap") or '' - def change_settings(self, description, cur_memory, memory, cur_vcpu, vcpu): + def resize(self, cur_memory, memory, cur_vcpu, vcpu): """ Function change ram and cpu on vds. """ @@ -484,18 +484,10 @@ class wvmInstance(wvmConnect): set_mem.text = str(memory) set_cur_mem = tree.find('currentMemory') set_cur_mem.text = str(cur_memory) - set_desc = tree.find('description') set_vcpu = tree.find('vcpu') set_vcpu.text = vcpu set_vcpu.set('current', cur_vcpu) - if not set_desc: - tree_desc = ElementTree.Element('description') - tree_desc.text = description - tree.insert(2, tree_desc) - else: - set_desc.text = description - new_xml = ElementTree.tostring(tree) self._defineXML(new_xml)