~gundlach/nova/servers_api

« back to all changes in this revision

Viewing changes to nova/api/rackspace/__init__.py

  • Committer: Cerberus
  • Date: 2010-09-29 22:24:36 UTC
  • mfrom: (295.1.15 trunk)
  • Revision ID: matt.dietz@rackspace.com-20100929222436-haxgq7uool12oqs1
Merge from trunk and networking setup for new instances

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from nova import flags
32
32
from nova import utils
33
33
from nova import wsgi
 
34
from nova.api.rackspace import faults
34
35
from nova.api.rackspace import backup_schedules
35
36
from nova.api.rackspace import flavors
36
37
from nova.api.rackspace import images
67
68
        user = self.auth_driver.authorize_token(req.headers["X-Auth-Token"])
68
69
 
69
70
        if not user:
70
 
            return webob.exc.HTTPUnauthorized()
 
71
            return faults.Fault(webob.exc.HTTPUnauthorized())
71
72
 
72
73
        if not req.environ.has_key('nova.context'):
73
74
            req.environ['nova.context'] = {}
112
113
        delay = self.get_delay(action_name, username)
113
114
        if delay:
114
115
            # TODO(gundlach): Get the retry-after format correct.
115
 
            raise webob.exc.HTTPRequestEntityTooLarge(headers={
116
 
                    'Retry-After': time.time() + delay})
 
116
            exc = webob.exc.HTTPRequestEntityTooLarge(
 
117
                    explanation='Too many requests.',
 
118
                    headers={'Retry-After': time.time() + delay})
 
119
            raise faults.Fault(exc)
117
120
        return self.application
118
121
 
119
122
    def get_delay(self, action_name, username):
165
168
                        controller=sharedipgroups.Controller())
166
169
 
167
170
        super(APIRouter, self).__init__(mapper)
 
171
 
 
172
 
 
173
def limited(items, req):
 
174
    """Return a slice of items according to requested offset and limit.
 
175
    
 
176
    items - a sliceable
 
177
    req - wobob.Request possibly containing offset and limit GET variables.
 
178
          offset is where to start in the list, and limit is the maximum number
 
179
          of items to return.
 
180
 
 
181
    If limit is not specified, 0, or > 1000, defaults to 1000.
 
182
    """
 
183
    offset = int(req.GET.get('offset', 0))
 
184
    limit = int(req.GET.get('limit', 0))
 
185
    if not limit:
 
186
        limit = 1000
 
187
    limit = min(1000, limit)
 
188
    range_end = offset + limit
 
189
    return items[offset:range_end]
 
190