Linode API Bindings

Python Bindings
Development history available in 3 blog posts: Part 1, Part 2, Part 3.

Source code available in a git repo
git clone http://git.atxconsulting.com/linode/
and browesable at http://git.atxconsulting.com/cgi-bin/gitweb.cgi?p=linode;a=summary
There are two modules:

  • api.py -- this contains all the base methods as defined by the documentation. pydoc generated documentation
  • shell.py -- is a means to run commands from api.py via command line operations
    • API Examples

      import api
      linode = api.Api('sekritmmmcakekey')
      for domain in linode.domainList():
        print domain
        for rr in linode.domainResourceList(domainid=domain['DOMAINID']):
          print rr

      produces
      {u'REFRESH_SEC': 0, u'RETRY_SEC': 0, u'DOMAIN': u'example.com', u'DOMAINID': 36, u'STATUS': 1, u'TTL_SEC': 0, u'SOA_EMAIL': u'test@example.com', u'TYPE': u'master'}
      {u'REFRESH_SEC': 0, u'RETRY_SEC': 0, u'DOMAIN': u'example3.com', u'DOMAINID': 14, u'STATUS': 0, u'TTL_SEC': 0, u'SOA_EMAIL': u'webmaster@example3.com', u'TYPE': u'master'}
      {u'DOMAINID': 14, u'NAME': u'', u'RESOURCEID': 52, u'TARGET': u'67.18.89.93', u'TYPE': u'A', u'TTL_SEC': 0}
      {u'DOMAINID': 14, u'NAME': u'www', u'RESOURCEID': 53, u'TARGET': u'67.18.89.93', u'TYPE': u'A', u'TTL_SEC': 0}
      {u'DOMAINID': 14, u'NAME': u'mail', u'RESOURCEID': 54, u'TARGET': u'67.18.89.93', u'TYPE': u'A', u'TTL_SEC': 0}
      {u'DOMAINID': 14, u'NAME': u'dynamic', u'RESOURCEID': 6719, u'TARGET': u'192.168.0.101', u'TYPE': u'a', u'TTL_SEC': 0}

      shell example
      tjlappy:linode tjfontaine$ ./shell.py --domainList
      [
        {
          "REFRESH_SEC": 0, 
          "RETRY_SEC": 0, 
          "DOMAIN": "example.com", 
          "DOMAINID": 36, 
          "STATUS": 1, 
          "TTL_SEC": 0, 
          "SOA_EMAIL": "test@example.com", 
          "TYPE": "master"
        }, 
        {
          "REFRESH_SEC": 0, 
          "RETRY_SEC": 0, 
          "DOMAIN": "example3.com", 
          "DOMAINID": 14, 
          "STATUS": 0, 
          "TTL_SEC": 0, 
          "SOA_EMAIL": "webmaster@example3.com", 
          "TYPE": "master"
        }
      ]

      The shell generates dynamic help, if you modify shell.py to load an alternative library that descends from Api you'll be able to access those methods and parameters and you'll be able to do more higher level operations like updating a resource record by domain name and not by domain id.

      shell help

      tjlappy:linode tjfontaine$ ./shell.py --help
      shell.py --<api action> [--parameter1=value [--parameter2=value [...]]]
      Valid Actions
      	--domainDelete
      	--domainGet
      	--domainList
      	--domainResourceDelete
      	--domainResourceGet
      	--domainResourceList
      	--domainResourceSave
      	--domainSave
      	--linodeList
      Valid Named Parameters
      	--domain=
      	--domainid=
      	--master_ips=
      	--name=
      	--port=
      	--priority=
      	--refresh_sec=
      	--resourceid=
      	--retry_sec=
      	--soa_email=
      	--status=
      	--target=
      	--ttl_sec=
      	--type=
      	--weight=