~glance-coresec/glance/trunk

« back to all changes in this revision

Viewing changes to glance/teller/backends/http.py

  • Committer: Tarmac
  • Author(s): Rick Harris
  • Date: 2010-10-05 16:16:42 UTC
  • mfrom: (8.2.10 refactor_swift_authurl)
  • Revision ID: hudson@openstack.org-20101005161642-0h3ugq7i4x2pqn13
With this patch Parallax and teller now work end-to-end with the Swift backend.

bash-3.2$ curl localhost:9292/image?uri=http://localhost:9191/images/2 > testimg.tar.gz
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 189M 0 189M 0 0 203k 0 --:--:-- 0:15:52 --:--:-- 214k

bash-3.2$ md5 testimg.tar.gz
MD5 (testimg.tar.gz) = ef6c5db4f55b0030828b71dd253a2384

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2010 OpenStack, LLC
 
4
# All Rights Reserved.
 
5
#
 
6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
7
#    not use this file except in compliance with the License. You may obtain
 
8
#    a copy of the License at
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
#    Unless required by applicable law or agreed to in writing, software
 
13
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
15
#    License for the specific language governing permissions and limitations
 
16
#    under the License.
 
17
 
 
18
import httplib
 
19
from glance.teller import backends
 
20
 
 
21
class HTTPBackend(backends.Backend):
 
22
    """ An implementation of the HTTP Backend Adapter """
 
23
 
 
24
    @classmethod
 
25
    def get(cls, parsed_uri, expected_size, conn_class=None):
 
26
        """Takes a parsed uri for an HTTP resource, fetches it, and yields the
 
27
        data.
 
28
        """
 
29
 
 
30
        if conn_class:
 
31
            pass # use the conn_class passed in
 
32
        elif parsed_uri.scheme == "http":
 
33
            conn_class = httplib.HTTPConnection
 
34
        elif parsed_uri.scheme == "https":
 
35
            conn_class = httplib.HTTPSConnection
 
36
        else:
 
37
            raise BackendException("scheme '%s' not supported for HTTPBackend")
 
38
        
 
39
        conn = conn_class(parsed_uri.netloc)
 
40
        conn.request("GET", parsed_uri.path, "", {})
 
41
        
 
42
        try:
 
43
            return backends._file_iter(conn.getresponse(), cls.CHUNKSIZE)
 
44
        finally:
 
45
            conn.close()
 
46
 
 
47