Exaforge

Cloud, DevOps, Evangelism

Python + CloudFoundry = ❤

Twitter_CF_Avatar_128x128_400x400

As I've been getting more and more into CloudFoundry's infrastructure side (and not just its awesomeness as a developer using it), I've of course been wanting to automate it.

python.sh-600x600

The cf cli is very good, and quite reliable, but it doesn't have XML or JSON output, and really, the CF API is quite accessible and pretty clear.  So I decided I'd like to use Python to do it of course.  I searched PyPI and found a python-cloudfoundry project but noted that it only worked with the CF 1.0 release, not the current v2 API releases.

So because of the awesomeness of the open source community and the CF API documentation, I began to rewrite it.

I'm pleased to announce the first alpha version of python-cloudfoundryv2 is available on my GitHub account.  Check it out, please share feedback and send me some pull requests.

Here's an example of how to use it:

from cloudfoundry import CloudFoundryInterface
import logging
from pprint import pprint,pformat


logging.basicConfig(format='%(asctime)s: %(levelname)s %(module)s:%(funcName)s@%(lineno)d | %(message)s', level=logging.CRITICAL)

def test_app(username,password,api):
    cfi = CloudFoundryInterface(target='api.run.pivotal.io',username=username,password=password,debug=False)
    cfi.login()
    myapp = cfi.get_app_by_name("chargers")
    pprint(myapp)
    pprint(cfi.spaces, cfi.routes)
    new_app = cfi.create_app("api-test-app",cfi.spaces.keys()[0])
    pprint(new_app)