OpenStack kilo 扩展nova api方法
作者:互联网
在nova/api/openstack/compute/contrib目录下创建一个自己的文件,我这里是storage_pool.py
1from nova.api.openstack import wsgi
2from nova.api.openstack import extensions
3
4#authorize = extensions.extension_authorizer('compute', 'storage_pool')
5
6class Controller(wsgi.Controller):
7 def detail(self, req):
8 return {'pool_name':'ssd'}
9
10class Storage_pool(extensions.ExtensionDescriptor):
11 """self-defined Nova-api"""
12 name = "Storage_pool"
13 alias = "os-storage-pool"
14 namespace = "http://docs.openstack.org/compute/ext/storage_pool/api/v1.1"
15 updated = "2011-08-08T00:00:00Z"
16
17 def get_resources(self):
18 resources = []
19 res = extensions.ResourceExtension(
20 'os-storage-pool',
21 Controller(),
22 collection_actions={'detail':'GET'})
23 resources.append(res)
24 return resources
要是先一个extensions api需要创建一个类继承ExtensionDescriptor,并复写get_resources方法。在这里的get_resources方法中,定义了一个自定义的集合操作detail,这个操作对应的处理方法是detail方法,detail方法在Controller类中定义,它返回一个字典。
验证:
1curl -v -X GET -H "X-Auth-Token: $OS_TOKEN" http://controller:8774/v2/f429c2349d0b03aa3c70c73723/os-storage-pool/detail |python -m json.tool
返回:
1{
2 "pool_name": "ssd"
3}
标签:storage,detail,nova,api,extensions,pool,kilo,resources 来源: https://blog.51cto.com/u_15127625/2758232