• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Lifecycle Management
  5. Viewing Lifecycle Rules

Viewing Lifecycle Rules

You can call ObsClient.getBucketLifecycleConfiguration to view lifecycle rules 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.getBucketLifecycleConfiguration('bucketname')
 
if resp.status < 300:
    print('requestId:', resp.requestId)
    index = 1
    for rule in resp.body.lifecycleConfig.rule:
        print('rule [' + str(index) + ']')
        print('id:', rule.id)
        print('prefix:', rule.prefix)
        print('status:', rule.status)
        if rule.transition:
            print('days:' , rule.transition.days)
            print('date:' , rule.transition.date)
            print('storageClass:' , rule.transition.storageClass)
        if rule.expiration:
            print('days:' , rule.expiration.days)
            print('date:' , rule.expiration.date)
        if rule.noncurrentVersionTransition:
            print('noncurrentDays:' , rule.noncurrentVersionTransition.noncurrentDays)
            print('storageClass:' , rule.noncurrentVersionTransition.storageClass)
        if rule.noncurrentVersionExpiration:
            print('noncurrentDays:' , rule.noncurrentVersionExpiration.noncurrentDays)
    index += 1
else:
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)