diff --git a/nova/api/openstack/compute/disk_config.py b/nova/api/openstack/compute/disk_config.py index be865cb9695d..9760702ec219 100644 --- a/nova/api/openstack/compute/disk_config.py +++ b/nova/api/openstack/compute/disk_config.py @@ -14,11 +14,9 @@ """Disk Config extension.""" -from oslo_utils import strutils from webob import exc from nova.api.openstack import extensions -from nova.api.openstack import wsgi from nova.i18n import _ ALIAS = 'os-disk-config' @@ -41,30 +39,6 @@ def disk_config_from_api(value): raise exc.HTTPBadRequest(explanation=msg) -class ImageDiskConfigController(wsgi.Controller): - def _add_disk_config(self, context, images): - for image in images: - metadata = image['metadata'] - if INTERNAL_DISK_CONFIG in metadata: - raw_value = metadata[INTERNAL_DISK_CONFIG] - value = strutils.bool_from_string(raw_value) - image[API_DISK_CONFIG] = disk_config_to_api(value) - - @wsgi.extends - def show(self, req, resp_obj, id): - context = req.environ['nova.context'] - if 'image' in resp_obj.obj and authorize(context): - image = resp_obj.obj['image'] - self._add_disk_config(context, [image]) - - @wsgi.extends - def detail(self, req, resp_obj): - context = req.environ['nova.context'] - if 'images' in resp_obj.obj and authorize(context): - images = resp_obj.obj['images'] - self._add_disk_config(context, images) - - class DiskConfig(extensions.V21APIExtensionBase): """Disk Management Extension.""" @@ -73,10 +47,7 @@ class DiskConfig(extensions.V21APIExtensionBase): version = 1 def get_controller_extensions(self): - images_extension = extensions.ControllerExtension( - self, 'images', ImageDiskConfigController()) - - return [images_extension] + return [] def get_resources(self): return [] diff --git a/nova/api/openstack/compute/views/images.py b/nova/api/openstack/compute/views/images.py index d954c63e7f01..e311934d9e3a 100644 --- a/nova/api/openstack/compute/views/images.py +++ b/nova/api/openstack/compute/views/images.py @@ -14,7 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_utils import strutils + from nova.api.openstack import common +from nova.api.openstack.compute import disk_config from nova.image import glance from nova import utils @@ -70,6 +73,12 @@ class ViewBuilder(common.ViewBuilder): }], } + auto_disk_config = image_dict['metadata'].get("auto_disk_config", None) + if auto_disk_config is not None: + value = strutils.bool_from_string(auto_disk_config) + image_dict["OS-DCF:diskConfig"] = \ + disk_config.disk_config_to_api(value) + return dict(image=image_dict) def detail(self, request, images):