~ttx/swift/release-1.4.2

« back to all changes in this revision

Viewing changes to swift/common/direct_client.py

  • Committer: Tarmac
  • Author(s): gholt, FUJITA Tomonori, John Dickinson, David Goetz, John Dickinson, Joe Arnold, Scott Simpson, joe at cloudscaling, Thierry Carrez
  • Date: 2011-07-26 09:08:37 UTC
  • mfrom: (305.1.1 milestone-proposed)
  • Revision ID: tarmac-20110726090837-fwlvja8dnk7nkppw
Merge 1.4.2 development from trunk (rev331)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    return _quote(value, safe)
37
37
 
38
38
 
 
39
def direct_get_account(node, part, account, marker=None, limit=None,
 
40
                       prefix=None, delimiter=None, conn_timeout=5,
 
41
                       response_timeout=15):
 
42
    """
 
43
    Get listings directly from the account server.
 
44
 
 
45
    :param node: node dictionary from the ring
 
46
    :param part: partition the account is on
 
47
    :param account: account name
 
48
    :param marker: marker query
 
49
    :param limit: query limit
 
50
    :param prefix: prefix query
 
51
    :param delimeter: delimeter for the query
 
52
    :param conn_timeout: timeout in seconds for establishing the connection
 
53
    :param response_timeout: timeout in seconds for getting the response
 
54
    :returns: a tuple of (response headers, a list of containers) The response
 
55
              headers will be a dict and all header names will be lowercase.
 
56
    """
 
57
    path = '/' + account
 
58
    qs = 'format=json'
 
59
    if marker:
 
60
        qs += '&marker=%s' % quote(marker)
 
61
    if limit:
 
62
        qs += '&limit=%d' % limit
 
63
    if prefix:
 
64
        qs += '&prefix=%s' % quote(prefix)
 
65
    if delimiter:
 
66
        qs += '&delimiter=%s' % quote(delimiter)
 
67
    with Timeout(conn_timeout):
 
68
        conn = http_connect(node['ip'], node['port'], node['device'], part,
 
69
                            'GET', path, query_string='format=json')
 
70
    with Timeout(response_timeout):
 
71
        resp = conn.getresponse()
 
72
    if resp.status < 200 or resp.status >= 300:
 
73
        resp.read()
 
74
        raise ClientException(
 
75
            'Account server %s:%s direct GET %s gave status %s' % (node['ip'],
 
76
                node['port'], repr('/%s/%s%s' % (node['device'], part, path)),
 
77
                resp.status),
 
78
            http_host=node['ip'], http_port=node['port'],
 
79
            http_device=node['device'], http_status=resp.status,
 
80
            http_reason=resp.reason)
 
81
    resp_headers = {}
 
82
    for header, value in resp.getheaders():
 
83
        resp_headers[header.lower()] = value
 
84
    if resp.status == 204:
 
85
        resp.read()
 
86
        return resp_headers, []
 
87
    return resp_headers, json_loads(resp.read())
 
88
 
 
89
 
39
90
def direct_head_container(node, part, account, container, conn_timeout=5,
40
91
                          response_timeout=15):
41
92
    """