~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/common/images.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-05 12:21:37 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20150105122137-171bqrdpcxqipunk
Tags: 2015.1~b1-0ubuntu1
* New upstream beta release:
  - d/control: Align version requirements with upstream release.
* d/watch: Update uversionmangle to deal with kilo beta versioning
  changes.
* d/control: Bumped Standards-Version to 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
import jinja2
26
26
from oslo.config import cfg
 
27
from oslo_concurrency import processutils
27
28
 
28
29
from ironic.common import exception
29
30
from ironic.common.i18n import _
34
35
from ironic.openstack.common import fileutils
35
36
from ironic.openstack.common import imageutils
36
37
from ironic.openstack.common import log as logging
37
 
from ironic.openstack.common import processutils
38
38
 
39
39
LOG = logging.getLogger(__name__)
40
40
 
231
231
    utils.execute(*cmd, run_as_root=run_as_root)
232
232
 
233
233
 
234
 
def fetch(context, image_href, path, image_service=None):
 
234
def fetch(context, image_href, path, image_service=None, force_raw=False):
235
235
    # TODO(vish): Improve context handling and add owner and auth data
236
236
    #             when it is added to glance.  Right now there is no
237
237
    #             auth checking in glance, so we assume that access was
243
243
        with open(path, "wb") as image_file:
244
244
            image_service.download(image_href, image_file)
245
245
 
246
 
 
247
 
def fetch_to_raw(context, image_href, path, image_service=None):
248
 
    path_tmp = "%s.part" % path
249
 
    fetch(context, image_href, path_tmp, image_service)
250
 
    image_to_raw(image_href, path, path_tmp)
 
246
    if force_raw:
 
247
        image_to_raw(image_href, path, "%s.part" % path)
251
248
 
252
249
 
253
250
def image_to_raw(image_href, path, path_tmp):
267
264
                                              {'fmt': fmt,
268
265
                                               'backing_file': backing_file})
269
266
 
270
 
        if fmt != "raw" and CONF.force_raw_images:
 
267
        if fmt != "raw":
271
268
            staged = "%s.converted" % path
272
269
            LOG.debug("%(image)s was %(format)s, converting to raw" %
273
270
                    {'image': image_href, 'format': fmt})
303
300
 
304
301
    """
305
302
    data = qemu_img_info(path)
306
 
    if data.file_format == "raw" or not CONF.force_raw_images:
307
 
        return 0
308
303
    return data.virtual_size
309
304
 
310
305
 
357
352
    with utils.tempdir() as tmpdir:
358
353
        kernel_path = os.path.join(tmpdir, kernel_uuid)
359
354
        ramdisk_path = os.path.join(tmpdir, ramdisk_uuid)
360
 
        fetch_to_raw(context, kernel_uuid, kernel_path)
361
 
        fetch_to_raw(context, ramdisk_uuid, ramdisk_path)
 
355
        fetch(context, kernel_uuid, kernel_path)
 
356
        fetch(context, ramdisk_uuid, ramdisk_path)
362
357
 
363
358
        params = []
364
359
        if root_uuid: