Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Created August 27, 2014 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nottrobin/ac1b53ec464c17cc20b3 to your computer and use it in GitHub Desktop.
Save nottrobin/ac1b53ec464c17cc20b3 to your computer and use it in GitHub Desktop.
Get swift container URL using swiftclient (also works with python-swiftclient <= 0.8)
#!/usr/bin/python
# Credit to Chris Stanford for this
import os
import sys
from swiftclient import client
userName = os.getenv('OS_USERNAME')
userPass = os.getenv('OS_PASSWORD')
userTenant = os.getenv('OS_TENANT_NAME')
authURL = os.getenv('OS_AUTH_URL')
regionName = os.getenv('OS_REGION_NAME')
if not (userName and userPass and userTenant and authURL and regionName):
print "Unable to find auth parameters in environment (OS_USERNAME, etc.)"
sys.exit(1)
if len(sys.argv) < 2:
print "Usage: {} <container>".format(os.path.basename(sys.argv[0]))
sys.exit(1)
containerName = sys.argv[1]
swift = client.Connection(authURL, userName, userPass, 5, auth_version='2.0',
os_options={'tenant_name': userTenant, 'region_name': regionName})
head = swift.head_container(containerName)
path= "{}/{}".format(swift.url, containerName)
print path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment