Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Neil-Jubinville/ba7e4d779a968c140ed07170de295201 to your computer and use it in GitHub Desktop.
Save Neil-Jubinville/ba7e4d779a968c140ed07170de295201 to your computer and use it in GitHub Desktop.
Swift Usage Examples
Execute the following command and make a note of X-Auth-Token. You will need this token to use in all subsequent commands.
curl -v -H 'X-Storage-User: system:root' -H 'X-Storage-Pass: testpass' http://10.80.83.68:8077/auth/v1.0
In the following command examples we are using 'AUTH_tk65840af9f6f74d1aaefac978cb8f0899' as the X-Auth-Token. Replace this with the appropriate token you obtained in the above step.
To create a container:
curl -X PUT -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
To list all containers in current account:
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/
Uploading a file "file1" to container "mycontainer"
curl -X PUT -T file1 -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/
To list all objects in a container:
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
To list all objects in a container that starts with a particular prefix "fi":
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/?prefix=fi
To download a particular file "file1" from the container "mycontainer":
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/file1
To download file1 and save it locally as localfile1:
curl -o localfile1 -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/file1
To delete a container "mycontainer"
curl -X DELETE -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
To delete a specific file "file1" from the container:
curl -X DELETE -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/file1
To get metadata associated with a Swift account:
curl -v -X HEAD -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/
To get metadata associated with a container:
curl -v -X HEAD -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
You can request the data from Swift in XML or JSON format by specifying the "format" paramater. This parameter can be applied to any of the above requests. Here are a few examples:
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/?format=json
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/?format=xml
The above operations can also be done using 'swift' command. For instructions on using 'swift' command, please refer to "swift --help".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment