nova-api扩展(1)

实现nova-api调用的filter,将调用记录保存到本地文件中和保存到数据库中

普通流程

关闭api

killall nova-api

编写filter

nova/api/openstack/compute/customs.py

from nova import wsgi as base_wsgi



import webob.dec



from oslo_log import log as logging



from nova.api.openstack import wsgi



LOG = logging.getLogger(__name__)



class RecordsMiddleware(base_wsgi.Middleware):



        def __init__(self,application):



                base_wsgi.Middleware.__init__(self,application)



        @webob.dec.wsgify(RequestClass=wsgi.Request)



        def __call__(self,req):



                file = open('/home/stack/customs/records','a')



                record = req.path_info + '\n'



                #LOG



                file.write(record)



                file.close()



                return self.application

配置filter

/etc/nova/api-paste.ini

1、增加filter

 

2、把filter添加到composit的keystone pipeline下

 nova-api扩展(1)

启动api

nova-api

查看~/stack/coutoms/record

 nova-api扩展(1)

你可能感兴趣的:(nova)