[Kimchi-devel] [PATCH] [Kimchi 3/4] Use the cached values for wok config when required

Aline Manera alinefm at linux.vnet.ibm.com
Fri Jan 22 12:38:46 UTC 2016


There is no need to call /config each time we need an information about
the Wok configuration. So use the cached values when required.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.api.js | 90 ++++++++++++++++++++-----------------------------
 ui/pages/i18n.json.tmpl |  3 +-
 2 files changed, 38 insertions(+), 55 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index af3034b..445cc80 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -292,66 +292,50 @@ var kimchi = {
     },
 
     vncToVM : function(vm) {
+        proxy_port = wok.config['websockets_port'];
+        ssl_port = wok.config['ssl_port'];
         wok.requestJSON({
-            url : 'config/',
-            type : 'GET',
-            dataType : 'json'
-        }).done(function(data, textStatus, xhr) {
-            proxy_port = data['websockets_port'];
-            ssl_port = data['ssl_port'];
-            wok.requestJSON({
-                url : "plugins/kimchi/vms/" + encodeURIComponent(vm) + "/connect",
-                type : "POST",
-                dataType : "json"
-            }).done(function() {
-                url = 'https://' + location.hostname + ':' + ssl_port;
-                url += "/plugins/kimchi/novnc/vnc_auto.html";
-                url += "?port=" + ssl_port;
-                /*
-                 * From python documentation base64.urlsafe_b64encode(s)
-                 * substitutes - instead of + and _ instead of / in the
-                 * standard Base64 alphabet, BUT the result can still
-                 * contain = which is not safe in a URL query component.
-                 * So remove it when needed as base64 can work well without it.
-                 * */
-                url += "&path=websockify?token=" + wok.urlSafeB64Encode(vm).replace(/=*$/g, "");
-                url += '&encrypt=1';
-                window.open(url);
-            });
-        }).error(function() {
-            wok.message.error.code('KCHAPI6002E');
+            url : "plugins/kimchi/vms/" + encodeURIComponent(vm) + "/connect",
+            type : "POST",
+            dataType : "json"
+        }).done(function() {
+            url = 'https://' + location.hostname + ':' + ssl_port;
+            url += "/plugins/kimchi/novnc/vnc_auto.html";
+            url += "?port=" + ssl_port;
+            /*
+             * From python documentation base64.urlsafe_b64encode(s)
+             * substitutes - instead of + and _ instead of / in the
+             * standard Base64 alphabet, BUT the result can still
+             * contain = which is not safe in a URL query component.
+             * So remove it when needed as base64 can work well without it.
+             * */
+            url += "&path=websockify?token=" + wok.urlSafeB64Encode(vm).replace(/=*$/g, "");
+            url += '&encrypt=1';
+            window.open(url);
         });
     },
 
     spiceToVM : function(vm) {
+        proxy_port = wok.config['websockets_port'];
+        ssl_port = wok.config['ssl_port'];
         wok.requestJSON({
-            url : 'config/',
-            type : 'GET',
-            dataType : 'json'
+            url : "plugins/kimchi/vms/" + encodeURIComponent(vm) + "/connect",
+            type : "POST",
+            dataType : "json"
         }).done(function(data, textStatus, xhr) {
-            proxy_port = data['websockets_port'];
-            ssl_port = data['ssl_port'];
-            wok.requestJSON({
-                url : "plugins/kimchi/vms/" + encodeURIComponent(vm) + "/connect",
-                type : "POST",
-                dataType : "json"
-            }).done(function(data, textStatus, xhr) {
-                url = 'https://' + location.hostname + ':' + ssl_port;
-                url += "/plugins/kimchi/spice_auto.html";
-                url += "?port=" + ssl_port + "&listen=" + location.hostname;
-                /*
-                 * From python documentation base64.urlsafe_b64encode(s)
-                 * substitutes - instead of + and _ instead of / in the
-                 * standard Base64 alphabet, BUT the result can still
-                 * contain = which is not safe in a URL query component.
-                 * So remove it when needed as base64 can work well without it.
-                 * */
-                url += "&token=" + wok.urlSafeB64Encode(vm).replace(/=*$/g, "");
-                url += '&encrypt=1';
-                window.open(url);
-            });
-        }).error(function() {
-            wok.message.error.code('KCHAPI6002E');
+            url = 'https://' + location.hostname + ':' + ssl_port;
+            url += "/plugins/kimchi/spice_auto.html";
+            url += "?port=" + ssl_port + "&listen=" + location.hostname;
+            /*
+             * From python documentation base64.urlsafe_b64encode(s)
+             * substitutes - instead of + and _ instead of / in the
+             * standard Base64 alphabet, BUT the result can still
+             * contain = which is not safe in a URL query component.
+             * So remove it when needed as base64 can work well without it.
+             * */
+            url += "&token=" + wok.urlSafeB64Encode(vm).replace(/=*$/g, "");
+            url += '&encrypt=1';
+            window.open(url);
         });
     },
 
diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl
index c1979c6..11f6004 100644
--- a/ui/pages/i18n.json.tmpl
+++ b/ui/pages/i18n.json.tmpl
@@ -1,7 +1,7 @@
 #*
  * Project Kimchi
  *
- * Copyright IBM, Corp. 2014-2015
+ * Copyright IBM, Corp. 2014-2016
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
     "Storage": "$_("Storage")",
     "Network": "$_("Network")",
 
-    "KCHAPI6002E": "$_("Failed to get application configuration")",
     "KCHAPI6003E": "$_("This is not a valid Linux path")",
     "KCHAPI6004E": "$_("This is not a valid URL.")",
     "KCHAPI6008E": "$_("Unable to read file.")",
-- 
2.5.0




More information about the Kimchi-devel mailing list