~ubuntu-branches/ubuntu/trusty/glance/trusty

« back to all changes in this revision

Viewing changes to glance/store/gridfs.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, James Page
  • Date: 2013-09-09 13:06:09 UTC
  • mfrom: (1.1.54)
  • Revision ID: package-import@ubuntu.com-20130909130609-33p9xrv7zu4b5sh7
Tags: 1:2013.2~b3-0ubuntu1
[ Chuck Short ]
* New upstream release. 
* debian/control: Add python-oslo.sphinx as a build 
  dependency.

[ James Page ]
* d/p/*: Refreshed patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import urlparse
23
23
 
24
24
from glance.common import exception
 
25
from glance.openstack.common import excutils
25
26
import glance.openstack.common.log as logging
26
27
import glance.store
27
28
import glance.store.base
38
39
LOG = logging.getLogger(__name__)
39
40
 
40
41
gridfs_opts = [
41
 
    cfg.StrOpt('mongodb_store_uri'),
42
 
    cfg.StrOpt('mongodb_store_db', default=None),
 
42
    cfg.StrOpt('mongodb_store_uri',
 
43
               help="Hostname or IP address of the instance to connect to, "
 
44
                    "or a mongodb URI, or a list of hostnames / mongodb URIs. "
 
45
                    "If host is an IPv6 literal it must be enclosed "
 
46
                    "in '[' and ']' characters following the RFC2732 "
 
47
                    "URL syntax (e.g. '[::1]' for localhost)"),
 
48
    cfg.StrOpt('mongodb_store_db', default=None, help='Database to use'),
43
49
]
44
50
 
45
51
CONF = cfg.CONF
180
186
        LOG.debug(_("Adding a new image to GridFS with id %s and size %s") %
181
187
                 (image_id, image_size))
182
188
 
183
 
        self.fs.put(image_file, _id=image_id)
184
 
        image = self._get_file(loc)
 
189
        try:
 
190
            self.fs.put(image_file, _id=image_id)
 
191
            image = self._get_file(loc)
 
192
        except:
 
193
            # Note(zhiyan): clean up already received data when
 
194
            # error occurs such as ImageSizeLimitExceeded exception.
 
195
            with excutils.save_and_reraise_exception():
 
196
                self.fs.delete(image_id)
185
197
 
186
198
        LOG.debug(_("Uploaded image %s, md5 %s, length %s to GridFS") %
187
199
                 (image._id, image.md5, image.length))