This patch adds a new field (Disk Format) in Storage tab in Template
edit window. Users will then be allowed to select any disk format
supported by Libvirt and Kimchi backend.
The default disk format is qcow2 (first option), so, for compatibility,
if the template register in objecstore does not contain the disk format
information, the new field is going to set 'qcow2' automatically.
For iscsi storagepools, the new field is going to be disabled and the
format is going to be set automatically as 'raw', just like the backend
behaves currently, avoiding errors.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
ui/css/theme-default/template-edit.css | 8 ++++++--
ui/js/src/kimchi.template_edit_main.js | 37 ++++++++++++++++++++++++++++------
ui/pages/template-edit.html.tmpl | 18 ++++++++++++++++-
3 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/ui/css/theme-default/template-edit.css
b/ui/css/theme-default/template-edit.css
index 7abee7c..ed9f02c 100644
--- a/ui/css/theme-default/template-edit.css
+++ b/ui/css/theme-default/template-edit.css
@@ -95,7 +95,7 @@
#edit-template-tabs .template-storage-cell{
display: inline-block;
- width: 230px;
+ width: 180px;
}
#edit-template-tabs .template-storage-cell label {
@@ -114,7 +114,11 @@
}
#form-template-storage .template-tab-body .template-storage-name {
- width: 220px;
+ width: 170px;
+}
+
+#form-template-storage .template-tab-body .template-storage-disk-format {
+ width: 160px;
}
#edit-template-tabs .template-tab-body input[readonly] {
diff --git a/ui/js/src/kimchi.template_edit_main.js
b/ui/js/src/kimchi.template_edit_main.js
index 85f76cd..21f5575 100644
--- a/ui/js/src/kimchi.template_edit_main.js
+++ b/ui/js/src/kimchi.template_edit_main.js
@@ -67,7 +67,7 @@ kimchi.template_edit_main = function() {
$('.template-tab-body',
'#form-template-storage').append(nodeStorage);
var storageOptions = '';
var scsiOptions = '';
- $('select',
'#form-template-storage').find('option').remove();
+ $('#selectStorageName').find('option').remove();
$.each(result, function(index, storageEntities) {
if((storageEntities.state === 'active') &&
(storageEntities.type != 'kimchi-iso')) {
if(storageEntities.type === 'iscsi' ||
storageEntities.type === 'scsi') {
@@ -77,7 +77,7 @@ kimchi.template_edit_main = function() {
var isSlected = tmpPath === thisName ? '
selected' : '';
scsiOptions += '<option' + isSlected +
'>' + tmpPath + '</option>';
});
- $('select',
'#form-template-storage').append(scsiOptions);
+ $('#selectStorageName').append(scsiOptions);
}, function() {});
} else {
var isSlected = storageEntities.name === thisName ? '
selected' : '';
@@ -85,8 +85,15 @@ kimchi.template_edit_main = function() {
}
}
});
- $('select',
'#form-template-storage').append(storageOptions);
- $('select', '#form-template-storage').change(function()
{
+ $('#selectStorageName').append(storageOptions);
+
+ // Set disk format
+ $('#diskFormat').val(storageData.storageDiskFormat);
+ $('#diskFormat').on('change', function() {
+ $('.template-storage-disk-format').val($(this).val());
+ });
+
+ $('#selectStorageName').change(function() {
var selectedItem = $(this).parent().parent();
var tempStorageNameFull = $(this).val();
var tempName = tempStorageNameFull.split('/');
@@ -99,9 +106,19 @@ 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();
});
+ } else if (tempType === 'logical') {
+ $('.template-storage-disk',
selectedItem).attr('readonly', false);
+ $('#diskFormat').val('raw');
+ $('#diskFormat').prop('disabled',
true).change();
} else {
$('.template-storage-disk',
selectedItem).attr('readonly', false);
+ if ($('#diskFormat').prop('disabled') ==
true) {
+ $('#diskFormat').val('qcow2');
+ $('#diskFormat').prop('disabled',
false).change();
+ }
}
});
});
@@ -120,7 +137,8 @@ kimchi.template_edit_main = function() {
editMode : 'hide',
storageName : defaultPool,
storageType : defaultType,
- storageDisk : diskEntities.size
+ storageDisk : diskEntities.size,
+ storageDiskFormat : diskEntities.format ? diskEntities.format
: 'qcow2'
}
if (diskEntities.volume) {
@@ -131,7 +149,13 @@ kimchi.template_edit_main = function() {
nodeData.storageDisk = volSize;
addStorageItem(nodeData);
$('.template-storage-disk').attr('readonly', true);
+ $('#diskFormat').val('raw');
+ $('#diskFormat').prop('disabled',
true).change();
});
+ } else if (defaultType === 'logical') {
+ addStorageItem(storageNodeData);
+ $('#diskFormat').val('raw');
+ $('#diskFormat').prop('disabled',
true).change();
} else {
addStorageItem(storageNodeData);
}
@@ -271,7 +295,8 @@ kimchi.template_edit_main = function() {
origDisks[0]['volume'] && delete
origDisks[0]['volume'];
origDisks[0].size = Number($('.template-storage-disk',
tmpItem).val());
}
- data[field] = origDisks;
+ origDisks[0].format = $('.template-storage-disk-format',
tmpItem).val();
+ data[field] = origDisks;
}
else if (field == 'graphics') {
var type = $('#form-template-general [name="' + field +
'"]').val();
diff --git a/ui/pages/template-edit.html.tmpl b/ui/pages/template-edit.html.tmpl
index c7832c9..5191f54 100644
--- a/ui/pages/template-edit.html.tmpl
+++ b/ui/pages/template-edit.html.tmpl
@@ -104,6 +104,7 @@
<span class="template-storage-cell">$_("Storage
Pool")</span>
<span
class="template-storage-cell">$_("Type")</span>
<span
class="template-storage-cell">$_("Disk(GB)")</span>
+ <span class="template-storage-cell">$_("Disk
Format")</span>
<button type="button"
id="template-edit-storage-add-button"
class="action-area"></button>
</div>
<div class="template-tab-body">
@@ -152,7 +153,7 @@
<div class='item'>
<span class="template-storage-cell">
<input class="template-storage-name" value={storageName}
type="text" style="display:none" />
- <select></select>
+ <select id="selectStorageName"></select>
</span>
<span class="template-storage-cell">
<input class="template-storage-type" value={storageType}
readonly=true type="text" />
@@ -160,6 +161,21 @@
<span class="template-storage-cell">
<input class="template-storage-disk" value={storageDisk}
type="text" />
</span>
+ <span class="template-storage-cell">
+ <input class="template-storage-disk-format"
value={storageDiskFormat} type="text" style="display:none" />
+ <select id="diskFormat">
+ <option value="qcow2">qcow2</option>
+ <option value="raw">raw</option>
+ <option value="bochs">bochs</option>
+ <option value="cloop">cloop</option>
+ <option value="cow">cow</option>
+ <option value="dmg">dmg</option>
+ <option value="qcow">qcow</option>
+ <option value="qed">qed</option>
+ <option value="vmdk">vmdk</option>
+ <option value="vpc">vpc</option>
+ </select>
+ </span>
</div>
</script>
<script id="template-interface-tmpl" type="text/html">
--
2.1.0