首先需要定义extension manager类(我定义在/usr/lib/python2.7/site-packages/novaclient/v2/storage.py):

1from novaclient import base  
2
3class StorageExtensionManager(base.ManagerWithFind):  
4    def list(self):  
5        pass  
6    def get_detail(self):  
7        url
= "/os-storage-pool/detail"  
8        resp,body = self.api.client.get(url)  
9        return body  

StorageExtensionManager类的get_detail方法通过Nova Client对象向nova api发送GET /os-storage-pool/detail请求。这个请求最终会由之前博客中扩展的api处理

调用我们的客户端use_storage.py

 1from novaclient.v2 import client as nova_client  
2from novaclient.v2 import storage  
3
4class ExtensionManagerMeta(object):  
5    def __init__(self, name, manager_class):  
6        self.name
= name  
7        self.manager_class = manager_class  
8
9user = {  
10    'username': 'nova',  
11    'password': 'YOURPASS',  
12    'tenant': 'service',  
13    'authurl': 'http://YOURHOST:5000/v2.0',  
14}  
15
16def storage_client():  
17    extensions
= [ExtensionManagerMeta('storage', storage.StorageExtensionManager)]  
18    client = nova_client.Client(user.get('username'), user.get('password'), project_id = user.get('tenant'), auth_url = user.get('authurl'), extensions = extensions)  
19    return client.storage  
20
21def get_storage_detail():  
22    return storage_client.get_detail()  
23
24if __name__
== '__main__':  
25    print get_storage_detail()  
26

这里的user定义了用户信息,ExtensionManagerMeta定义了extension manager的元数据类。

最后测试一下:

1python use_storage.py   
2{"pool_name": "ssd"}