Swift Python Script (Legacy Auth)
Version 1 Authentication End of Life - 1/29/2021archived
Install
Make sure you have Python version 2.5 or higher (download python)
Windows: Set the PYTHONPATH environment variable
On your desktop, right-click My Computer, and then click Properties. In the System Properties dialog box, click Advanced, and then click Environment Variables. Under User variables for <username> (the top half of this window), click New. In the New User Variable dialog box, type "PYTHONPATH" in the Variable name box. In the Variable Value box, type "%PYTHONPATH%;C:\YourPythonFolder" (replace "C:\YourPythonFolder" with the location where you installed Python), and then click OK.
Download the swift.py script
Navigate to the location where the script is installed and type "swift.py" - you should see a list of all the script options
Test the connection (replace "account", "username" and "password" with your own)
swift.py -A https://cloud.sdsc.edu/auth/v1.0 -U <account>:<username> -K <password> stat
Set environment variables to avoid having to type common options each time:
ST_AUTH: server name (https://cloud.sdsc.edu/auth/v1.0)
ST_USER: username
ST_KEY: password
Command Line Examples
post [options] [container] [object]
Updates meta information for the account, container, or object depending on the args given. If the container is not found, it will be created automatically; but this is not true for accounts and objects. Containers also allow the -r (or -read-acl) and -w (or -write-acl) options. The -m or -meta option is allowed on all and used to define the user meta data items to set in the form Name:Value. This option can be repeated.
Example to Create a Container:
swift.py post myContainer
Example to Set Meta Information:
swift.py post -m Color:Blue -m Size:Large
Lists the containers for the account or the objects for a container. -p or -prefix is an option that will only list items beginning with that prefix. -d or -delimiter is option (for container listings only) that will roll up items with the given delimiter, or character that can act as a nested directory organizer.
Example to Show Container Names:
Example to Show Container Contents:
Displays information for the account, container, or object depending on the entry.
Example:
upload [options] container file_or_directory [file_or_directory]
Uploads to the given container the files and directories specified by the remaining args. -c or -changed is an option that will only upload files that have changed since the last upload.
Example to Upload Files to the Container (you can drag and drop your file into the command prompt to get its path):
Example to upload only files that have been changed (saves bandwidth):
download -all OR download container [object] [object]
Downloads everything in the account (with -all), or everything in a container, or a list of objects depending on the args given. For a single object download, you may use the -o [-output] (filename) option to redirect the output to a specific file or if "-" then just redirect to stdout.
Example to Download a Container:
delete-all OR delete container [object] [object]
Deletes everything in the account (with -all), or everything in a container, or a list of objects depending on the args given.Example to Delete a File:swift.py delete myContainer C:\Documents\myFile.txt
Example to Delete a Container:
-version show program’s version number and exit
-h, -help show this help message and exit
-s, -snet Use SERVICENET internal network
-v, -verbose Print more info
-q, -quiet Suppress status output
-A AUTH, -auth=AUTH URL for obtaining an auth token
-U USER, -user=USER User name for obtaining an auth token
-K KEY, -key=KEY Key for obtaining an auth token
Large Files
Note: This section pertains only to uploading files that are individually larger than 5 GB.
Files over the size of 5 GB reach the Cloud by allowing the user to split the file into pieces ("segments") then the Cloud keeps track of how they fit together (a "manifest file" will map the segments together). Once the segments are uploaded, Swift manages the updates to the segments automatically. The following is an example of how to segment, upload and download large files to and from the Cloud, using Swift.
Segment & Upload
This will upload largefile.iso to test_container in 5 segments. In this example, the 2147483648 is the number of bytes in 2 GB. So that indicates that largefile.iso is 10 GB.
Example:
swift.py upload -S <file size in bytes> <container name> <file name>
Now, to download the large file as a single object:
You may edit your file segments just like any other object within Cloud Files. Ensure your files are linked correctly by including your manifest file in your upload. You can change your file name by editing this manifest file as well.
Help
Please email support@sdsc.edu with any problems using the Swift Python script.