Search This Blog

Tuesday, July 24, 2012

Rackspace python-cloudservers debugging

For the first generation of Rackspace cloud there is a cli tool and a python library [1].
The source code can the tool can be found on github [2].

Problem description

After successful installation of this tool I run into the follow error below.
 
# cat /etc/issue
Ubuntu 11.04 \n \l
# aptitude install python-rackspace-cloudservers

$ cloudservers --username user --apikey 391c7...be1  show 10197279
Traceback (most recent call last):
  File "/usr/bin/cloudservers", line 9, in 
    load_entry_point('python-cloudservers==1.0a5', 'console_scripts', 'cloudservers')()
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 409, in main
    CloudserversShell().main(sys.argv[1:])
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 123, in main
    self.cs.authenticate()
  File "/usr/lib/pymodules/python2.7/cloudservers/__init__.py", line 60, in authenticate
    self.client.authenticate()
  File "/usr/lib/pymodules/python2.7/cloudservers/client.py", line 79, in authenticate
    resp, body = self.request(self.AUTH_URL, 'GET', headers=headers)
  File "/usr/lib/pymodules/python2.7/cloudservers/client.py", line 34, in request
    body = json.loads(body) if body else None
  File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 360, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 378, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Troubleshooting


Investigating the stacktrace we see that there are various method called before the error was reported. Looking at the stack from bottom up we see that the the code gets interested around lines 12 and 13.

$ sed -n 79p  /usr/lib/pymodules/python2.7/cloudservers/client.py
        resp, body = self.request(self.AUTH_URL, 'GET', headers=headers)

$ grep AUTH_URL /usr/lib/pymodules/python2.7/cloudservers/client.py 
    AUTH_URL = 'https://auth.api.rackspacecloud.com/v1.0'
        resp, body = self.request(self.AUTH_URL, 'GET', headers=headers)

We see that the URL is hard coded in python code. Because my cloud account is base in London (my cloud files and cloud server provisioning regions are in London ) this URL is wrong. More info about the authentication point can be found in the official doc [3].

An easy fix for this requires to change the URL to a new one:

https://lon.auth.api.rackspacecloud.com/v1.0

References

[1] http://packages.python.org/python-cloudservers/index.html
[2] https://github.com/rackspace/python-cloudservers
[3]
http://docs.rackspace.com/api/
http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/Overview-d1e70.html

[4] http://www.dimitrioskouzisloukas.com/blog/index.php?blog=2&title=authenticate_with_cloudservers_to_the_lo&more=1&c=1&tb=1&pb=1

No comments:

Post a Comment