在nova/api/openstack/compute/contrib目录下创建一个自己的文件,我这里是storage_pool.py
1from nova.api.openstack import wsgi 2from nova.api.openstack import extensions 4#authorize = extensions.extension_authorizer('compute', 'storage_pool') 6class Controller(wsgi.Controller): def detail(self, req): return {'pool_name':'ssd'} 10class Storage_pool(extensions.ExtensionDescriptor): """self-defined Nova-api""" name = "Storage_pool" alias = "os-storage-pool" namespace = "http://docs.openstack.org/compute/ext/storage_pool/api/v1.1" updated = "2011-08-08T00:00:00Z" def get_resources(self): resources = [] res = extensions.ResourceExtension( 'os-storage-pool', Controller(), collection_actions={'detail':'GET'}) resources.append(res) 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{ "pool_name": "ssd" 3}