From 07a464231d541203c9baef9dd0e13b95f79a60eb Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 14 Sep 2017 02:24:10 +0530 Subject: [PATCH 01/27] animation added to vm termination --- hosting/static/hosting/css/landing-page.css | 3 + .../static/hosting/css/virtual-machine.css | 33 ++++++++ hosting/static/hosting/img/ajax-loader.gif | Bin 0 -> 404 bytes .../hosting/js/virtual_machine_detail.js | 38 ++++++++- .../hosting/includes/_navbar_user.html | 5 -- .../hosting/virtual_machine_detail.html | 35 ++++---- hosting/urls.py | 2 + hosting/views.py | 76 +++++++++++------- 8 files changed, 141 insertions(+), 51 deletions(-) create mode 100644 hosting/static/hosting/img/ajax-loader.gif diff --git a/hosting/static/hosting/css/landing-page.css b/hosting/static/hosting/css/landing-page.css index 71b7a33d..9d067b3c 100644 --- a/hosting/static/hosting/css/landing-page.css +++ b/hosting/static/hosting/css/landing-page.css @@ -853,6 +853,9 @@ a.list-group-item-danger:focus, .panel-danger > .panel-heading { color: #eb4d5c; } +.alert-danger{ + background: rgba(235, 204, 209, 0.2); +} .has-error .form-control, .has-error .input-group-addon { color: #eb4d5c; diff --git a/hosting/static/hosting/css/virtual-machine.css b/hosting/static/hosting/css/virtual-machine.css index b4916da0..b6afe4ef 100644 --- a/hosting/static/hosting/css/virtual-machine.css +++ b/hosting/static/hosting/css/virtual-machine.css @@ -290,6 +290,11 @@ text-align: center; } +.vm-vmid .alert { + margin-top: 15px; + margin-bottom: -60px; +} + .vm-item-lg { font-size: 22px; margin-top: 5px; @@ -305,6 +310,10 @@ color: #e47f2f; } +.vm-color-failed { + color: #eb4d5c; +} + .vm-detail-item .value{ font-weight: 400; } @@ -627,4 +636,28 @@ left: auto; right: 8px; } +} + +.processing > .btn { + position: relative; + border-color: #eee; +} +.processing > .btn:hover, +.processing > .btn:focus, +.processing > .btn:active { + border-color: #eee; +} + +.processing > .btn:after { + content: ' '; + display: block; + position: absolute; + background-image: url('/static/hosting/img/ajax-loader.gif'); + background-repeat: no-repeat; + background-position: center; + background-color: #eee; + width: 100%; + top: 0; + height: 100%; + left: 0; } \ No newline at end of file diff --git a/hosting/static/hosting/img/ajax-loader.gif b/hosting/static/hosting/img/ajax-loader.gif new file mode 100644 index 0000000000000000000000000000000000000000..a7c3f2bacbe630950c16f53e3c27dd840f2e8622 GIT binary patch literal 404 zcmZ?wbhEHb)Mnsj_{hNU?%lhzw6s;LRsl)He^Smxsfi`2DGKG8B^e5dS&0=n`H3ld znR#jX42nNl7`PZ17!?0=`?-b$J39ur8tEA@GXjNlfS3VfAOn+8OCQJSX*X{)e?H13 zeJ||u>DC8kZ4r?R)6{G4&Dyt|CtcU`diyE8Uq?3owA-;j!N^AxXd>8TMr31bj{uEP z;7?56IIHFOnwrlu67PNQNtrQY{;7pt&RzvNJJ_?&Ze06Pg>MsMs)$s6#HZT6Q+}5p z&C*E81%TGdiiN4(8Lw%U?wsno9F=b>WnG7*rn?>{@R)9v%+M)yIi1FiTcrX vD}VECG@HG3ZvWp+k0+)$$G&~0?NxTdRajt8g3>tw(O*m=3=Gzwa03GXAUBr* literal 0 HcmV?d00001 diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index 303f95ca..ce97d44e 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -2,7 +2,43 @@ $( document ).ready(function() { $('#confirm-cancel').on('click', '.btn-ok', function(e) { - $('#virtual_machine_cancel_form').trigger('submit'); + var url = $('#virtual_machine_cancel_form').attr('action'); + var $container = $('#terminate-VM'); + var $btn = $container.find('.btn'); + var text = $container.find('.vm-item-lg').text(); + var altText = $container.attr('data-alt'); + $container.find('.alert-danger').addClass('hide'); + $container.addClass('processing') + .find('.vm-item-lg').attr('class', '') + .addClass('vm-item-lg vm-color-failed') + .text(altText); + $btn.prop('disabled', true); + $('#confirm-cancel').modal('hide'); + $.post(url) + .done(function(data) { + console.log( "success" , data); + if (data.status == true) { + $container.addClass('terminate-success') + .find('.vm-item-lg').text(data.text); + $btn.remove(); + // window.location = data.redirect; + } + else { + $container.addClass('terminate-fail') + .find('.vm-item-lg').text(text); + $container.find('.btn').prop('disabled', false); + $container.find('.alert-danger').text(data.text).removeClass('hide'); + } + }) + .fail(function(data) { + $container.addClass('terminate-fail') + .find('.vm-item-lg').text(text); + $container.find('.btn').prop('disabled', false); + $container.find('.alert-danger').removeClass('hide'); + }) + .always(function(data) { + $container.removeClass('processing'); + }); }); var hash = window.location.hash; diff --git a/hosting/templates/hosting/includes/_navbar_user.html b/hosting/templates/hosting/includes/_navbar_user.html index d06477ca..37c01109 100644 --- a/hosting/templates/hosting/includes/_navbar_user.html +++ b/hosting/templates/hosting/includes/_navbar_user.html @@ -37,11 +37,6 @@
  • {% get_current_language as LANGUAGE_CODE %} - {% if LANGUAGE_CODE == 'en-us'%} -   Deutsch - {% else %} -   English - {% endif %}
  • diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index 6243c309..a5c82e90 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -46,26 +46,33 @@
    {% trans "Current Pricing" %}
    {{virtual_machine.price|floatformat}} CHF/{% trans "Month" %}
    - {% trans "See Invoice" %} + {% trans "See Invoice" %}

    {% trans "Status" %}

    {% trans "Your VM is" %}
    - {% if virtual_machine.state == 'PENDING' %} -
    {% trans "Pending" %}
    - {% elif virtual_machine.state == 'ACTIVE' %} -
    {% trans "Online" %}
    - {% elif virtual_machine.state == 'FAILED'%} -
    {% trans "Failed" %}
    - {% endif %} - {% if not virtual_machine.status == 'canceled' %} -
    - {% csrf_token %} -
    - - {% endif %} +
    + {% if virtual_machine.state == 'PENDING' %} +
    {% trans "Pending" %}
    + {% elif virtual_machine.state == 'ACTIVE' %} +
    {% trans "Online" %}
    + {% elif virtual_machine.state == 'FAILED'%} +
    {% trans "Failed" %}
    + {% else %} +
    + {% endif %} + {% if not virtual_machine.status == 'canceled' %} +
    + {% csrf_token %} +
    + +
    + {% trans "Sorry, there was an unexpected error. Kindly retry." %} +
    + {% endif %} +
    diff --git a/hosting/urls.py b/hosting/urls.py index 10e09dd0..c3b982cb 100644 --- a/hosting/urls.py +++ b/hosting/urls.py @@ -10,9 +10,11 @@ from .views import ( HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView, SSHKeyChoiceView, DashboardView, SettingsView) +from django.views.generic import TemplateView urlpatterns = [ + url(r'test/?$', TemplateView.as_view(template_name='hosting/virtual_machine_detail.html')), url(r'index/?$', IndexView.as_view(), name='index'), url(r'django/?$', DjangoHostingView.as_view(), name='djangohosting'), url(r'dashboard/?$', DashboardView.as_view(), name='dashboard'), diff --git a/hosting/views.py b/hosting/views.py index f7d6e414..df6e6100 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1,4 +1,6 @@ import uuid +import json +from time import sleep from django.conf import settings from django.contrib import messages @@ -6,13 +8,12 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.tokens import default_token_generator from django.core.files.base import ContentFile from django.core.urlresolvers import reverse_lazy, reverse -from django.http import Http404 -from django.http import HttpResponseRedirect -from django.shortcuts import redirect -from django.shortcuts import render +from django.http import Http404, HttpResponseRedirect, HttpResponse +from django.shortcuts import redirect, render from django.utils.http import urlsafe_base64_decode from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext from django.views.generic import View, CreateView, FormView, ListView, \ DetailView, \ DeleteView, TemplateView, UpdateView @@ -711,7 +712,7 @@ class PaymentVMView(LoginRequiredMixin, FormView): request.get_host()), 'page_header': _( 'Your New VM %(vm_name)s at Data Center Light') % { - 'vm_name': vm.get('name')} + 'vm_name': vm.get('name')} } email_data = { 'subject': context.get('page_header'), @@ -924,6 +925,7 @@ class VirtualMachineView(LoginRequiredMixin, View): return render(request, self.template_name, context) def post(self, request, *args, **kwargs): + response = {} owner = self.request.user vm = self.get_object() @@ -934,41 +936,53 @@ class VirtualMachineView(LoginRequiredMixin, View): password=owner.password ) vm_data = VirtualMachineSerializer(manager.get_vm(vm.id)).data - terminated = manager.delete_vm( - vm.id - ) + + terminated = manager.delete_vm(vm.id) if not terminated: messages.error( request, 'Error terminating VM %s' % (opennebula_vm_id) ) - return HttpResponseRedirect(self.get_success_url()) - context = { - 'vm': vm_data, - 'base_url': "{0}://{1}".format(self.request.scheme, - self.request.get_host()), - 'page_header': _('Virtual Machine Cancellation') - } - email_data = { - 'subject': context['page_header'], - 'to': self.request.user.email, - 'context': context, - 'template_name': 'vm_canceled', - 'template_path': 'hosting/emails/', - 'from_address': settings.DCL_SUPPORT_FROM_ADDRESS, - } - email = BaseEmail(**email_data) - email.send() + response['status'] = False + else: + context = { + 'vm': vm_data, + 'base_url': "{0}://{1}".format(self.request.scheme, + self.request.get_host()), + 'page_header': _('Virtual Machine Cancellation') + } + email_data = { + 'subject': context['page_header'], + 'to': self.request.user.email, + 'context': context, + 'template_name': 'vm_canceled', + 'template_path': 'hosting/emails/', + 'from_address': settings.DCL_SUPPORT_FROM_ADDRESS, + } + email = BaseEmail(**email_data) + email.send() - messages.error( - request, - _('VM %(VM_ID)s terminated successfully') % { - 'VM_ID': opennebula_vm_id} + # messages.error( + # request, + # _('VM %(VM_ID)s terminated successfully') % { + # 'VM_ID': opennebula_vm_id} + # ) + deleting = True + t = 0 + while deleting: + if t < 150 and manager.get_vm(self.kwargs.get('pk')): + sleep(2) + else: + deleting = False + response['status'] = True + response['redirect'] = self.get_success_url() + response['text'] = ugettext('Terminated') + return HttpResponse( + json.dumps(response), + content_type="application/json" ) - return HttpResponseRedirect(self.get_success_url()) - class HostingBillListView(PermissionRequiredMixin, LoginRequiredMixin, ListView): From 8ca1b13f80a70c7ed1bdf29836d60ae3e302b1b9 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 14 Sep 2017 02:29:51 +0530 Subject: [PATCH 02/27] template fixed --- hosting/templates/hosting/virtual_machine_detail.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index a5c82e90..d0bfae47 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -46,7 +46,7 @@
    {% trans "Current Pricing" %}
    {{virtual_machine.price|floatformat}} CHF/{% trans "Month" %}
    - {% trans "See Invoice" %} + {% trans "See Invoice" %}
    @@ -64,7 +64,7 @@
    {% endif %} {% if not virtual_machine.status == 'canceled' %} -
    + {% csrf_token %}
    From abc290de61c748a22f0ae85d5ffe8820ff9d455d Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 14 Sep 2017 02:43:01 +0530 Subject: [PATCH 03/27] added error msg --- hosting/views.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index df6e6100..ca80a8d1 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -940,11 +940,8 @@ class VirtualMachineView(LoginRequiredMixin, View): terminated = manager.delete_vm(vm.id) if not terminated: - messages.error( - request, - 'Error terminating VM %s' % (opennebula_vm_id) - ) response['status'] = False + response['text'] = 'Error terminating VM %s' % (opennebula_vm_id) else: context = { 'vm': vm_data, From a808f3bf7e2173fbf44e0521591981f2e38e4d57 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 14 Sep 2017 02:48:56 +0530 Subject: [PATCH 04/27] error fix on termination --- hosting/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index ca80a8d1..685fe0b4 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -965,13 +965,17 @@ class VirtualMachineView(LoginRequiredMixin, View): # _('VM %(VM_ID)s terminated successfully') % { # 'VM_ID': opennebula_vm_id} # ) - deleting = True t = 0 - while deleting: - if t < 150 and manager.get_vm(self.kwargs.get('pk')): - sleep(2) + while True: + if t > 150: + break + try: + manager.get_vm(self.kwargs.get('pk')) + except: + break else: - deleting = False + sleep(2) + response['status'] = True response['redirect'] = self.get_success_url() response['text'] = ugettext('Terminated') From e045caebbe6f704b6a95fc7763365de1c2e18a2e Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 14 Sep 2017 02:52:37 +0530 Subject: [PATCH 05/27] redirect on success --- hosting/static/hosting/js/virtual_machine_detail.js | 2 +- hosting/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index ce97d44e..076ec344 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -21,7 +21,7 @@ $( document ).ready(function() { $container.addClass('terminate-success') .find('.vm-item-lg').text(data.text); $btn.remove(); - // window.location = data.redirect; + window.location = data.redirect; } else { $container.addClass('terminate-fail') diff --git a/hosting/views.py b/hosting/views.py index 685fe0b4..cf17c9f8 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -971,7 +971,7 @@ class VirtualMachineView(LoginRequiredMixin, View): break try: manager.get_vm(self.kwargs.get('pk')) - except: + except BaseException: break else: sleep(2) From 8393afe1418408b8cfac9c7d71c608e10b446293 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 14 Sep 2017 02:59:08 +0530 Subject: [PATCH 06/27] translations and test methods removed --- hosting/locale/de/LC_MESSAGES/django.po | 21 +++++++++++++++++---- hosting/urls.py | 3 --- hosting/views.py | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hosting/locale/de/LC_MESSAGES/django.po b/hosting/locale/de/LC_MESSAGES/django.po index 780419b1..2f6cee4e 100644 --- a/hosting/locale/de/LC_MESSAGES/django.po +++ b/hosting/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-09 06:04+0000\n" +"POT-Creation-Date: 2017-09-14 02:55+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -524,6 +524,9 @@ msgstr "Aktueller Preis" msgid "Your VM is" msgstr "Deine VM ist" +msgid "Terminating" +msgstr "Beenden" + msgid "Pending" msgstr "In Vorbereitung" @@ -536,6 +539,11 @@ msgstr "Fehlgeschlagen" msgid "Terminate VM" msgstr "VM Beenden" +msgid "Sorry, there was an unexpected error. Kindly retry." +msgstr "" +"Bitte entschuldige, es scheint ein unerwarteter Fehler aufgetreten zu sein. " +"Versuche es doch bitte noch einmal." + msgid "Something doesn't work?" msgstr "Etwas funktioniert nicht?" @@ -624,12 +632,17 @@ msgid "" "contact Data Center Light Support." msgstr "Kontaktiere den Data Center Light Support." +msgid "Error terminating VM" +msgstr "Fehler beenden VM" + msgid "Virtual Machine Cancellation" msgstr "VM Kündigung" -#, python-format -msgid "VM %(VM_ID)s terminated successfully" -msgstr "VM %(VM_ID)s erfolgreich beendet" +msgid "Terminated" +msgstr "Beendet" + +#~ msgid "VM %(VM_ID)s terminated successfully" +#~ msgstr "VM %(VM_ID)s erfolgreich beendet" #~ msgid "My Virtual Machines" #~ msgstr "Meine virtuellen Maschinen" diff --git a/hosting/urls.py b/hosting/urls.py index c3b982cb..455aa97f 100644 --- a/hosting/urls.py +++ b/hosting/urls.py @@ -10,11 +10,8 @@ from .views import ( HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView, SSHKeyChoiceView, DashboardView, SettingsView) -from django.views.generic import TemplateView - urlpatterns = [ - url(r'test/?$', TemplateView.as_view(template_name='hosting/virtual_machine_detail.html')), url(r'index/?$', IndexView.as_view(), name='index'), url(r'django/?$', DjangoHostingView.as_view(), name='djangohosting'), url(r'dashboard/?$', DashboardView.as_view(), name='dashboard'), diff --git a/hosting/views.py b/hosting/views.py index cf17c9f8..4d9aeb18 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -941,7 +941,8 @@ class VirtualMachineView(LoginRequiredMixin, View): if not terminated: response['status'] = False - response['text'] = 'Error terminating VM %s' % (opennebula_vm_id) + response['text'] = ugettext( + 'Error terminating VM') + opennebula_vm_id else: context = { 'vm': vm_data, From a1a90ed5d0a79940fc1528d2e7ec061e4a3323d4 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 00:14:09 +0530 Subject: [PATCH 07/27] while loop code formating --- hosting/views.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 4d9aeb18..290d5f0f 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -968,14 +968,16 @@ class VirtualMachineView(LoginRequiredMixin, View): # ) t = 0 while True: - if t > 150: - break - try: - manager.get_vm(self.kwargs.get('pk')) - except BaseException: - break + if t < 150: + t += 1 + try: + manager.get_vm(self.kwargs.get('pk')) + except BaseException: + break + else: + sleep(2) else: - sleep(2) + break response['status'] = True response['redirect'] = self.get_success_url() From a935871722f530f0ac08e2b658cf58315db5df0e Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 00:57:59 +0530 Subject: [PATCH 08/27] code reformating --- .../hosting/js/virtual_machine_detail.js | 96 +++++++++---------- hosting/views.py | 28 ++---- 2 files changed, 56 insertions(+), 68 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index 076ec344..898ecbaa 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -1,54 +1,52 @@ +$(document).ready(function() { -$( document ).ready(function() { + $('#confirm-cancel').on('click', '.btn-ok', function(e) { + var url = $('#virtual_machine_cancel_form').attr('action'); + var $container = $('#terminate-VM'); + var $btn = $container.find('.btn'); + var text = $container.find('.vm-item-lg').text(); + var altText = $container.attr('data-alt'); + $container.find('.alert-danger').addClass('hide'); + $container.addClass('processing') + .find('.vm-item-lg').attr('class', '') + .addClass('vm-item-lg vm-color-failed') + .text(altText); + $btn.prop('disabled', true); + $('#confirm-cancel').modal('hide'); + $.post(url) + .done(function(data) { + console.log("success", data); + if (data.status == true) { + $container.addClass('terminate-success') + .find('.vm-item-lg').text(data.text); + $btn.remove(); + window.location = data.redirect; + } else { + $container.addClass('terminate-fail') + .find('.vm-item-lg').text(text); + $container.find('.btn').prop('disabled', false); + $container.find('.alert-danger').text(data.text).removeClass('hide'); + } + }) + .fail(function(data) { + $container.addClass('terminate-fail') + .find('.vm-item-lg').text(text); + $container.find('.btn').prop('disabled', false); + $container.find('.alert-danger').removeClass('hide'); + }) + .always(function(data) { + $container.removeClass('processing'); + }); + }); - $('#confirm-cancel').on('click', '.btn-ok', function(e) { - var url = $('#virtual_machine_cancel_form').attr('action'); - var $container = $('#terminate-VM'); - var $btn = $container.find('.btn'); - var text = $container.find('.vm-item-lg').text(); - var altText = $container.attr('data-alt'); - $container.find('.alert-danger').addClass('hide'); - $container.addClass('processing') - .find('.vm-item-lg').attr('class', '') - .addClass('vm-item-lg vm-color-failed') - .text(altText); - $btn.prop('disabled', true); - $('#confirm-cancel').modal('hide'); - $.post(url) - .done(function(data) { - console.log( "success" , data); - if (data.status == true) { - $container.addClass('terminate-success') - .find('.vm-item-lg').text(data.text); - $btn.remove(); - window.location = data.redirect; - } - else { - $container.addClass('terminate-fail') - .find('.vm-item-lg').text(text); - $container.find('.btn').prop('disabled', false); - $container.find('.alert-danger').text(data.text).removeClass('hide'); - } - }) - .fail(function(data) { - $container.addClass('terminate-fail') - .find('.vm-item-lg').text(text); - $container.find('.btn').prop('disabled', false); - $container.find('.alert-danger').removeClass('hide'); - }) - .always(function(data) { - $container.removeClass('processing'); - }); - }); + var hash = window.location.hash; + hash && $('ul.nav a[href="' + hash + '"]').tab('show'); - var hash = window.location.hash; - hash && $('ul.nav a[href="' + hash + '"]').tab('show'); - - $('.nav-tabs a').click(function (e) { - $(this).tab('show'); - var scrollmem = $('body').scrollTop() || $('html').scrollTop(); - window.location.hash = this.hash; - $('html,body').scrollTop(scrollmem); - }); + $('.nav-tabs a').click(function(e) { + $(this).tab('show'); + var scrollmem = $('body').scrollTop() || $('html').scrollTop(); + window.location.hash = this.hash; + $('html,body').scrollTop(scrollmem); + }); }); \ No newline at end of file diff --git a/hosting/views.py b/hosting/views.py index ed85dbdb..f25d6567 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -957,6 +957,14 @@ class VirtualMachineView(LoginRequiredMixin, View): response['text'] = ugettext( 'Error terminating VM') + opennebula_vm_id else: + for t in range(150): + try: + manager.get_vm(self.kwargs.get('pk')) + except BaseException: + break + else: + sleep(2) + context = { 'vm': vm_data, 'base_url': "{0}://{1}".format(self.request.scheme, @@ -973,28 +981,10 @@ class VirtualMachineView(LoginRequiredMixin, View): } email = BaseEmail(**email_data) email.send() - - # messages.error( - # request, - # _('VM %(VM_ID)s terminated successfully') % { - # 'VM_ID': opennebula_vm_id} - # ) - t = 0 - while True: - if t < 150: - t += 1 - try: - manager.get_vm(self.kwargs.get('pk')) - except BaseException: - break - else: - sleep(2) - else: - break - response['status'] = True response['redirect'] = self.get_success_url() response['text'] = ugettext('Terminated') + return HttpResponse( json.dumps(response), content_type="application/json" From 75156d2c00389bf2e15a38202f90a68e844a85d1 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 01:00:07 +0530 Subject: [PATCH 09/27] undo changes in navbar --- hosting/templates/hosting/includes/_navbar_user.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hosting/templates/hosting/includes/_navbar_user.html b/hosting/templates/hosting/includes/_navbar_user.html index 37c01109..d06477ca 100644 --- a/hosting/templates/hosting/includes/_navbar_user.html +++ b/hosting/templates/hosting/includes/_navbar_user.html @@ -37,6 +37,11 @@
  • {% get_current_language as LANGUAGE_CODE %} + {% if LANGUAGE_CODE == 'en-us'%} +   Deutsch + {% else %} +   English + {% endif %}
  • From 852c1228bad339bdfbe5939fa4a2cbe39258d4a3 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 14:48:11 +0530 Subject: [PATCH 10/27] minor fix --- hosting/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index f25d6567..f5780aed 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -957,7 +957,7 @@ class VirtualMachineView(LoginRequiredMixin, View): response['text'] = ugettext( 'Error terminating VM') + opennebula_vm_id else: - for t in range(150): + for t in range(50): try: manager.get_vm(self.kwargs.get('pk')) except BaseException: From 6136a48961b0b17146cffdb4298fa788a15ed1fa Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 16:46:56 +0530 Subject: [PATCH 11/27] edge cases handled --- .../hosting/js/virtual_machine_detail.js | 74 +++++++++++++------ hosting/views.py | 19 ++--- 2 files changed, 62 insertions(+), 31 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index 898ecbaa..0485bc36 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -1,42 +1,72 @@ +function VMTerminateStatus($container, url) { + $.get(url) + .done(function(data) { + setTimeout(function(){ + VMTerminateStatus($container, url); + }, 2000); + }) + .fail(function(data) { + VMTerminateSuccess($container, data) + window.location.reload(true); + }); +} + +function VMTerminateActive($container, altText) { + $container.find('.alert-danger').addClass('hide'); + $container.addClass('processing') + .find('.vm-item-lg').attr('class', '') + .addClass('vm-item-lg vm-color-failed') + .text(altText); + $container.find('.btn').prop('disabled', true); + $('#confirm-cancel').modal('hide'); +} + +function VMTerminateSuccess($container, data) { + $container.addClass('terminate-success') + .find('.vm-item-lg').text(data.text); + $container.find('.btn').remove(); +} + +function VMTerminateFail($container, data, text) { + $container.addClass('terminate-fail') + .find('.vm-item-lg').text(text); + $container.find('.btn').prop('disabled', false); + $container.find('.alert-danger').text(data.text).removeClass('hide'); + $container.removeClass('processing'); +} + + $(document).ready(function() { $('#confirm-cancel').on('click', '.btn-ok', function(e) { var url = $('#virtual_machine_cancel_form').attr('action'); var $container = $('#terminate-VM'); - var $btn = $container.find('.btn'); var text = $container.find('.vm-item-lg').text(); var altText = $container.attr('data-alt'); - $container.find('.alert-danger').addClass('hide'); - $container.addClass('processing') - .find('.vm-item-lg').attr('class', '') - .addClass('vm-item-lg vm-color-failed') - .text(altText); - $btn.prop('disabled', true); - $('#confirm-cancel').modal('hide'); + VMTerminateActive($container, altText); + $.post(url) .done(function(data) { console.log("success", data); if (data.status == true) { - $container.addClass('terminate-success') - .find('.vm-item-lg').text(data.text); - $btn.remove(); + VMTerminateSuccess($container, data); window.location = data.redirect; } else { - $container.addClass('terminate-fail') - .find('.vm-item-lg').text(text); - $container.find('.btn').prop('disabled', false); - $container.find('.alert-danger').text(data.text).removeClass('hide'); + if ('text' in data) { + VMTerminateFail($container, data, text); + } else { + VMTerminateStatus($container, url); + } } }) .fail(function(data) { - $container.addClass('terminate-fail') - .find('.vm-item-lg').text(text); - $container.find('.btn').prop('disabled', false); - $container.find('.alert-danger').removeClass('hide'); + console.log(data) + if (data.status==504) { + VMTerminateStatus($container, url); + } else { + VMTerminateFail($container, data, text); + } }) - .always(function(data) { - $container.removeClass('processing'); - }); }); var hash = window.location.hash; diff --git a/hosting/views.py b/hosting/views.py index f5780aed..848ac9e8 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -923,7 +923,10 @@ class VirtualMachineView(LoginRequiredMixin, View): def get(self, request, *args, **kwargs): vm = self.get_object() if vm is None: - return redirect(reverse('hosting:virtual_machines')) + if self.request.is_ajax(): + raise Http404() + else: + return redirect(reverse('hosting:virtual_machines')) try: serializer = VirtualMachineSerializer(vm) context = { @@ -938,7 +941,7 @@ class VirtualMachineView(LoginRequiredMixin, View): return render(request, self.template_name, context) def post(self, request, *args, **kwargs): - response = {} + response = {'status': False} owner = self.request.user vm = self.get_object() @@ -948,23 +951,25 @@ class VirtualMachineView(LoginRequiredMixin, View): email=owner.email, password=owner.password ) + vm_data = VirtualMachineSerializer(manager.get_vm(vm.id)).data terminated = manager.delete_vm(vm.id) if not terminated: - response['status'] = False response['text'] = ugettext( 'Error terminating VM') + opennebula_vm_id else: - for t in range(50): + for t in range(15): try: manager.get_vm(self.kwargs.get('pk')) except BaseException: + response['status'] = True + response['redirect'] = self.get_success_url() + response['text'] = ugettext('Terminated') break else: sleep(2) - context = { 'vm': vm_data, 'base_url': "{0}://{1}".format(self.request.scheme, @@ -981,10 +986,6 @@ class VirtualMachineView(LoginRequiredMixin, View): } email = BaseEmail(**email_data) email.send() - response['status'] = True - response['redirect'] = self.get_success_url() - response['text'] = ugettext('Terminated') - return HttpResponse( json.dumps(response), content_type="application/json" From fdb5039c029c59ae177fdc9f71d9429e5919256f Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 16:57:17 +0530 Subject: [PATCH 12/27] minor adjustments --- hosting/static/hosting/css/virtual-machine.css | 3 +++ hosting/static/hosting/js/virtual_machine_detail.js | 2 +- hosting/views.py | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hosting/static/hosting/css/virtual-machine.css b/hosting/static/hosting/css/virtual-machine.css index b6afe4ef..48932350 100644 --- a/hosting/static/hosting/css/virtual-machine.css +++ b/hosting/static/hosting/css/virtual-machine.css @@ -530,6 +530,9 @@ .vm-status-failed { color: #eb4d5c; } +.vm-status-failed { + color: #e47f2f; +} @media (min-width:768px) { .dashboard-subtitle { diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index 0485bc36..df401ebe 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -3,7 +3,7 @@ function VMTerminateStatus($container, url) { .done(function(data) { setTimeout(function(){ VMTerminateStatus($container, url); - }, 2000); + }, 4000); }) .fail(function(data) { VMTerminateSuccess($container, data) diff --git a/hosting/views.py b/hosting/views.py index 848ac9e8..77c4b8dc 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -924,6 +924,8 @@ class VirtualMachineView(LoginRequiredMixin, View): vm = self.get_object() if vm is None: if self.request.is_ajax(): + storage = messages.get_messages(request) + storage.used = True raise Http404() else: return redirect(reverse('hosting:virtual_machines')) From 0c3f60573568d7a18620f9c125fd767c2af791d9 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 17:02:02 +0530 Subject: [PATCH 13/27] status pending style in vm-list --- hosting/static/hosting/css/virtual-machine.css | 4 ++-- hosting/templates/hosting/virtual_machines.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hosting/static/hosting/css/virtual-machine.css b/hosting/static/hosting/css/virtual-machine.css index 48932350..a14abc31 100644 --- a/hosting/static/hosting/css/virtual-machine.css +++ b/hosting/static/hosting/css/virtual-machine.css @@ -521,7 +521,7 @@ color: #87B6EA; } -.vm-status, .vm-status-active, .vm-status-failed { +.vm-status, .vm-status-active, .vm-status-failed, .vm-status-pending { font-weight: 600; } .vm-status-active { @@ -530,7 +530,7 @@ .vm-status-failed { color: #eb4d5c; } -.vm-status-failed { +.vm-status-pending { color: #e47f2f; } diff --git a/hosting/templates/hosting/virtual_machines.html b/hosting/templates/hosting/virtual_machines.html index f7461abe..da8c79a5 100644 --- a/hosting/templates/hosting/virtual_machines.html +++ b/hosting/templates/hosting/virtual_machines.html @@ -46,7 +46,7 @@ {% elif vm.state == 'FAILED' %} {{vm.state|title}} {% else %} - {{vm.state|title}} + {{vm.state|title}} {% endif %} From 77f2454e3cc1b1c1480e1e46ae2646cd7bc771d6 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 17:20:42 +0530 Subject: [PATCH 14/27] remove error msg on successful termination --- .../hosting/js/virtual_machine_detail.js | 18 ++++++++++-------- hosting/views.py | 7 ++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index df401ebe..47080cd4 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -1,14 +1,16 @@ function VMTerminateStatus($container, url) { - $.get(url) - .done(function(data) { + $.ajax({ + url: url, + dataType: 'json', + success: function(data) { + VMTerminateSuccess($container, data); + }, + error: function() { setTimeout(function(){ VMTerminateStatus($container, url); }, 4000); - }) - .fail(function(data) { - VMTerminateSuccess($container, data) - window.location.reload(true); - }); + } + }); } function VMTerminateActive($container, altText) { @@ -25,6 +27,7 @@ function VMTerminateSuccess($container, data) { $container.addClass('terminate-success') .find('.vm-item-lg').text(data.text); $container.find('.btn').remove(); + window.location = data.redirect; } function VMTerminateFail($container, data, text) { @@ -50,7 +53,6 @@ $(document).ready(function() { console.log("success", data); if (data.status == true) { VMTerminateSuccess($container, data); - window.location = data.redirect; } else { if ('text' in data) { VMTerminateFail($container, data, text); diff --git a/hosting/views.py b/hosting/views.py index 77c4b8dc..072ada8e 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -926,9 +926,14 @@ class VirtualMachineView(LoginRequiredMixin, View): if self.request.is_ajax(): storage = messages.get_messages(request) storage.used = True - raise Http404() + return HttpResponse( + json.dumps({'redirect': self.get_success_url()}), + content_type="application/json" + ) else: return redirect(reverse('hosting:virtual_machines')) + elif self.request.is_ajax(): + return HttpResponse() try: serializer = VirtualMachineSerializer(vm) context = { From bbb1919404085b145a95e00f58a4ee2e4f37f9db Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 17:38:52 +0530 Subject: [PATCH 15/27] error msg fix --- hosting/static/hosting/js/virtual_machine_detail.js | 2 -- hosting/views.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index 47080cd4..29b08cda 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -50,7 +50,6 @@ $(document).ready(function() { $.post(url) .done(function(data) { - console.log("success", data); if (data.status == true) { VMTerminateSuccess($container, data); } else { @@ -62,7 +61,6 @@ $(document).ready(function() { } }) .fail(function(data) { - console.log(data) if (data.status==504) { VMTerminateStatus($container, url); } else { diff --git a/hosting/views.py b/hosting/views.py index 072ada8e..201f590a 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -925,6 +925,8 @@ class VirtualMachineView(LoginRequiredMixin, View): if vm is None: if self.request.is_ajax(): storage = messages.get_messages(request) + for m in storage: + pass storage.used = True return HttpResponse( json.dumps({'redirect': self.get_success_url()}), From 9c0cefd41968ef03b65dacb6572accc702fdd277 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 17:44:27 +0530 Subject: [PATCH 16/27] js polling timing to 5s --- hosting/static/hosting/js/virtual_machine_detail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index 29b08cda..d6387dbc 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -8,7 +8,7 @@ function VMTerminateStatus($container, url) { error: function() { setTimeout(function(){ VMTerminateStatus($container, url); - }, 4000); + }, 5000); } }); } From d49e90bd209868b710f6f4d61a45c146482cc5ff Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 18:15:06 +0530 Subject: [PATCH 17/27] catching WrongIdError --- hosting/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index 201f590a..acd7e67b 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -972,10 +972,13 @@ class VirtualMachineView(LoginRequiredMixin, View): for t in range(15): try: manager.get_vm(self.kwargs.get('pk')) - except BaseException: + except WrongIdError: response['status'] = True response['redirect'] = self.get_success_url() response['text'] = ugettext('Terminated') + self.send_mail() + break + except BaseException: break else: sleep(2) From 226f744bae4307c6b4fd984614340430d1a61d69 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Mon, 18 Sep 2017 21:52:59 +0530 Subject: [PATCH 18/27] success modal added --- .../hosting/js/virtual_machine_detail.js | 2 +- .../hosting/virtual_machine_detail.html | 19 ++++++++++++++++++- hosting/views.py | 12 ++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index d6387dbc..711b486b 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -27,7 +27,7 @@ function VMTerminateSuccess($container, data) { $container.addClass('terminate-success') .find('.vm-item-lg').text(data.text); $container.find('.btn').remove(); - window.location = data.redirect; + $('#terminate-success').modal('show'); } function VMTerminateFail($container, data, text) { diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index d0bfae47..9d77c31d 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -103,7 +103,7 @@ + + + {%endblock%} diff --git a/hosting/views.py b/hosting/views.py index acd7e67b..8356d5ad 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -961,7 +961,13 @@ class VirtualMachineView(LoginRequiredMixin, View): password=owner.password ) - vm_data = VirtualMachineSerializer(manager.get_vm(vm.id)).data + try: + vm_data = VirtualMachineSerializer(manager.get_vm(vm.id)).data + except BaseException: + return redirect( + reverse('hosting:virtual_machines', + kwargs={'pk': opennebula_vm_id}) + ) terminated = manager.delete_vm(vm.id) @@ -971,12 +977,10 @@ class VirtualMachineView(LoginRequiredMixin, View): else: for t in range(15): try: - manager.get_vm(self.kwargs.get('pk')) + manager.get_vm(opennebula_vm_id) except WrongIdError: response['status'] = True - response['redirect'] = self.get_success_url() response['text'] = ugettext('Terminated') - self.send_mail() break except BaseException: break From 43300c72269faa80983c38aa43a20ccd3f1f4d4f Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Mon, 18 Sep 2017 23:21:04 +0530 Subject: [PATCH 19/27] translations added, modal fixed --- hosting/locale/de/LC_MESSAGES/django.po | 20 +++++++++------ .../hosting/js/virtual_machine_detail.js | 1 - .../hosting/virtual_machine_detail.html | 25 +++++++++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/hosting/locale/de/LC_MESSAGES/django.po b/hosting/locale/de/LC_MESSAGES/django.po index 1c0f3faa..ca78a381 100644 --- a/hosting/locale/de/LC_MESSAGES/django.po +++ b/hosting/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-14 12:27+0000\n" +"POT-Creation-Date: 2017-09-18 23:16+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -575,6 +575,15 @@ msgstr "Bist Du sicher, dass Du Deine virtuelle Maschine beenden willst" msgid "OK" msgstr "" +msgid "Your Virtual Machine" +msgstr "Deine Maschinen Detail" + +msgid "was successfully terminated!" +msgstr "wurde erfolgreich beendet!" + +msgid "Close" +msgstr "Schliessen" + msgid "Virtual Machines" msgstr "Virtuelle Maschinen" @@ -645,12 +654,12 @@ msgstr "Kontaktiere den Data Center Light Support." msgid "Error terminating VM" msgstr "Fehler beenden VM" -msgid "Virtual Machine Cancellation" -msgstr "VM Kündigung" - msgid "Terminated" msgstr "Beendet" +msgid "Virtual Machine Cancellation" +msgstr "VM Kündigung" + #~ msgid "VM %(VM_ID)s terminated successfully" #~ msgstr "VM %(VM_ID)s erfolgreich beendet" @@ -702,9 +711,6 @@ msgstr "Beendet" #~ msgid "Ipv6" #~ msgstr "IPv6" -#~ msgid "Close" -#~ msgstr "Schliessen" - #~ msgid "Cancel" #~ msgstr "Beenden" diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index 711b486b..e611246b 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -40,7 +40,6 @@ function VMTerminateFail($container, data, text) { $(document).ready(function() { - $('#confirm-cancel').on('click', '.btn-ok', function(e) { var url = $('#virtual_machine_cancel_form').attr('action'); var $container = $('#terminate-VM'); diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index 9d77c31d..08872c1e 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -96,24 +96,24 @@ @@ -123,10 +123,13 @@ From 8db7ead9e272e2c9536c31e245d2765915bcf1c3 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Tue, 19 Sep 2017 00:24:06 +0530 Subject: [PATCH 20/27] checking VM termination error --- hosting/views.py | 5 +++-- opennebula_api/models.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 8356d5ad..5f123dd4 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -969,11 +969,12 @@ class VirtualMachineView(LoginRequiredMixin, View): kwargs={'pk': opennebula_vm_id}) ) - terminated = manager.delete_vm(vm.id) + terminated, err = manager.delete_vm(vm.id) if not terminated: response['text'] = ugettext( - 'Error terminating VM') + opennebula_vm_id + 'Error terminating VM') + opennebula_vm_id + '\n' + + err else: for t in range(15): try: diff --git a/opennebula_api/models.py b/opennebula_api/models.py index d584bf26..9eb89fdf 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -324,6 +324,7 @@ class OpenNebulaManager(): def delete_vm(self, vm_id): TERMINATE_ACTION = 'terminate' vm_terminated = False + err = '' try: self.oneadmin_client.call( oca.VirtualMachine.METHODS['action'], @@ -333,15 +334,19 @@ class OpenNebulaManager(): vm_terminated = True except socket.timeout as socket_err: logger.info("Socket timeout error: {0}".format(socket_err)) + err = ("Socket timeout error: {0}".format(socket_err)) except OpenNebulaException as opennebula_err: logger.info( "OpenNebulaException error: {0}".format(opennebula_err)) + err = ("OpenNebulaException error: {0}".format(opennebula_err)) except OSError as os_err: logger.info("OSError : {0}".format(os_err)) + err = ("OSError : {0}".format(os_err)) except ValueError as value_err: logger.info("ValueError : {0}".format(value_err)) + err = ("ValueError : {0}".format(value_err)) - return vm_terminated + return (vm_terminated, err) def _get_template_pool(self): try: From 61bf15823861fd45a06b0cafdf399ff73d4189ac Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Tue, 19 Sep 2017 00:25:38 +0530 Subject: [PATCH 21/27] fix --- hosting/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 5f123dd4..8e01bb22 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -973,8 +973,7 @@ class VirtualMachineView(LoginRequiredMixin, View): if not terminated: response['text'] = ugettext( - 'Error terminating VM') + opennebula_vm_id + '\n' + - err + 'Error terminating VM') + opennebula_vm_id + '\n' + err else: for t in range(15): try: From 78423c83e3721da584f917ea6521969e38d68d5d Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Tue, 19 Sep 2017 00:59:51 +0530 Subject: [PATCH 22/27] removed error details from error msg --- hosting/static/hosting/js/virtual_machine_detail.js | 1 + hosting/views.py | 4 ++-- opennebula_api/models.py | 7 +------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index e611246b..76c00a91 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -1,6 +1,7 @@ function VMTerminateStatus($container, url) { $.ajax({ url: url, + type: 'GET', dataType: 'json', success: function(data) { VMTerminateSuccess($container, data); diff --git a/hosting/views.py b/hosting/views.py index 8e01bb22..8356d5ad 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -969,11 +969,11 @@ class VirtualMachineView(LoginRequiredMixin, View): kwargs={'pk': opennebula_vm_id}) ) - terminated, err = manager.delete_vm(vm.id) + terminated = manager.delete_vm(vm.id) if not terminated: response['text'] = ugettext( - 'Error terminating VM') + opennebula_vm_id + '\n' + err + 'Error terminating VM') + opennebula_vm_id else: for t in range(15): try: diff --git a/opennebula_api/models.py b/opennebula_api/models.py index 9eb89fdf..d584bf26 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -324,7 +324,6 @@ class OpenNebulaManager(): def delete_vm(self, vm_id): TERMINATE_ACTION = 'terminate' vm_terminated = False - err = '' try: self.oneadmin_client.call( oca.VirtualMachine.METHODS['action'], @@ -334,19 +333,15 @@ class OpenNebulaManager(): vm_terminated = True except socket.timeout as socket_err: logger.info("Socket timeout error: {0}".format(socket_err)) - err = ("Socket timeout error: {0}".format(socket_err)) except OpenNebulaException as opennebula_err: logger.info( "OpenNebulaException error: {0}".format(opennebula_err)) - err = ("OpenNebulaException error: {0}".format(opennebula_err)) except OSError as os_err: logger.info("OSError : {0}".format(os_err)) - err = ("OSError : {0}".format(os_err)) except ValueError as value_err: logger.info("ValueError : {0}".format(value_err)) - err = ("ValueError : {0}".format(value_err)) - return (vm_terminated, err) + return vm_terminated def _get_template_pool(self): try: From 3ef07758effebf0fdea8c4e1bc6a904a35a02fed Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Tue, 19 Sep 2017 01:08:27 +0530 Subject: [PATCH 23/27] translation and text fix --- hosting/locale/de/LC_MESSAGES/django.po | 14 +++++++------- .../templates/hosting/virtual_machine_detail.html | 2 +- hosting/views.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hosting/locale/de/LC_MESSAGES/django.po b/hosting/locale/de/LC_MESSAGES/django.po index ca78a381..cd47faa3 100644 --- a/hosting/locale/de/LC_MESSAGES/django.po +++ b/hosting/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-18 23:16+0530\n" +"POT-Creation-Date: 2017-09-19 01:04+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -575,10 +575,10 @@ msgstr "Bist Du sicher, dass Du Deine virtuelle Maschine beenden willst" msgid "OK" msgstr "" -msgid "Your Virtual Machine" -msgstr "Deine Maschinen Detail" +msgid "Your virtual machine" +msgstr "Deine Virtuelle Machine (VM)" -msgid "was successfully terminated!" +msgid "is successfully terminated!" msgstr "wurde erfolgreich beendet!" msgid "Close" @@ -651,12 +651,12 @@ msgid "" "contact Data Center Light Support." msgstr "Kontaktiere den Data Center Light Support." -msgid "Error terminating VM" -msgstr "Fehler beenden VM" - msgid "Terminated" msgstr "Beendet" +msgid "Error terminating VM" +msgstr "Fehler beenden VM" + msgid "Virtual Machine Cancellation" msgstr "VM Kündigung" diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index 08872c1e..d2d23db8 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -124,7 +124,7 @@ From 445359e1ed3c9319118004a265403975fe83561e Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Tue, 19 Sep 2017 14:29:18 +0530 Subject: [PATCH 25/27] modal restyle --- hosting/static/hosting/css/commons.css | 4 ++++ hosting/templates/hosting/virtual_machine_detail.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hosting/static/hosting/css/commons.css b/hosting/static/hosting/css/commons.css index 01ff5090..a922174c 100644 --- a/hosting/static/hosting/css/commons.css +++ b/hosting/static/hosting/css/commons.css @@ -139,6 +139,10 @@ .modal-text p:not(:last-of-type){ margin-bottom: 5px; } + +.modal-title + .modal-footer { + margin-top: 5px; +} .modal-footer { border-top: 0px solid #e5e5e5; width: 100%; diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index 33c5bf2a..e91fd0eb 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -124,7 +124,7 @@