~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/virt/images.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    #             checked before we got here.
52
52
    (image_service, image_id) = nova.image.get_image_service(context,
53
53
                                                             image_href)
54
 
    try:
 
54
    with utils.remove_path_on_error(path):
55
55
        with open(path, "wb") as image_file:
56
56
            metadata = image_service.get(context, image_id, image_file)
57
 
    except Exception:
58
 
        with utils.save_and_reraise_exception():
59
 
            try:
60
 
                os.unlink(path)
61
 
            except OSError, e:
62
 
                if e.errno != errno.ENOENT:
63
 
                    LOG.warn("unable to remove stale image '%s': %s" %
64
 
                             (path, e.strerror))
65
 
    return metadata
 
57
            return metadata
66
58
 
67
59
 
68
60
def fetch_to_raw(context, image_href, path, user_id, project_id):
85
77
 
86
78
        return(data)
87
79
 
88
 
    data = _qemu_img_info(path_tmp)
89
 
 
90
 
    fmt = data.get("file format")
91
 
    if fmt is None:
92
 
        os.unlink(path_tmp)
93
 
        raise exception.ImageUnacceptable(
94
 
            reason=_("'qemu-img info' parsing failed."), image_id=image_href)
95
 
 
96
 
    if "backing file" in data:
97
 
        backing_file = data['backing file']
98
 
        os.unlink(path_tmp)
99
 
        raise exception.ImageUnacceptable(image_id=image_href,
100
 
            reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % locals())
101
 
 
102
 
    if fmt != "raw" and FLAGS.force_raw_images:
103
 
        staged = "%s.converted" % path
104
 
        LOG.debug("%s was %s, converting to raw" % (image_href, fmt))
105
 
        out, err = utils.execute('qemu-img', 'convert', '-O', 'raw',
106
 
                                 path_tmp, staged)
107
 
        os.unlink(path_tmp)
108
 
 
109
 
        data = _qemu_img_info(staged)
110
 
        if data.get('file format', None) != "raw":
111
 
            os.unlink(staged)
 
80
    with utils.remove_path_on_error(path_tmp):
 
81
        data = _qemu_img_info(path_tmp)
 
82
 
 
83
        fmt = data.get("file format")
 
84
        if fmt is None:
 
85
            raise exception.ImageUnacceptable(
 
86
                reason=_("'qemu-img info' parsing failed."),
 
87
                image_id=image_href)
 
88
 
 
89
        if "backing file" in data:
 
90
            backing_file = data['backing file']
112
91
            raise exception.ImageUnacceptable(image_id=image_href,
113
 
                reason=_("Converted to raw, but format is now %s") %
114
 
                data.get('file format', None))
115
 
 
116
 
        os.rename(staged, path)
117
 
 
118
 
    else:
119
 
        os.rename(path_tmp, path)
 
92
                reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % locals())
 
93
 
 
94
        if fmt != "raw" and FLAGS.force_raw_images:
 
95
            staged = "%s.converted" % path
 
96
            LOG.debug("%s was %s, converting to raw" % (image_href, fmt))
 
97
            with utils.remove_path_on_error(staged):
 
98
                out, err = utils.execute('qemu-img', 'convert', '-O', 'raw',
 
99
                                         path_tmp, staged)
 
100
 
 
101
                data = _qemu_img_info(staged)
 
102
                if data.get('file format', None) != "raw":
 
103
                    raise exception.ImageUnacceptable(image_id=image_href,
 
104
                        reason=_("Converted to raw, but format is now %s") %
 
105
                        data.get('file format', None))
 
106
 
 
107
                os.rename(staged, path)
 
108
 
 
109
        else:
 
110
            os.rename(path_tmp, path)
120
111
 
121
112
    return metadata