Object Storage Swift - Getting started with the Swift API
Objective
You can use the OpenStack API to generate various scripts in order to automate your actions on the Public Cloud.
The OpenStack swiftclient lets you interact with and manage your containers and objects. For example, you can upload files to your containers regularly in order to back them up.
This guide will help you get started with the OpenStack API in order to manage your object containers using the python-swiftclient.
Requirements
- Preparing the environment to use the OpenStack API by installing python-swiftclient
- Setting the OpenStack environment variables
Instructions
Please note that the following instructions only pertain to the command line interface of a GNU/Linux distribution, after implementing the requirements above.
Swift documentation
You can retrieve the list of possible commands from the client's documentation:
Here is the list of the main commands:
For an explanation of a specific Swift command, add --help at the end of it:
You can also consult the Swift documentation available on the OpenStack website.
Creating a public object container
- Create the container "container1":
- Configure the access rights to make your container public:
- Check the container configuration:
Uploading files to your container
- Upload the content of a local folder to a container:
A prefix will automatically be added to your files if you send an entire folder instead of a single file.
- List a container's files:
You can display all files with a particular prefix using the --prefix argument:
If the container is configured as public, you can access the file using a URL:
This URL is made up of an endpoint, available from the Horizon interface, the name of your container and the name of your object (including the prefix).
Downloading files
- Download a file:
You can download multiple files with the same prefix, using the following command:
Deleting containers or objects
- Delete a file:
As with downloading, you can delete multiple files using the same prefix, with the following command:
- Delete a container:
This will delete all the files in the container.
Go further
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for assisting you on your specific use case of your project.
Join our community of users.