Created
August 27, 2014 10:49
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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