X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=azure%2Fazure.py;h=0d19ed4c1c7abb1d1e953c9825014573f4ba8975;hb=9d32f47c84c4b8aae2ec6fd63d1a4f008228e82f;hp=dd0173edf1ca410ef14603f5ef606d61fda51550;hpb=4282ffea530c1e6a6e7350545d8708abd8fbe248;p=bluesky.git diff --git a/azure/azure.py b/azure/azure.py index dd0173e..0d19ed4 100755 --- a/azure/azure.py +++ b/azure/azure.py @@ -15,7 +15,7 @@ def uri_decode(s): # TODO return s -def add_auth_header(headers, method, path): +def add_auth_headers(headers, method, path): header_order = ['Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Date', 'If-Modified-Since', 'If-Match', 'If-None-Match', 'If-Unmodified-Since', @@ -69,26 +69,37 @@ def add_auth_header(headers, method, path): signature = base64.b64encode(h.digest()) headers['Authorization'] = "SharedKey %s:%s" % (account_name, signature) -def generate_request(path, method='GET', body="", headers={}): - host = os.environ['AZURE_ACCOUNT_NAME'] + ".blob.core.windows.net" - #auth_path = conn.calling_format.build_auth_path(self.bucket, key) - - headers = headers.copy() - headers['Content-Length'] = str(len(body)) - if len(body) > 0: - headers['Content-MD5'] = base64.b64encode(hashlib.md5(body).digest()) - add_auth_header(headers, method, path) - - req = "%s %s HTTP/1.1\r\nHost: %s\r\n" % (method, path, host) - req = req + ''.join("%s: %s\r\n" % h for h in headers.items()) + "\r\n" - print req - - conn = httplib.HTTPConnection(host) - conn.request(method, path, body, headers) - response = conn.getresponse() - print "Response:", response.status - print "Headers:", response.getheaders() - print "Body:", response.read() - -if False: - generate_request("/?comp=list") +class Connection: + def __init__(self): + self.host = os.environ['AZURE_ACCOUNT_NAME'] + ".blob.core.windows.net" + self.conn = httplib.HTTPConnection(self.host) + + def make_request(self, path, method='GET', body="", headers={}): + headers = headers.copy() + headers['Content-Length'] = str(len(body)) + if len(body) > 0: + headers['Content-MD5'] \ + = base64.b64encode(hashlib.md5(body).digest()) + add_auth_headers(headers, method, path) + + # req = "%s %s HTTP/1.1\r\nHost: %s\r\n" % (method, path, host) + # req = req + ''.join("%s: %s\r\n" % h for h in headers.items()) + "\r\n" + # print req + + self.conn.request(method, path, body, headers) + response = self.conn.getresponse() + print "Response:", response.status + print "Headers:", response.getheaders() + body = response.read() + +if __name__ == '__main__': + # generate_request("/?comp=list") + buf = 'A' * 1048576 + conn = Connection() + for i in range(16): + conn.make_request('/benchmark/file-1M-' + str(i), 'PUT', buf, + {'x-ms-blob-type': 'BlockBlob'}) + + conn = Connection() + for i in range(16): + conn.make_request('/benchmark/file-1M-' + str(i), 'GET')