Skip to content

Instantly share code, notes, and snippets.

@s-chb
Last active June 25, 2020 17:06
Show Gist options
  • Select an option

  • Save s-chb/d07e7d1d17884c18d7e0e6e49eb4b536 to your computer and use it in GitHub Desktop.

Select an option

Save s-chb/d07e7d1d17884c18d7e0e6e49eb4b536 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from com.obs.client.obs_client import ObsClient
from com.obs.models.delete_objects_request import DeleteObjectsRequest, Object
# Setup the credentials
AK='put here your public access key'
SK='put here your secret access key'
server='put here your endpoint'
bucketName = 'put here the name of the bucket you wanna create or you wanna deal with'
# Constructs an obs client instance with your account for accessing OBS
obsClient = ObsClient(
access_key_id=AK,
secret_access_key=SK,
server=server
)
def createBucket():
resp = obsClient.createBucket(bucketName)
if resp.status < 300:
print('Create bucket:' + bucketName + ' successfully!\n')
else:
print(resp.errorCode)
def getBucketLocation():
resp = obsClient.getBucketLocation(bucketName)
if resp.status < 300:
print('Getting bucket location ' + str(resp.body) + ' \n')
else:
print(resp.errorCode)
def getBucketStorageInfo():
resp = obsClient.getBucketStorageInfo(bucketName)
if resp.status < 300:
print('Getting bucket storageInfo ' + str(resp.body) + ' \n')
else:
print(resp.errorCode)
def deleteBucket():
print('Deleting bucket ' + bucketName + '\n')
resp = obsClient.deleteBucket(bucketName)
print('common msg:status:', resp.status, ',errorCode:', resp.errorCode, ',errorMessage:', resp.errorMessage)
# Run Methods
createBucket()
getBucketLocation()
getBucketStorageInfo()
deleteBucket()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment