summaryrefslogtreecommitdiff
path: root/nova/virt/images.py
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2014-03-11 12:11:05 -0700
committerDan Smith <dansmith@redhat.com>2014-03-12 08:27:20 -0700
commit0ba9cca788309bd8763a0d277a907769604cd9f4 (patch)
treea3acd49914f04e5812ffc2ca6d87642c9a629344 /nova/virt/images.py
parenta7e018e8c76d6805dc0e857f24c64e3223224ae8 (diff)
downloadnova-0ba9cca788309bd8763a0d277a907769604cd9f4.tar.gz
Revert "Adding image multiple location support"
This reverts commit a55bbbfa1957d02b3006a51afcf4984a1f8ff886. The series of patches involved with adding this feature introduced an unexpected dependency on glance's v2 API, which we do not currently support. Triggering a user-facing bug quickly, and leaving some uncertainty about what else is likely to come in the future, a revert of this code was decided given the short time to -rc1. Closes-bug: 1291014 Change-Id: I2ed6a861e583b9513b0984ff9801d4b9f7536798
Diffstat (limited to 'nova/virt/images.py')
-rw-r--r--nova/virt/images.py105
1 files changed, 18 insertions, 87 deletions
diff --git a/nova/virt/images.py b/nova/virt/images.py
index a4de6e41f4..6b23944035 100644
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -19,18 +19,17 @@
Handling of VM disk images.
"""
-import functools
import os
from oslo.config import cfg
from nova import exception
+from nova.image import glance
from nova.openstack.common import fileutils
from nova.openstack.common.gettextutils import _
from nova.openstack.common import imageutils
from nova.openstack.common import log as logging
from nova import utils
-from nova.virt import imagehandler
LOG = logging.getLogger(__name__)
@@ -62,61 +61,23 @@ def convert_image(source, dest, out_format, run_as_root=False):
utils.execute(*cmd, run_as_root=run_as_root)
-def _remove_image_on_exec(context, image_href, user_id, project_id,
- imagehandler_args, image_path):
- for handler, loc, image_meta in imagehandler.handle_image(context,
- image_href,
- user_id,
- project_id,
- image_path):
- # The loop will stop when the handle function returns success.
- handler.remove_image(context, image_href, image_meta, image_path,
- user_id, project_id, loc, **imagehandler_args)
- fileutils.delete_if_exists(image_path)
-
-
-def fetch(context, image_href, path, _user_id, _project_id,
- max_size=0, imagehandler_args=None):
- """Fetch image and returns whether the image was stored locally."""
- imagehandler_args = imagehandler_args or {}
- _remove_image_fun = functools.partial(_remove_image_on_exec,
- context, image_href,
- _user_id, _project_id,
- imagehandler_args)
-
- fetched_to_local = True
- with fileutils.remove_path_on_error(path, remove=_remove_image_fun):
- for handler, loc, image_meta in imagehandler.handle_image(context,
- image_href,
- _user_id,
- _project_id,
- path):
- # The loop will stop when the handle function returns success.
- handler.fetch_image(context, image_href, image_meta, path,
- _user_id, _project_id, loc,
- **imagehandler_args)
- fetched_to_local = handler.is_local()
- return fetched_to_local
-
-
-def fetch_to_raw(context, image_href, path, user_id, project_id,
- max_size=0, imagehandler_args=None):
- path_tmp = "%s.part" % path
- fetched_to_local = fetch(context, image_href, path_tmp,
- user_id, project_id,
- max_size=max_size,
- imagehandler_args=imagehandler_args)
+def fetch(context, image_href, path, _user_id, _project_id, max_size=0):
+ # TODO(vish): Improve context handling and add owner and auth data
+ # when it is added to glance. Right now there is no
+ # auth checking in glance, so we assume that access was
+ # checked before we got here.
+ (image_service, image_id) = glance.get_remote_image_service(context,
+ image_href)
+ with fileutils.remove_path_on_error(path):
+ image_service.download(context, image_id, dst_path=path)
- if not fetched_to_local:
- return
- imagehandler_args = imagehandler_args or {}
- _remove_image_fun = functools.partial(_remove_image_on_exec,
- context, image_href,
- user_id, project_id,
- imagehandler_args)
+def fetch_to_raw(context, image_href, path, user_id, project_id, max_size=0):
+ path_tmp = "%s.part" % path
+ fetch(context, image_href, path_tmp, user_id, project_id,
+ max_size=max_size)
- with fileutils.remove_path_on_error(path_tmp, remove=_remove_image_fun):
+ with fileutils.remove_path_on_error(path_tmp):
data = qemu_img_info(path_tmp)
fmt = data.file_format
@@ -151,9 +112,9 @@ def fetch_to_raw(context, image_href, path, user_id, project_id,
if fmt != "raw" and CONF.force_raw_images:
staged = "%s.converted" % path
LOG.debug("%s was %s, converting to raw" % (image_href, fmt))
-
with fileutils.remove_path_on_error(staged):
convert_image(path_tmp, staged, 'raw')
+ os.unlink(path_tmp)
data = qemu_img_info(staged)
if data.file_format != "raw":
@@ -161,36 +122,6 @@ def fetch_to_raw(context, image_href, path, user_id, project_id,
reason=_("Converted to raw, but format is now %s") %
data.file_format)
- for handler_context in imagehandler.handle_image(context,
- image_href,
- user_id,
- project_id,
- staged):
- (handler, loc, image_meta) = handler_context
- # The loop will stop when the handle function
- # return success.
- handler.move_image(context, image_href, image_meta,
- staged, path,
- user_id, project_id, loc,
- **imagehandler_args)
-
- for handler_context in imagehandler.handle_image(context,
- image_href,
- user_id,
- project_id,
- path_tmp):
- (handler, loc, image_meta) = handler_context
- handler.remove_image(context, image_href, image_meta,
- path_tmp, user_id, project_id, loc,
- **imagehandler_args)
+ os.rename(staged, path)
else:
- for handler_context in imagehandler.handle_image(context,
- image_href,
- user_id,
- project_id,
- path_tmp):
- (handler, loc, image_meta) = handler_context
- handler.move_image(context, image_href, image_meta,
- path_tmp, path,
- user_id, project_id, loc,
- **imagehandler_args)
+ os.rename(path_tmp, path)