Validate minimum RAM for snapshot source

On launch instance there was no check for
min RAM values when launching from snapshot.
Now when launching from snapshot it will check
the same requirements as the images.

Change-Id: I138476b839319f357022f9545c5104a17a382df3
Partial-Bug: #1401101
(cherry picked from commit ce8677e675)
This commit is contained in:
Itxaka 2015-12-14 17:56:25 +01:00 committed by Rob Cresswell
parent 6c6bccec44
commit d4ac1d28c3
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
for selected image and flavor
*/
function update_device_size() {
function update_device_size(source_type) {
var volume_size = horizon.Quota.getSelectedFlavor().disk;
var image = horizon.Quota.getSelectedImage();
var size_field = $("#id_volume_size");
if (image !== undefined && image.min_disk > volume_size) {
volume_size = image.min_disk;
}
if (image !== undefined && image.size > volume_size) {
volume_size = image.size;
if (source_type === 'image') {
var image = horizon.Quota.getSelectedImageOrSnapshot(source_type);
if (image !== undefined && image.min_disk > volume_size) {
volume_size = image.min_disk;
}
if (image !== undefined && image.size > volume_size) {
volume_size = image.size;
}
}
// 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 () {
update_device_size();
update_device_size('image');
});
$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() {
var selected = $('#id_image_id option:selected').val();
getSelectedImageOrSnapshot: function(source_type) {
var selected = $('#id_' + source_type + '_id option:selected').val();
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.
*/
disableFlavorsForImage: function(image) {
image = horizon.Quota.getSelectedImage();
disableFlavorsForImage: function(source_type) {
var source = horizon.Quota.getSelectedImageOrSnapshot(source_type);
var to_disable = []; // an array of flavor names to disable
horizon.Quota.resetFlavors(); // clear any previous messages
$.each(horizon.Quota.flavors, function(i, flavor) {
if (!horizon.Quota.imageFitsFlavor(image, flavor)) {
if (!horizon.Quota.imageFitsFlavor(source, flavor)) {
to_disable.push(flavor.name);
}
});
@ -192,7 +192,7 @@ horizon.Quota = {
this.disabledFlavorMessage = disabledMessage;
this.allFlavorsDisabledMessage = allDisabledMessage;
// Check if the image is pre-selected
horizon.Quota.disableFlavorsForImage();
horizon.Quota.disableFlavorsForImage('image');
},
/*
@ -397,12 +397,17 @@ horizon.Quota = {
};
var imageChangeCallback = function() {
scope.disableFlavorsForImage();
scope.disableFlavorsForImage('image');
};
var snapshotChangeCallback = function() {
scope.disableFlavorsForImage('instance_snapshot');
};
$('#id_flavor').on('keyup change', eventCallback);
$('#id_count').on('input', eventCallback);
$('#id_image_id').on('change', imageChangeCallback);
$('#id_instance_snapshot_id').on('change', snapshotChangeCallback);
}
$(this.user_value_form_inputs).each(function(index, element) {

View File

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