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

Jose Ricardo Ziviani joserz at linux.vnet.ibm.com
Wed Aug 26 18:53:52 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 | 35 +++++++++++++++++++++++++---------
 1 file changed, 26 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..5b2fa75 100644
--- a/ui/js/src/kimchi.template_edit_main.js
+++ b/ui/js/src/kimchi.template_edit_main.js
@@ -58,6 +58,12 @@ kimchi.template_edit_main = function() {
                 kimchi.select('template-edit-graphics-list', spiceOpt);
             }
         };
+        var isImageBasedTemplate = function() {
+            if (template["vm-image"] && typeof template["vm-image"] == "string") {
+                return true;
+            }
+            return false;
+        }
         enableSpice();
         var initStorage = function(result) {
             var scsipools = {};
@@ -88,10 +94,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 +118,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