from os import environ # Native Module for System Level Calls
import swiftclient # SwiftStack Python Client :: https://pypi.python.org/pypi/python-swiftclient
import frontmatter # Frontmatter module :: https://pypi.python.org/pypi/python-frontmatter
import requests # Requests: HTTP for Humans :: http://docs.python-requests.org/en/latest/
** Below is a link to a raw
post from My Course Blog**
The post discusses using SwiftStack for Georgia Tech students.
post_raw = 'https://raw.githubusercontent.com/Materials-Informatics-Lab/Materials-Informatics-Lab.github.io/master/_posts/2014-10-07-Swift-Stack-on-Storm.html'
In my class, I try to make my blog posts as functional as possible. I use Jekyll pages and YAML front matter in my posts. This way I can use information in both a blog presentation layer and as data in my computing environments.
requests
and frontmatter
modules I can pull information...req = requests.get( post_raw )
authurl = "https://" + frontmatter.loads(req.text).metadata['swift'][2]['value']
post_url = frontmatter.loads(req.text).metadata['url']
metadata = frontmatter.loads(req.text).metadata
req.close()
The Front Matter contains information that could information that could be reused programmatically. It is easily converted to Python variables using python-frontmatter
.
All of the frontmatter information from the post is available in the variable metadata
print metadata
{'layout': 'post', 'title': 'SwiftStack on Storm', 'url': 'http://materials-informatics-lab.github.io/2014/10/07/Swift-Stack-on-Storm.html', 'tagline': 'Personal Object Storage for the Georgia Tech folks... and why SwiftStack Rules!\n', 'references': ['https://www.swiftstack.com/', 'http://www.openstack.org/', 'http://www.rackspace.com/cloud/what_is_cloud_computing/', 'https://github.com/swiftstack', 'https://github.com/swiftstack/django-tastypie', 'https://github.com/swiftstack/sc-benchmark', 'https://wiki.openstack.org/wiki/Main_Page', 'https://swift.storm.gatech.edu/console', 'https://cyberduck.io/?l=en', 'http://www.cloudberrylab.com/free-openstack-storage-explorer.aspx', 'http://www.expandrive.com/', 'https://twitter.com/robdaly', '/assets/SwiftStackClients-CloudberryExplorer.pdf'], 'swift': [{'key': 'Server', 'value': 'swift.storm.gatech.edu'}, {'key': 'Website URL', 'value': 'https://swift.storm.gatech.edu'}, {'key': 'Authentication Service', 'value': 'swift.storm.gatech.edu/auth/v1.0'}, {'key': 'Port', 'value': '443\n'}, {'key': 'User name', 'value': '_GATech User name_\n'}, {'key': 'API/Secret Key', 'value': '_GATech PW_\n'}]}
print "Blog Post from class :: " + post_url
Blog Post from class :: http://materials-informatics-lab.github.io/2014/10/07/Swift-Stack-on-Storm.html
Connect to SwiftStack on Storm using some credentials from the blog post
I have assigned my credentials as environment variables. Never ever expose your passwords to repositories. You can simply add you GT authorization information, but DO NOT add, commit, or push those changes.
swift = swiftclient.Connection(
user = environ['SWIFT_USER'], # Change ``environ['SWIFT_USER']`` to your GT username
key = environ['SWIFT_PASS'], # Change ``environ['SWIFT_PASS']`` to your GT password
authurl = authurl,
insecure = True, # Don't verify SSL certificate
)
from IPython.display import Image
img = swift.get_object( "Personal", "dirty.jpg" )
Image( img[1] )
swift.close()