ceph 中rgw对象的etag

import hashlib
import boto
import traceback
from boto.s3.connection import S3Connection
class ETagExample(object):
    def __init__(self):
        self.s3_bucket = "yuliyang6"
        self.s3_conn = boto.connect_s3(
            "admin",
            "admin",
            host="192.168.10.147",
            is_secure=False,
            port=8081,
            calling_format=boto.s3.connection.OrdinaryCallingFormat(),
        )
    #Function to calculate the checksum of a local file
    def find_checksum(self, file_name):
        try:
            checksum = hashlib.md5(open(file_name).read()).hexdigest()
            return checksum
        except Exception, e:
            print "Exception occurred while calculating checksum :" + str(e)
            print traceback.print_exc()

    #Function to calculate the Etag of a file in S3
    def find_etag(self, full_key_name):
        try:
            bucket = self.s3_conn.get_bucket(self.s3_bucket)
            key = bucket.get_key(full_key_name)
            s3_etag = key.etag.strip('"').strip("'")
            return s3_etag
        except Exception, e:
            print "Exception occurred while calculating S3 Etag : " + str(e)
            print traceback.print_exc()

if __name__ == '__main__':
    test = ETagExample()
    print test.find_checksum('object1')
    print test.find_etag('object1')


320c1c0f22dc91d94afe36a042ebc89d
send: 'HEAD /yuliyang6/ HTTP/1.1\r\nHost: 192.168.10.147:8081\r\nAccept-Encoding: identity\r\nDate: Sun, 06 Nov 2016 07:54:51 GMT\r\nContent-Length: 0\r\nAuthorization: AWS admin:P7eaeSj73/8dObIeJtIac/ZwXzA=\r\nUser-Agent: Boto/2.41.0 Python/2.7.9 Windows/7\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: X-RGW-Object-Count: 1
header: X-RGW-Bytes-Used: 847
header: x-amz-request-id: tx0000000000000000004f6-00581ee1cb-857b-default
header: Content-Length: 0
header: Date: Sun, 06 Nov 2016 07:54:51 GMT
send: 'HEAD /yuliyang2/ HTTP/1.1\r\nHost: 192.168.10.147:8081\r\nAccept-Encoding: identity\r\nDate: Sun, 06 Nov 2016 07:54:51 GMT\r\nContent-Length: 0\r\nAuthorization: AWS admin:FOtHjwG9XIHPaoBy8TT8QDB3y0I=\r\nUser-Agent: Boto/2.41.0 Python/2.7.9 Windows/7\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: X-RGW-Object-Count: 4
header: X-RGW-Bytes-Used: 104858452
header: x-amz-request-id: tx0000000000000000004f7-00581ee1cb-857b-default
header: Content-Length: 0
header: Date: Sun, 06 Nov 2016 07:54:51 GMT
send: 'HEAD /yuliyang2/object1 HTTP/1.1\r\nHost: 192.168.10.147:8081\r\nAccept-Encoding: identity\r\nDate: Sun, 06 Nov 2016 07:54:51 GMT\r\nContent-Length: 0\r\nAuthorization: AWS admin:KADu0hAVS1BVs3Y9zTIO7dRovCs=\r\nUser-Agent: Boto/2.41.0 Python/2.7.9 Windows/7\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Content-Length: 847
header: Accept-Ranges: bytes
header: Last-Modified: Sun, 06 Nov 2016 07:54:12 GMT
header: ETag: "320c1c0f22dc91d94afe36a042ebc89d"
header: x-amz-request-id: tx0000000000000000004f8-00581ee1cb-857b-default
header: Content-Type: binary/octet-stream
header: Date: Sun, 06 Nov 2016 07:54:51 GMT
320c1c0f22dc91d94afe36a042ebc89d


[root@joke ceph-request]# ceph-request -c ceph-request.cfg  -m head -r '/yuliyang2/object1'  -v
< HEAD /yuliyang2/object1 HTTP/1.1
< Host: 192.168.10.147:8081
< Connection: keep-alive
< Accept-Encoding: gzip, deflate
< Accept: */*
< User-Agent: python-requests/2.11.1
< date: Sun, 06 Nov 2016 07:54:28 GMT
< Authorization: AWS admin:qCWFpvxlOfSERMeaV/sfVm0Wcek=
< 

> HTTP/1.1 200 OK
> Content-Length: 847
> Accept-Ranges: bytes
> Last-Modified: Sun, 06 Nov 2016 07:54:12 GMT
> ETag: "320c1c0f22dc91d94afe36a042ebc89d"
> x-amz-request-id: tx0000000000000000004f5-00581ee1b4-857b-default
> Content-Type: binary/octet-stream
> Date: Sun, 06 Nov 2016 07:54:28 GMT
> Connection: Keep-Alive
> 

转载于:https://my.oschina.net/leeyoung/blog/782471

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值