Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Support for Legacy Accounts will be discontinued on 1/29/2021

Install

  1. 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.

  2. Download the swift.py script

  3. Navigate to the location where the script is installed and type "swift.py" - you should see a list of all the script options

  4. Test the connection (replace "account", "username" and "password" with your own)

    Code Block
    languagebash
    swift.py -A https://cloud.sdsc.edu/auth/v1.0 -U <account>:<username> -K <password> stat


  5. Set environment variables to avoid having to type common options each time:

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:

Code Block
languagebash
swift.py post myContainer

Example to Set Meta Information:

Code Block
languagebash
swift.py post -m Color:Blue -m Size:Large

list [options] [container]

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:

Code Block
languagebash
swift.py list

Example to Show Container Contents:

Code Block
languagebash
swift.py list myContainer

stat [container] [object]

Displays information for the account, container, or object depending on the entry.

Example:

Code Block
languagebash
swift.py stat

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):

Code Block
languagebash
swift.py upload myContainer C:\Documents\myFolder

Example to upload only files that have been changed (saves bandwidth):

Code Block
languagebash
swift.py upload -c myContainer C:\Documents\myFolder

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:

Code Block
languagebash
swift.py download myContainer

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:

Code Block
languagebash
swift.py delete myContainer

Options for Swift

-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.

Code Block
languagebash
input:
swift.py upload -S 2147483648 test_container largefile.iso

output:
largefile.iso segment 1
largefile.iso segment 4
largefile.iso segment 3
largefile.iso segment 2
largefile.iso segment 0
largefile.iso

...

Example: 
swift.py upload -S <file size in bytes> <container name> <file name>

Now, to download the large file as a single object:

Code Block
languagebash
input:
swift.py  download test_container largefile.iso

output:
largefile.iso
You can list the segments, and download them separately if you want:
swift list test_container_segments
largefile.iso/1300906481.0/10485760/00000000
largefile.iso/1300906481.0/10485760/00000001
largefile.iso/1300906481.0/10485760/00000002
largefile.iso/1300906481.0/10485760/00000003
largefile.iso/1300906481.0/10485760/00000004
largefile.iso/1300906481.0/10485760/00000005
largefile.iso/1300906481.0/10485760/00000006
largefile.iso/1300906481.0/10485760/00000007
largefile.iso/1300906481.0/10485760/00000008
largefile.iso/1300906481.0/10485760/00000009

...


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.