def swift_conn(authurl, user, project, password): ''' authurl : http://keystone:5000 user: aaa project: aaa password: bbb ''' # by default add http schema if not authurl.startswith("http"): authurl = "http://" + authurl os_options = {"tenant_name": project} conn = SwiftConnection(authurl=authurl, user=user, key=password, os_options=os_options, auth_version=3) conn.get_auth() yield conn conn.close()
from swiftclient.client import Connection auth = v3.Password(auth_url='http://192.168.122.68:5000/v3', user_domain_name='default', username='******', password='******', project_domain_name='default', project_name='admin') sess = session.Session(auth=auth) try: client = Connection('2', session=sess) # print(client.get_account()) print(client.put_container('fake-container')) # print(client.post_container('fake-container-1', headers={'x-container-meta-new': 'value'})) with open('/home/kiennt/Pictures/XIEC_2014_029.jpg', 'r') as local: print(client.put_object( 'fake-container', 'fake-obj', contents=local, )) # print(client.get_container('fake-container')) # print(client.post_object('fake-container', 'fake-obj', {'x-object-meta-newkey': 'newvalue'})) # print(client.head_object('fake-container', 'fake-obj')) print( client.copy_object('fake-container', 'fake-obj', headers=None, destination='/fake-container/fake-obj')) finally: client.close()