[Kimchi-devel] [PATCH 1/4] Download Remote Image UI: Add Common API to kimchi.api.js

Hongliang Wang hlwang at linux.vnet.ibm.com
Wed Sep 10 12:02:33 UTC 2014


Added APIs to kimchi.api.js.

Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.api.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 5fc456d..393962b 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -1130,5 +1130,54 @@ var kimchi = {
                 kimchi.message.error(data.responseJSON.reason);
             }
         });
+    },
+
+    /**
+     * Add a volume to a given storage pool by URL.
+     */
+    downloadVolumeToSP: function(settings, suc, err) {
+        var url = settings['url'];
+        var name = settings['name'];
+        var sp = encodeURIComponent(settings['sp']);
+        kimchi.requestJSON({
+            url : kimchi.url + 'storagepools/' + sp + '/storagevolumes',
+            type : 'POST',
+            data : JSON.stringify({
+                name: name,
+                url: url
+            }),
+            contentType : 'application/json',
+            dataType : 'json',
+            success : suc,
+            error : err
+        });
+    },
+
+    makeTaskTrackFunc: function(task) {
+        return function(suc, err, progress) {
+            var onTaskResponse = function(result) {
+                var taskStatus = result['status'];
+                switch(taskStatus) {
+                case 'running':
+                    progress && progress(result);
+                    setTimeout(trackTask, 200);
+                    break;
+                case 'finished':
+                    suc(result);
+                    break;
+                case 'failed':
+                    err(result);
+                    break;
+                default:
+                    break;
+                }
+            };
+
+            var trackTask = function() {
+                kimchi.getTask(task, onTaskResponse, err);
+            };
+
+            trackTask();
+        };
     }
 };
-- 
1.8.1.4




More information about the Kimchi-devel mailing list