From 0f55c1759d4f959f4de448289b5f31fc95ae88d5 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 26 Nov 2024 11:51:38 -0500 Subject: [PATCH] examples/rgw: register boto extension for HeadBucket stats Signed-off-by: Casey Bodley --- examples/rgw/boto3/head_bucket_stats.py | 27 +++++++++++++++++ examples/rgw/boto3/service-2.sdk-extras.json | 31 +++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100755 examples/rgw/boto3/head_bucket_stats.py diff --git a/examples/rgw/boto3/head_bucket_stats.py b/examples/rgw/boto3/head_bucket_stats.py new file mode 100755 index 0000000000000..1de40d63f4ac1 --- /dev/null +++ b/examples/rgw/boto3/head_bucket_stats.py @@ -0,0 +1,27 @@ +#!/usr/bin/python + +import boto3 +import sys + +if len(sys.argv) != 2: + print('Usage: ' + sys.argv[0] + ' ') + sys.exit(1) + +# bucket name as first argument +bucketname = sys.argv[1] + +# endpoint and keys from vstart +endpoint = 'http://127.0.0.1:8000' +access_key='0555b35654ad1656d804' +secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==' + +client = boto3.client('s3', + endpoint_url=endpoint, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key) + +# reading bucket stats via HeadBucket + +response = client.head_bucket(Bucket=bucketname, ReadStats=True) + +print('Objects:', response['ObjectCount'], 'Bytes:', response['BytesUsed']) diff --git a/examples/rgw/boto3/service-2.sdk-extras.json b/examples/rgw/boto3/service-2.sdk-extras.json index b81667ecd090b..4618543d61baf 100644 --- a/examples/rgw/boto3/service-2.sdk-extras.json +++ b/examples/rgw/boto3/service-2.sdk-extras.json @@ -379,7 +379,36 @@ }, "documentation":"

A filter for all log object. Filter for the object by its key (prefix, suffix and regex).

", "locationName":"Filter" - } + }, + "HeadBucketRequest": { + "members": { + "ReadStats":{ + "shape":"ReadStats", + "documentation":"

Read additional usage statistics for ObjectCount and BytesUsed in the response.

This request parameter is a Ceph RGW extension.

", + "location":"querystring", + "locationName":"read-stats" + } + } + }, + "HeadBucketOutput":{ + "members":{ + "ObjectCount":{ + "shape":"ObjectCount", + "documentation": "

Total number of objects/versions in the bucket.

", + "location": "header", + "locationName": "x-rgw-object-count" + }, + "BytesUsed":{ + "shape":"BytesUsed", + "documentation": "

Total size in bytes of all objects/versions in the bucket.

", + "location": "header", + "locationName": "x-rgw-bytes-used" + } + } + }, + "ReadStats":{"type":"boolean"}, + "ObjectCount":{"type":"integer"}, + "BytesUsed":{"type":"integer"} }, "documentation":"

" } -- 2.39.5