[Kimchi-devel] [PATCH V3 4/4] (WIP) Storagepool SCSI/FC: Modifies UI flow to select a LUN to new VM

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Mon Feb 3 18:26:03 UTC 2014


This patch implements the UI functions and API calls to show to user
the list of volumes (LUNs) of a SCSI FC storagepools. The user can then
select the LUN when creating a new VM.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.api.js            | 13 +++++++
 ui/js/src/kimchi.guest_add_main.js | 72 +++++++++++++++++++++++++++++++++++---
 2 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 66fc41e..4597c5d 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -155,6 +155,19 @@ var kimchi = {
         });
     },
 
+    /*
+    *   Retrieve the information of a storage pool by the given name.
+    */
+    retrieveStoragePool : function(storagePoolName, suc, err) {
+        kimchi.requestJSON({
+            url : kimchi.url + "storagepools/" +
+                  encodeURIComponent(storagePoolName),
+            type : 'GET',
+            contentType : 'application/json',
+            dataType : 'json'
+        }).done(suc);
+    },
+
     /**
      * Retrieve the information of a template by the given name.
      */
diff --git a/ui/js/src/kimchi.guest_add_main.js b/ui/js/src/kimchi.guest_add_main.js
index 2085562..66dc212 100644
--- a/ui/js/src/kimchi.guest_add_main.js
+++ b/ui/js/src/kimchi.guest_add_main.js
@@ -62,9 +62,7 @@ kimchi.guest_add_main = function() {
         }
     });
 
-    var addGuest = function(event) {
-        var formData = $('#form-vm-add').serializeObject();
-
+    var addGuest = function(formData) {
         kimchi.createVM(formData, function() {
             kimchi.listVmsAuto();
             kimchi.window.close();
@@ -79,8 +77,74 @@ kimchi.guest_add_main = function() {
         return false;
     };
 
+    // This function is used to select a lun for new vm disk if template has
+    // a SCSI storagepool associated.
+    function getLun() {
+        var formData = $('#form-vm-add').serializeObject();
+        var templateName = formData.template.substring(11);
+        kimchi.retrieveTemplate(templateName, function(templateInfo) {
+            var poolName = templateInfo.storagepool.substring(14);
+            kimchi.retrieveStoragePool(poolName, function(poolInfo){
+                if (poolInfo.type === "scsi") {
+                    kimchi.listStorageVolumes(poolInfo.name, function(lunsList) {
+                        if (lunsList.length == 0) {
+                            kimchi.message.error('There are not volumes for this pool');
+                            return false;
+                        }
+                        var popUpList = '<div class="section-container">' +
+                                           '<div class="section-header">1. Storage Pool: ' +  poolInfo.name + '</div>' +
+                                           '<div class="text-help">';
+                        $.each(lunsList, function(index, value) {
+                            popUpList += '<div class="input-container">' +
+                                             '<input type="radio" id="lun-' + value.name + '" name="lun" value="' + value.name + '">' +
+                                             '<label for="lun-' + value.name + '">' + value.name + '</label></div>';
+                        });
+                        popUpList += '</div></div>';
+                        console.log(popUpList)
+                        var popup = $(popUpList);
+                        popup.dialog({
+                            autoOpen : true,
+                            modal : true,
+                            width : 400,
+                            draggable : false,
+                            resizable : false,
+                            closeText: "X",
+                            dialogClass : "network-ui-dialog",
+                            title: "Please, select a LUN",
+                            close: function( event, ui ) { $('input[name=lun]').attr('checked',false); },
+                            buttons : [ {
+                                text : "Select",
+                                click : function() {
+                                    var lunName = $('input:radio[name=lun]:checked').val();
+                                    if (lunName === undefined) {
+                                        kimchi.message.error('You must select a LUN');
+                                    } else {
+                                        formData.volumes = new Array(lunName);
+                                        addGuest(formData);
+                                    }
+                                    $( this ).dialog( "close" );
+                                }
+                            }]
+                        });
+                    },function() {
+                        // listStorageVolumes error handler
+                        kimchi.message.error(i18n['msg.kimchi.list.volume.fail']);
+                    });
+                }
+                else { addGuest(formData); }
+            }, function() {
+                // retrieveStoragePool error handler
+                kimchi.message.error(i18n['msg.kimchi.retrieve.pool.fail']);
+            });
+        }, function() {
+            // retrieveStoragePool error handler
+            kimchi.message.error(i18n['msg.fail.template.retrieve']);
+        });
+        return false;
+    }
+
     $('#form-vm-add').on('submit', addGuest);
-    $('#vm-doAdd').on('click', addGuest);
+    $('#vm-doAdd').on('click', getLun);
 
     showTemplates();
 };
-- 
1.8.5.3




More information about the Kimchi-devel mailing list