您好,登錄后才能下訂單哦!
OpenStack中怎么擴展自定義功能,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
Text代碼
[pipeline:openstackapi11] pipeline = faultwrap authtoken keystonecontext ratelimit audit extensions osapiapp11 [filter:audit] paste.filter_factory = nova.api.openstack.audit:AuditMiddleware.factory
然后我們寫一個Middleware:
Python代碼
import time
from nova import log as logging
from nova import wsgi as base_wsgi
from nova.api.openstack import wsgi
LOG = logging.getLogger('nova.api.audit')
class AuditMiddleware(base_wsgi.Middleware):
"""store POST/PUT/DELETE api request for audit."""
def __init__(self, application, audit_methods='POST,PUT,DELETE'):
base_wsgi.Middleware.__init__(self, application)
self._audit_methods = audit_methods.split(",")
def process_request(self, req):
self._need_audit = req.method in self._audit_methods
if self._need_audit:
self._request = req
self._requested_at = time.time()
def process_response(self, response):
if self._need_audit and response.status_int >= 200 and response.status_int < 300:
self._store_log(response)
return response
def _store_log(self, response):
req = self._request
LOG.info("tenant: %s, user: %s, %s: %s, at: %s",
req.headers.get('X-Tenant', 'admin'),
req.headers.get('X-User', 'admin'),
req.method,
req.path_info,
self._requested_at)
重啟一下nova-api進程,然后在dashboard上做一些操作,我們就能在日志文件里面看到如下的信息:
Text代碼
tenant: 1, user: admin, POST: /1/os-security-group-rules, at: 1326352441.16 tenant: 1, user: admin, DELETE: /1/servers/32, at: 1326353021.58
這里默認記錄所有的非GET請求,如果不想將PUT請求記錄(PUT對應更新),在配置文件里面更改一下:
Text代碼
[filter:audit] audit_methods=POST,DELETE
關于OpenStack中怎么擴展自定義功能問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。