[PATCH 0/2 V3] Issue #363: Fix

V3: This patch set is a merge of previous patches from Rodrigo and Sheldon. This patch set address comments from Aline: - encodes pool and volume names; - saves disk or volume disk size in template data; - set disk size to default value (10GB) when changing to a new pool, or uses previous saved disk value; Rodrigo Trujillo (2): Issue #363: Add new rest api function - getStoragePoolVolume Issue #363: Fix data/information consistence in edit template window ui/js/src/kimchi.api.js | 13 ++++++++++++ ui/js/src/kimchi.template_edit_main.js | 37 ++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) -- 1.9.0

This patch adds new api AJAX method to retrieve specific storage pool volume information. This method is used in template edit window. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 8c1030c..a802ce5 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -744,6 +744,19 @@ var kimchi = { }); }, + getStoragePoolVolume: function(poolName, volumeName, suc, err) { + var url = kimchi.url + 'storagepools/' + encodeURIComponent(poolName) + '/storagevolumes/' + encodeURIComponent(volumeName); + kimchi.requestJSON({ + url : url, + type : 'GET', + contentType : 'application/json', + timeout: 2000, + dataType : 'json', + success : suc, + error : err + }); + }, + addVMStorage : function(settings, suc, err) { var vm = encodeURIComponent(settings['vm']); delete settings['vm']; -- 1.9.0

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 04/13/2014 01:27 PM, Rodrigo Trujillo wrote:
This patch adds new api AJAX method to retrieve specific storage pool volume information. This method is used in template edit window.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 8c1030c..a802ce5 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -744,6 +744,19 @@ var kimchi = { }); },
+ getStoragePoolVolume: function(poolName, volumeName, suc, err) { + var url = kimchi.url + 'storagepools/' + encodeURIComponent(poolName) + '/storagevolumes/' + encodeURIComponent(volumeName); + kimchi.requestJSON({ + url : url, + type : 'GET', + contentType : 'application/json', + timeout: 2000, + dataType : 'json', + success : suc, + error : err + }); + }, + addVMStorage : function(settings, suc, err) { var vm = encodeURIComponent(settings['vm']); delete settings['vm'];

This patch changes edit template window to fix consistence: - Show storagepool + volume name correctly in storagepool field after saving - Show disk size according to storagepool or storagepool/volume selected - Block disk size input box when disk is type volume (iscsi/scsi volumes cannot be changed) - When changing between storagepools, shows original saved size, default disk size (10 GB) or the volume size Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.template_edit_main.js | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/ui/js/src/kimchi.template_edit_main.js b/ui/js/src/kimchi.template_edit_main.js index 386095b..f0f4718 100644 --- a/ui/js/src/kimchi.template_edit_main.js +++ b/ui/js/src/kimchi.template_edit_main.js @@ -18,9 +18,11 @@ kimchi.template_edit_main = function() { var templateEditForm = $('#form-template-edit'); var origDisks; + var origPool; $('#template-name', templateEditForm).val(kimchi.selectedTemplate); kimchi.retrieveTemplate(kimchi.selectedTemplate, function(template) { origDisks = template.disks; + origPool = template.storagepool; for ( var prop in template) { var value = template[prop]; if (prop == 'graphics') { @@ -30,6 +32,11 @@ kimchi.template_edit_main = function() { } var disks = template.disks; $('input[name="disks"]').val(disks[0].size); + if (disks[0].volume) { + var spool_value = $('#form-template-edit [name="storagepool"]').val(); + $('input[name="storagepool"]', templateEditForm).val(spool_value + '/' + disks[0].volume); + $('input[name="disks"]', templateEditForm).attr('disabled','disabled'); + } var options = [{label: 'VNC', value: 'vnc'}]; kimchi.getCapabilities(function(result) { @@ -37,7 +44,7 @@ kimchi.template_edit_main = function() { options.push({label: 'Spice', value: 'spice'}) } }, function() { - }, function(){ + }, function() { kimchi.select('template-edit-graphics-list', options); }); @@ -101,6 +108,31 @@ kimchi.template_edit_main = function() { kimchi.window.close(); }); + $('#template-edit-storagePool').change(function() { + storagepool = $(this).val(); + var storageArray = storagepool.split("/"); + if (storageArray.length > 3) { + volumeName = storageArray.pop(); + poolName = storageArray.pop(); + kimchi.getStoragePoolVolume(poolName, volumeName, function(result) { + $('input[name="disks"]', templateEditForm).val(result.capacity / Math.pow(1024,3)); + $('input[name="disks"]', templateEditForm).attr('disabled','disabled'); + return false; + }, function (err) { + kimchi.message.error(err.responseJSON.reason); + }); + } else { + if (origPool == storagepool) { + // Previous disk size value + $('input[name="disks"]', templateEditForm).val(origDisks[0].size); + } else { + // Default disk size value + $('input[name="disks"]', templateEditForm).val(10); + } + $('input[name="disks"]', templateEditForm).removeAttr('disabled'); + } + }); + $('#tmpl-edit-button-save').on('click', function() { var editableFields = [ 'name', 'cpus', 'memory', 'storagepool', 'disks', 'graphics']; var data = {}; @@ -124,9 +156,10 @@ kimchi.template_edit_main = function() { storageArray = storagepool.split("/"); if (storageArray.length > 3){ /* Support only 1 disk at this moment */ - delete data["disks"][0].size; data["disks"][0].volume = storageArray.pop(); data['storagepool'] = storageArray.join("/"); + } else if (data["disks"][0].volume) { + delete data["disks"][0].volume; } var networks = templateEditForm.serializeObject().networks; if (networks instanceof Array) { -- 1.9.0

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 04/13/2014 01:27 PM, Rodrigo Trujillo wrote:
This patch changes edit template window to fix consistence: - Show storagepool + volume name correctly in storagepool field after saving - Show disk size according to storagepool or storagepool/volume selected - Block disk size input box when disk is type volume (iscsi/scsi volumes cannot be changed) - When changing between storagepools, shows original saved size, default disk size (10 GB) or the volume size
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.template_edit_main.js | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/ui/js/src/kimchi.template_edit_main.js b/ui/js/src/kimchi.template_edit_main.js index 386095b..f0f4718 100644 --- a/ui/js/src/kimchi.template_edit_main.js +++ b/ui/js/src/kimchi.template_edit_main.js @@ -18,9 +18,11 @@ kimchi.template_edit_main = function() { var templateEditForm = $('#form-template-edit'); var origDisks; + var origPool; $('#template-name', templateEditForm).val(kimchi.selectedTemplate); kimchi.retrieveTemplate(kimchi.selectedTemplate, function(template) { origDisks = template.disks; + origPool = template.storagepool; for ( var prop in template) { var value = template[prop]; if (prop == 'graphics') { @@ -30,6 +32,11 @@ kimchi.template_edit_main = function() { } var disks = template.disks; $('input[name="disks"]').val(disks[0].size); + if (disks[0].volume) { + var spool_value = $('#form-template-edit [name="storagepool"]').val(); + $('input[name="storagepool"]', templateEditForm).val(spool_value + '/' + disks[0].volume); + $('input[name="disks"]', templateEditForm).attr('disabled','disabled'); + }
var options = [{label: 'VNC', value: 'vnc'}]; kimchi.getCapabilities(function(result) { @@ -37,7 +44,7 @@ kimchi.template_edit_main = function() { options.push({label: 'Spice', value: 'spice'}) } }, function() { - }, function(){ + }, function() { kimchi.select('template-edit-graphics-list', options); });
@@ -101,6 +108,31 @@ kimchi.template_edit_main = function() { kimchi.window.close(); });
+ $('#template-edit-storagePool').change(function() { + storagepool = $(this).val(); + var storageArray = storagepool.split("/"); + if (storageArray.length > 3) { + volumeName = storageArray.pop(); + poolName = storageArray.pop(); + kimchi.getStoragePoolVolume(poolName, volumeName, function(result) { + $('input[name="disks"]', templateEditForm).val(result.capacity / Math.pow(1024,3)); + $('input[name="disks"]', templateEditForm).attr('disabled','disabled'); + return false; + }, function (err) { + kimchi.message.error(err.responseJSON.reason); + }); + } else { + if (origPool == storagepool) { + // Previous disk size value + $('input[name="disks"]', templateEditForm).val(origDisks[0].size); + } else { + // Default disk size value + $('input[name="disks"]', templateEditForm).val(10); + } + $('input[name="disks"]', templateEditForm).removeAttr('disabled'); + } + }); + $('#tmpl-edit-button-save').on('click', function() { var editableFields = [ 'name', 'cpus', 'memory', 'storagepool', 'disks', 'graphics']; var data = {}; @@ -124,9 +156,10 @@ kimchi.template_edit_main = function() { storageArray = storagepool.split("/"); if (storageArray.length > 3){ /* Support only 1 disk at this moment */ - delete data["disks"][0].size; data["disks"][0].volume = storageArray.pop(); data['storagepool'] = storageArray.join("/"); + } else if (data["disks"][0].volume) { + delete data["disks"][0].volume; } var networks = templateEditForm.serializeObject().networks; if (networks instanceof Array) {
participants (2)
-
Aline Manera
-
Rodrigo Trujillo