Swift Object Store
Goal
Use the command-line utility swift
to perform operations on your object store.
Requirements
Note
FIXME: TBD
Swift client documentation
Useful commands
command | description |
---|---|
list | Lists the containers for the account or the objects for a container. |
capabilities | Retrieve capability of the proxy. |
post | Updates meta information on the account, container, or object. If the container is not found, it will be created automatically. |
stat | Displays information for the account, container, or object. |
upload | Uploads specified files and directories to the given container. |
download | Download objects from containers. |
tempurl | Generates a temporary URL for a Swift object. |
delete | Delete a container or objects within a container. |
For a more detailed explanation of any specific command, add --help
after it:
Example
$ swift list --help
Usage: swift list [--long] [--lh] [--totals] [--prefix <prefix>]
[--delimiter <delimiter>] [--header <header:value>]
[--versions] [<container>]
Lists the containers for the account or the objects for a container.
Positional arguments:
[<container>] Name of container to list object in.
Optional arguments:
-l, --long Long listing format, similar to ls -l.
--lh Report sizes in human readable format similar to
ls -lh.
-t, --totals Used with -l or --lh, only report totals.
-p <prefix>, --prefix <prefix>
Only list items beginning with the prefix.
-d <delim>, --delimiter <delim>
Roll up items with the given delimiter. For containers
only. See OpenStack Swift API documentation for what
this means.
-j, --json Display listing information in json
--versions Display listing information for all versions
-H, --header <header:value>
Adds a custom request header to use for listing.
Create an object container
Create the container named "flex-container01":
If you like, make the container public:
Verify the container's configuration:
Example
FIXME: Example coming soon!
Upload files to the container
Upload the entire contents of a folder to the container:
Example
Uploading an entire folder will add that prefix to your filenames inside the container.
Example
Filter the display of files only with the prefix by using the --prefix
argument:
Example
Downloading files
When the container is public, you can access each file using a specific URL, made up of your region's endpoint, the name of your container, the prefix (if any) of your object, and finally, the object name.
Using the swift client to download a single file:
Using the swift client to download multiple files with the same prefix:
Deleting containers or objects
Similar to downloading, you can delete multiple files with the same prefix:
Example
Deleting a container:
Deleting a container will delete all files in the container.
Setting and removing object expiration
Swift objects can be scheduled to expire by setting either the X-Delete-At
or X-Delete-After
header.
Once the object expires, swift will no longer serve the object, and it will be deleted.
Expire at a specific time
Obtain the current Unix epoch timestamp by running date +%s
.
Set an object to expire at an absolute Unix epoch timestamp:
Verify the header has been applied to the object:
Expire after a number of seconds
Set an object to expire after a relative amount of time, in seconds:
The X-Delete-After
header will be converted to X-Delete-At
.
Verify the header has been applied to the object:
Remove the expire header
If you no longer want the object to expire, you can remove the X-Delete-At
header:
Additional documentation
Additional documentation can be found at the official swift client site, on the Openstack Documentation Site.
https://docs.openstack.org/python-openstackclient/latest/