概述
本文针对对象存储OSS的基本功能,提供能测试的方法和脚本
一些基于boto3API的简单操作示例:boto3API.py
1 | #!/usr/bin/env python |
用户管理
用户的管理是通过Admin Ops API提供;这里我们通过之前创建好的管理账户来执行Admin Ops API,具体可以参考:http://docs.ceph.com/docs/master/radosgw/adminops/
创建用户
1 | $ cat usercreate.sh |
删除用户
1 | $ cat userdelete.sh |
User keys
管理User的keys也是通过admin Ops API操作的,同样需要通过管理账户来执行;
创建user key
1 | $cat createKey.sh |
删除user key
1 | cat removeKey.sh |
列出user keys
1 | cat getUserInfo.sh |
权限管理
开源的比较常用的s3的SDK有boto3,我们在RDS的备份中已经使用过
参考:http://boto3.readthedocs.io/en/latest/reference/services/s3.html#s3
下面的操作都简要列出了调用的api和说明;
获取Bucket权限
get_bucket_acl(**kwargs)
- Gets the access control policy for the bucket.
设置Bucket权限
put_bucket_acl(**kwargs)
- Sets the permissions on a bucket using access control lists (ACL).
Bucket操作
同权限管理,下面的操作基于boto3,都简要列出了调用的api和说明;
列出Buckets
list_buckets()
- Returns a list of all buckets owned by the authenticated sender of the request.
创建Bucket
create_bucket(**kwargs)
- Creates a new bucket.
删除Bucket
delete_bucket(**kwargs)
- Deletes the bucket. All objects (including all object versions and Delete Markers) in the bucket must be deleted before the bucket itself can be deleted.
列出Bucket Objects
list_objects(**kwargs)
Returns some or all (up to 1000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket.list_objects_v2(**kwargs)
Returns some or all (up to 1000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. Note: ListObjectsV2 is the revised List Objects API and we recommend you use this revised API for new application development.
获取Bucket ACL
get_bucket_acl(**kwargs)
- Gets the access control policy for the bucket.
设置Bucket ACL
put_bucket_acl(**kwargs)
- Sets the permissions on a bucket using access control lists (ACL).
获取Bucket Info
head_bucket(**kwargs)
- This operation is useful to determine if a bucket exists and you have permission to access it.
枚举Bucket分块上传
list_multipart_uploads(**kwargs)
- This operation lists in-progress multipart uploads.
Object操作
上传Object
put_object(**kwargs)
Adds an object to a bucket.upload_file(Filename, Bucket, Key, ExtraArgs=None, Callback=None, Config=None)
Upload a file to an S3 object.upload_fileobj(Fileobj, Bucket, Key, ExtraArgs=None, Callback=None, Config=None)
Upload a file-like object to S3.
The file-like object must be in binary mode.
This is a managed transfer which will perform a multipart upload in multiple threads if necessary.
复制Object
copy_object(**kwargs)
- Creates a copy of an object that is already stored in Amazon S3.
删除Object
delete_object(**kwargs)
Removes the null version (if there is one) of an object and inserts a delete marker, which becomes the latest version of the object. If there isn’t a null version, Amazon S3 does not remove any objects.delete_objects(**kwargs)
This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000 keys.
下载Object
get_object(**kwargs)
Retrieves objects from Amazon S3.download_file(Bucket, Key, Filename, ExtraArgs=None, Callback=None, Config=None)
Download an S3 object to a file.download_fileobj(Bucket, Key, Fileobj, ExtraArgs=None, Callback=None, Config=None)
Download an object from S3 to a file-like object.
The file-like object must be in binary mode.
This is a managed transfer which will perform a multipart download in multiple threads if necessary.
获取Object ACL
get_object_acl(**kwargs)
- Returns the access control list (ACL) of an object.
设置Object ACL
put_object_acl(**kwargs)
- uses the acl subresource to set the access control list (ACL) permissions for an object that already exists in a bucket
获取Object Info
head_object(**kwargs)
- The HEAD operation retrieves metadata from an object without returning the object itself. This operation is useful if you’re only interested in an object’s metadata. To use HEAD, you must have READ access to the object.
支持Object Multipart
create_multipart_upload(**kwargs)
Initiates a multipart upload and returns an upload ID.complete_multipart_upload(**kwargs)
Completes a multipart upload by assembling previously uploaded parts.abort_multipart_upload(**kwargs)
Aborts a multipart upload.
To verify that all parts have been removed, so you don’t get charged for the part storage, you should call the List Parts operation and ensure the parts list is empty.upload_part(**kwargs)
Uploads a part in a multipart upload.
其他操作
获取RGW User统计信息
1 | $ cat getUsage.sh |
删除RGW User统计信息
1 | $ cat trimeUsage.sh |