[Kimchi-devel] [PATCH] Disallow storage format changes in UI for templates based on image file
Aline Manera
alinefm at linux.vnet.ibm.com
Fri Aug 21 18:27:44 UTC 2015
On 17/08/2015 13:36, Jose Ricardo Ziviani wrote:
> - 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;
> + }
A template may have multiple disks. I know it is not supported on UI
right now, but the data type is a list.
So we need to do that for each disk and verify if it has the 'base'
parameter.
Something like:
for disk in template.disks:
if template.disks[i].base:
# must set the disk type to qcow2
else:
# let user changes it
I think this 'for' is already implemented somewhere. We just need to
adjust the logic for each disk.
Let me know if you need help on it.
> 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();
> }
More information about the Kimchi-devel
mailing list