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)
J'ai essayé d'écrire la gestion des exceptions, mais ... à propos du mémo
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)
Informations sur la méthode affichée par bpython.
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)
Informations sur la méthode affichée par bpython. «container» est requis.
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'
)
Informations sur la méthode affichée par bpython.
container, obj, contents
sont obligatoires.
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)
Informations sur la méthode affichée par bpython.
container, obj
est obligatoire.
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)
Informations sur la méthode affichée par bpython.
container, obj
est obligatoire.
swift_conn.delete_object: (self, container, obj, query_string=None,
response_dict=None, headers=None)
delete_object
Wrapper for :func:`delete_object`
Spécifiez le chemin normal avec ʻobj, mais le chemin se terminant par
/` est reconnu comme un dossier.
Un dossier a-t-il été créé dans le conteneur? ??
Je suis désolé de ne pas tellement comprendre Swift (´ ・ ω ・ `)
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