Merge "Validate minimum RAM for snapshot source"

This commit is contained in:
Jenkins 2016-06-28 11:38:33 +00:00 committed by Gerrit Code Review
commit 0bd4aa91d1
3 changed files with 26 additions and 19 deletions

View File

@ -212,16 +212,18 @@ horizon.addInitFunction(horizon.instances.init = function () {
Update the device size value to reflect minimum allowed Update the device size value to reflect minimum allowed
for selected image and flavor for selected image and flavor
*/ */
function update_device_size() { function update_device_size(source_type) {
var volume_size = horizon.Quota.getSelectedFlavor().disk; var volume_size = horizon.Quota.getSelectedFlavor().disk;
var image = horizon.Quota.getSelectedImage();
var size_field = $("#id_volume_size"); var size_field = $("#id_volume_size");
if (image !== undefined && image.min_disk > volume_size) { if (source_type === 'image') {
volume_size = image.min_disk; var image = horizon.Quota.getSelectedImageOrSnapshot(source_type);
} if (image !== undefined && image.min_disk > volume_size) {
if (image !== undefined && image.size > volume_size) { volume_size = image.min_disk;
volume_size = image.size; }
if (image !== undefined && image.size > volume_size) {
volume_size = image.size;
}
} }
// If the user has manually changed the volume size, do not override // If the user has manually changed the volume size, do not override
@ -246,7 +248,7 @@ horizon.addInitFunction(horizon.instances.init = function () {
}); });
$document.on('change', '.workflow #id_image_id', function () { $document.on('change', '.workflow #id_image_id', function () {
update_device_size(); update_device_size('image');
}); });
$document.on('input', '.workflow #id_volume_size', function () { $document.on('input', '.workflow #id_volume_size', function () {

View File

@ -134,25 +134,25 @@ horizon.Quota = {
}, },
/* /*
Return an image Object based on which image ID is selected Return an image/snapshot Object based on which image/snapshot ID is selected
*/ */
getSelectedImage: function() { getSelectedImageOrSnapshot: function(source_type) {
var selected = $('#id_image_id option:selected').val(); var selected = $('#id_' + source_type + '_id option:selected').val();
return horizon.Quota.findImageById(selected); return horizon.Quota.findImageById(selected);
}, },
/* /*
Disable any flavors for a given image that do not meet Disable any flavors for a given image/snapshot that do not meet
its minimum RAM or disk requirements. its minimum RAM or disk requirements.
*/ */
disableFlavorsForImage: function(image) { disableFlavorsForImage: function(source_type) {
image = horizon.Quota.getSelectedImage(); var source = horizon.Quota.getSelectedImageOrSnapshot(source_type);
var to_disable = []; // an array of flavor names to disable var to_disable = []; // an array of flavor names to disable
horizon.Quota.resetFlavors(); // clear any previous messages horizon.Quota.resetFlavors(); // clear any previous messages
$.each(horizon.Quota.flavors, function(i, flavor) { $.each(horizon.Quota.flavors, function(i, flavor) {
if (!horizon.Quota.imageFitsFlavor(image, flavor)) { if (!horizon.Quota.imageFitsFlavor(source, flavor)) {
to_disable.push(flavor.name); to_disable.push(flavor.name);
} }
}); });
@ -192,7 +192,7 @@ horizon.Quota = {
this.disabledFlavorMessage = disabledMessage; this.disabledFlavorMessage = disabledMessage;
this.allFlavorsDisabledMessage = allDisabledMessage; this.allFlavorsDisabledMessage = allDisabledMessage;
// Check if the image is pre-selected // Check if the image is pre-selected
horizon.Quota.disableFlavorsForImage(); horizon.Quota.disableFlavorsForImage('image');
}, },
/* /*
@ -397,12 +397,17 @@ horizon.Quota = {
}; };
var imageChangeCallback = function() { var imageChangeCallback = function() {
scope.disableFlavorsForImage(); scope.disableFlavorsForImage('image');
};
var snapshotChangeCallback = function() {
scope.disableFlavorsForImage('instance_snapshot');
}; };
$('#id_flavor').on('keyup change', eventCallback); $('#id_flavor').on('keyup change', eventCallback);
$('#id_count').on('input', eventCallback); $('#id_count').on('input', eventCallback);
$('#id_image_id').on('change', imageChangeCallback); $('#id_image_id').on('change', imageChangeCallback);
$('#id_instance_snapshot_id').on('change', snapshotChangeCallback);
} }
$(this.user_value_form_inputs).each(function(index, element) { $(this.user_value_form_inputs).each(function(index, element) {

View File

@ -75,8 +75,8 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
some_disabled_msg = '{{_("Some flavors not meeting minimum image requirements have been disabled.")|escapejs }}'; some_disabled_msg = '{{_("Some flavors not meeting minimum boot source requirements have been disabled.")|escapejs }}';
all_disabled_msg = '{{_("No flavors meet minimum criteria for selected image.")|escapejs }}'; all_disabled_msg = '{{_("No flavors meet minimum criteria for selected boot source.")|escapejs }}';
if(typeof horizon.Quota !== 'undefined') { if(typeof horizon.Quota !== 'undefined') {
horizon.Quota.initWithFlavors({{ flavors|safe|default:"{}" }}); horizon.Quota.initWithFlavors({{ flavors|safe|default:"{}" }});