from keystoneauth1 import session
from keystoneauth1.identity import v3
from swiftclient import client
username = 'admin'
tenant_name = 'admin'
password = 'password'
auth_url='http://192.x.x.x/identity/v3'
auth = v3.Password(auth_url=auth_url,
username=username,
password=password,
project_name=tenant_name,
user_domain_id='default',
project_domain_id='default')
sess = session.Session(auth=auth)
swift_conn = client.Connection(session=sess)
Ich habe versucht, Ausnahmebehandlung zu schreiben, aber ... über Memo
try:
resp_headers, containers = swift_conn.get_account()
except session.exceptions.Unauthorized:
print "The request you have made requires authentication."
except client.ClientException:
print "Account GET failed"
print(containers)
Informationen zur von bpython angezeigten Methode.
swift_conn.get_account: (self, marker=None, limit=None, prefix=None,
end_marker=None, full_listing=False, headers=None)
get_account
Wrapper for :func:`get_account`
container = 'new-container'
swift_conn.put_container(container)
Informationen zur von bpython angezeigten Methode.
container
ist erforderlich.
swift_conn.put_container: (self, container, headers=None,
response_dict=None, query_string=None)
put_container
Wrapper for :func:`put_container`
container = 'new-container'
with open('local.txt', 'r') as local:
swift_conn.put_object(
container=container,
obj='local_object.txt',
contents=local,
content_type='text/plain'
)
Informationen zur von bpython angezeigten Methode.
container, obj, content
sind erforderlich.
swift_conn.put_object: (self, container, obj, contents,
content_length=None, etag=None, chunk_size=None, content_type=None,
headers=None, query_string=None, response_dict=None)
put_object
Wrapper for :func:`put_object`
obj = 'local_object.txt
container = 'new-container'
resp_headers, obj_contents = swift_conn.get_object(container, obj)
with open('local_copy.txt','w') as local:
local.write(obj_contents)
Informationen zur von bpython angezeigten Methode.
container, obj
ist erforderlich.
swift_conn.get_object: (self, container, obj, resp_chunk_size=None,
query_string=None, response_dict=None, headers=None)
get_object
Wrapper for :func:`get_object`
obj = 'local_object.txt'
container = 'new-container'
try:
swift_conn.delete_object(container, obj)
print("Successfully deleted the object")
except ClientException as e:
print("Failed to delete the object with error: %s" % e)
Informationen zur von bpython angezeigten Methode.
container, obj
ist erforderlich.
swift_conn.delete_object: (self, container, obj, query_string=None,
response_dict=None, headers=None)
delete_object
Wrapper for :func:`delete_object`
Geben Sie den normalen Pfad mit "obj" an, aber der Pfad, der mit "/" endet, wird als Ordner erkannt. Wird im Container ein Ordner erstellt? ?? Es tut mir leid, dass ich Swift nicht so gut verstehe (´ ・ ω ・ `)
container = 'new-container'
swift_conn.put_object(
container=container,
obj="folder/",
contents=None,
content_type="application/octet-stream"
)
container = 'new-container'
with open('local.txt', 'r') as local:
swift_conn.put_object(
container=container,
obj='folder/local_object.txt',
contents=local,
content_type='text/plain'
)
Recommended Posts