[Kimchi-devel] [PATCH] Disallow storage format changes in UI for templates based on image file

Jose Ricardo Ziviani joserz at linux.vnet.ibm.com
Mon Aug 17 16:36:43 UTC 2015


 - Only support qcow2 for VMs created by a template based on an existing
   image file. This commit sets the template format type to qcow2 and
   disables changes on it for such scenario.

Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.template_edit_main.js | 37 +++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/ui/js/src/kimchi.template_edit_main.js b/ui/js/src/kimchi.template_edit_main.js
index 21f5575..141e451 100644
--- a/ui/js/src/kimchi.template_edit_main.js
+++ b/ui/js/src/kimchi.template_edit_main.js
@@ -58,6 +58,14 @@ kimchi.template_edit_main = function() {
                 kimchi.select('template-edit-graphics-list', spiceOpt);
             }
         };
+        var isImageBasedTemplate = function() {
+            if (template["vm-image"] &&
+                typeof template["vm-image"] == "string" &&
+                template["vm-image"].substr(template["vm-image"].length - 4) == ".img") {
+                return true;
+            }
+            return false;
+        }
         enableSpice();
         var initStorage = function(result) {
             var scsipools = {};
@@ -88,10 +96,16 @@ kimchi.template_edit_main = function() {
                 $('#selectStorageName').append(storageOptions);
 
                 // Set disk format
-                $('#diskFormat').val(storageData.storageDiskFormat);
-                $('#diskFormat').on('change', function() {
-                    $('.template-storage-disk-format').val($(this).val());
-                });
+                if (isImageBasedTemplate()) {
+                    $('#diskFormat').val('qcow2');
+                    $('#diskFormat').prop('disabled', 'disabled');
+                }
+                else {
+                    $('#diskFormat').val(storageData.storageDiskFormat);
+                    $('#diskFormat').on('change', function() {
+                        $('.template-storage-disk-format').val($(this).val());
+                    });
+                }
 
                 $('#selectStorageName').change(function() {
                     var selectedItem = $(this).parent().parent();
@@ -106,16 +120,21 @@ kimchi.template_edit_main = function() {
                             kimchi.getStoragePoolVolume(tempStorageName, tempName[tempName.length-1], function(info) {
                                 volSize = info.capacity / Math.pow(1024, 3);
                                 $('.template-storage-disk', selectedItem).attr('readonly', true).val(volSize);
-                                $('#diskFormat').val('raw');
-                                $('#diskFormat').prop('disabled', true).change();
+                                if (!isImageBasedTemplate()) {
+                                    $('#diskFormat').val('raw');
+                                    $('#diskFormat').prop('disabled', true).change();
+                                }
                             });
                         } else if (tempType === 'logical') {
                             $('.template-storage-disk', selectedItem).attr('readonly', false);
-                            $('#diskFormat').val('raw');
-                            $('#diskFormat').prop('disabled', true).change();
+                            if (!isImageBasedTemplate()) {
+                                $('#diskFormat').val('raw');
+                                $('#diskFormat').prop('disabled', true).change();
+                            }
                         } else {
                             $('.template-storage-disk', selectedItem).attr('readonly', false);
-                            if ($('#diskFormat').prop('disabled') == true) {
+                            if ($('#diskFormat').prop('disabled') == true &&
+                               !isImageBasedTemplate()) {
                                 $('#diskFormat').val('qcow2');
                                 $('#diskFormat').prop('disabled', false).change();
                             }
-- 
1.9.1




More information about the Kimchi-devel mailing list