OpenStack is great but as all young projects it has some UX issues. One of the most user facing is initialization of OpenStack python clients. Every OpenStack Service like Nova, Cinder, Glance have own.
Since the begging in Rally we have internal class that unifies initialization of all clients. Recently we merged patch that allows to init this class from environment variables, which makes it really simple to use OpenStack python clients. Take a look at code snippet below:
boris@ubuntu:~$ . devstack/openrc admin admin boris@ubuntu:~$ python >>> from rally import osclients >>> clients = osclients.Clients.create_from_env() >>> clients.nova().flavors.list() [<Flavor: m1.tiny>, <Flavor: m1.small>, <Flavor: m1.medium>, <Flavor: m1.large>, <Flavor: m1.nano>, <Flavor: m1.heat>, <Flavor: m1.xlarge>, <Flavor: m1.micro>]
Another nice thing that you should know about rally.osclients is that Clients() instance caches all initialized python clients inside it self. In other words you don’t need to create a billions of variables for every client:
>>> with utils.Timer() as timer: ... c = clients.cinder() ... [c.volumes.list() for i in range(50)] ... >>> timer.duration() 0.91 seconds >>> with utils.Timer() as timer: ... [clients.cinder().volumes.list() for i in range(50)] ... >>> timer.duration() 0.91 seconds
Impact of cache is so huge that can be easily measured by next sample:
>>> with utils.Timer() as timer: ... [clients.clear() or clients.cinder().volumes.list() for i in range(50)] ... # clients.clear() purge cache so client is inited on every iteration >>> timer.duration() 10.59 seconds
This small and awesome feature is one more brick in the future Rally library.