Last active
May 10, 2017 15:08
-
-
Save mbonell/0046a9d91bca0cf8ba6940c5e468989b to your computer and use it in GitHub Desktop.
First steps using Shade to interact with OpenStack Swift API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shade import * | |
simple_logging(debug=True) | |
conn = openstack_cloud(cloud='ovh-boston-summit-cloud') | |
# Create a swift container | |
container_name = 'my-pets' | |
container = conn.create_container(container_name) | |
# List containers | |
print(conn.list_containers()) | |
# Upload pictures inside a container | |
pets = {'Euler the Pomeranian': 'pets-pics/euler.jpg', 'An amazing Goat': 'pets-pics/goat.jpg'} | |
for object_name, file_path in pets.items(): | |
conn.create_object(container=container_name, name=object_name, filename=file_path) | |
# List objects inside a container | |
print '\nListing objets in %s' % container_name | |
print(conn.list_objects(container_name)) | |
# Delete objects inside a container | |
print '\nDeleting objects in %s' % container_name | |
for object in conn.list_objects(container_name): | |
print('Good bye %s!' % object['name']) | |
conn.delete_object(container_name, object['name']) | |
# Delete an empty container | |
conn.delete_container(container_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment