[Kimchi-devel] [PATCH V5 5/6] Storagepool SCSI/FC: Modifies UI flow to select a LUN to new VM

Aline Manera alinefm at linux.vnet.ibm.com
Wed Feb 12 18:13:44 UTC 2014


On 02/12/2014 04:25 AM, Rodrigo Trujillo wrote:
> 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 | 73 +++++++++++++++++++++++++++++++++++---
>   ui/pages/i18n.html.tmpl            |  4 +++
>   3 files changed, 86 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..1d3c60d 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,75 @@ 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 = '<section class="form-section">' +
> +                                           '<p class="text-help">' + i18n['msg.guest.select.lun.helper'] + '</p>' +
> +                                           '<h2>1. Storage Pool: ' +  poolInfo.name + '</h2>' +
> +                                           '<div class="lun_radios">';
> +                        $.each(lunsList, function(index, value) {
> +                            popUpList += '<div class="field">' +
> +                                             '<input type="radio" id="lun-' + value.name + '" name="lun" value="' + value.name + '">' +
> +                                             '<label for="lun-' + value.name + '">' + value.name + '</label></div>';
> +                        });
> +                        popUpList += '</div></section>';
> +                        var popup = $(popUpList);
> +                        popup.dialog({
> +                            autoOpen : true,
> +                            modal : true,
> +                            width : 400,
> +                            draggable : false,
> +                            resizable : false,
> +                            closeText: "X",
> +                            dialogClass : "network-config",
> +                            title: i18n['msg.guest.select.lun.header'],
> +                            close: function( event, ui ) { $('input[name=lun]').attr('checked',false); },
> +                            buttons : [ {
> +                                text : i18n.action_select_lun,
> +                                class: "ui-button-primary",
> +                                click : function() {
> +                                    var lunName = $('input:radio[name=lun]:checked').val();
> +                                    if (lunName === undefined) {
> +                                        window.alert(i18n['msg.guest.select.lun.error']);
> +                                    } 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;
> +    }
> +

As I said before split this huge function into smaller ones. It is 
terrible to review it.

>       $('#form-vm-add').on('submit', addGuest);
> -    $('#vm-doAdd').on('click', addGuest);
> +    $('#vm-doAdd').on('click', getLun);
>
>       showTemplates();
>   };
> diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl
> index a4c3ccb..af824f7 100644
> --- a/ui/pages/i18n.html.tmpl
> +++ b/ui/pages/i18n.html.tmpl
> @@ -123,6 +123,10 @@ var i18n = {
>       'network_dialog_ok': "$_("OK")",
>       'network_dialog_cancel': "$_("Cancel")",
>       'action_create': "$_("Create")",
> +    'action_select_lun': "$_("Select")",
> +    'msg.guest.select.lun.helper': "$_("You selected a Template associated to a SCSI Fibre Channel Storage Pool so you need to select which LUN you wan to use as primary disk to your guest.")",
> +    'msg.guest.select.lun.header': "$_("Please, select a LUN")",
> +    'msg.guest.select.lun.error': "$_("No LUN selected.")",
>       'msg_warning': "$_("Warning")",
>       'msg.logicalpool.confirm.delete': "$_("It will format your disk and you will loose any data in"
>                                         " there, are you sure to continue? ")",




More information about the Kimchi-devel mailing list