diff --git a/horizon/static/horizon/js/horizon.instances.js b/horizon/static/horizon/js/horizon.instances.js index 43413661f8..73eaba92b1 100644 --- a/horizon/static/horizon/js/horizon.instances.js +++ b/horizon/static/horizon/js/horizon.instances.js @@ -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 () { diff --git a/horizon/static/horizon/js/horizon.quota.js b/horizon/static/horizon/js/horizon.quota.js index 6b41f9f920..a2402a4ef1 100644 --- a/horizon/static/horizon/js/horizon.quota.js +++ b/horizon/static/horizon/js/horizon.quota.js @@ -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) { diff --git a/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html b/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html index 186e556cd6..840524a537 100644 --- a/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html +++ b/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html @@ -75,8 +75,8 @@