• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Bucket Management
  5. Setting or Obtaining the Storage Class of a Bucket

Setting or Obtaining the Storage Class of a Bucket

OBS allows you to set storage classes for buckets. The storage class of an object defaults to be that of its residing bucket. Different storage classes meet different needs for storage performance and costs. There are three types of storage class for buckets, as described in the following table:

Storage Class

Description

Value on the OBS Server

OBS Standard

Features low access latency and high throughput and is applicable to storing frequently-accessed (multiple times per month) hotspot or small objects (< 1 MB) requiring quick response.

STANDARD

OBS Warm

Is applicable to storing semi-frequently accessed (less than 12 times a year) data requiring quick response.

STANDARD_IA

OBS Cold

Is applicable to archiving rarely-accessed (once a year) data.

GLACIER

Setting the Storage Class for a Bucket

You can call ObsClient.setBucketStoragePolicy to set the storage class for a bucket. Sample code is as follows:

# Import the module.
from com.obs.client.obs_client import ObsClient

# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',
    secret_access_key='*** Provide your Secret Key ***',        
    server='yourdomainname'
)

# Set the storage class to OBS Warm.
resp = obsClient.setBucketStoragePolicy('bucketname', 'STANDARD_IA')

if resp.status < 300:    
    print('requestId:', resp.requestId)    
else:    
    print('errorCode:', resp.errorCode)    
    print('errorMessage:', resp.errorMessage)

Obtaining the Storage Class of a Bucket

You can call ObsClient.getBucketStoragePolicy to obtain the storage class of a bucket. Sample code is as follows:

# Import the module.
from com.obs.client.obs_client import ObsClient

# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',
    secret_access_key='*** Provide your Secret Key ***',        
    server='yourdomainname'
)

resp = obsClient.getBucketStoragePolicy('bucketname')

if resp.status < 300:    
    print('requestId:', resp.requestId)    
    print('storageClass:', resp.body.storageClass)
else:    
    print('errorCode:', resp.errorCode)    
    print('errorMessage:', resp.errorMessage)