[Kimchi-devel] [PATCH][Kimchi] Check memory values in UI before submit request

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Mon Mar 28 20:34:32 UTC 2016


This patch adds a simple test to check memory values being submitted to
backend, canceling the request if Memory is higher then Max Memory,
avoiding useless requests.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.guest_edit_main.js | 8 ++++++++
 ui/pages/i18n.json.tmpl             | 1 +
 2 files changed, 9 insertions(+)

diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
index 19d9e7d..7a9c754 100644
--- a/ui/js/src/kimchi.guest_edit_main.js
+++ b/ui/js/src/kimchi.guest_edit_main.js
@@ -744,6 +744,14 @@ kimchi.guest_edit_main = function() {
         if (data['max-memory'] !== undefined) {
             data['max-memory'] = Number(data['max-memory']);
         }
+
+        // Test memory values before submit. Avoid requests we know are going to fail
+        if ($('#guest-edit-memory-textbox').val() > $('#guest-edit-max-memory-textbox').val()) {
+            wok.message.error(i18n['KCHVM0002E'], '#alert-modal-container');
+            $(saveButton).prop('disabled', false);
+            return;
+        }
+
         if (data['vcpus'] !== undefined) {
             var cpu = Number(data['vcpus']);
             var maxCpu = Number(data['max-processor']);
diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl
index 5be0a66..153d7c2 100644
--- a/ui/pages/i18n.json.tmpl
+++ b/ui/pages/i18n.json.tmpl
@@ -66,6 +66,7 @@
     "KCHVM6009M": "$_("This virtual machine is not persistent. Power Off will delete it. Continue?")",
 
     "KCHVM0001E": "$_("Input is not a number")",
+    "KCHVM0002E": "$_("Memory value cannot be higher then Max Memory value")",
 
     "KCHVMCD6001M": "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")",
     "KCHVMCD6003M": "$_("Attaching...")",
-- 
2.1.0




More information about the Kimchi-devel mailing list