Search This Blog

Friday, July 27, 2012

Stale data and caching problem when dealing with cloud API responses

Because the Rackspace cloud API is using caching extensively you have to write a code that is able to handle a stale HTTP data and be able to resent the request if needed.

Example 

A simple example that sometimes works and another time may not work because the API HTTP response contains 404 status code.

from cloudservers import CloudServers
cs=CloudServers(user, key)
cs.authenticate()
sm=cs.servers
server=sm.create(name, image, flavor)
sm.find( name=_server.name )

The cloud 'find' function [1] raises exception NotFound even though we know that the server is there and it shouldn't. 

Traceback (most recent call last):
  File "performance-single-cs.py", line 175, in module
    Main().run()
  File "performance-single-cs.py", line 172, in run
    self.test_performance(user,key)
  File "performance-single-cs.py", line 134, in test_performance
    t.test_perf_single_cs(1)
  File "performance-single-cs.py", line 105, in test_perf_single_cs
    status=self.check_cs_status(server)
  File "performance-single-cs.py", line 45, in check_cs_status
    server=sm.find( name=_server.name )
  File "/usr/lib/pymodules/python2.7/cloudservers/base.py", line 50, in find
    raise NotFound(404, "No %s matching %s." % (self.resource_class.__name__, kwargs))


References

[1] http://packages.python.org/python-cloudservers/ref/servers.html#classes

No comments:

Post a Comment