您好,登錄后才能下訂單哦!
OpenStack中怎么擴(kuò)展自定義功能,針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。
Text代碼
[pipeline:openstackapi11] pipeline = faultwrap authtoken keystonecontext ratelimit audit extensions osapiapp11 [filter:audit] paste.filter_factory = nova.api.openstack.audit:AuditMiddleware.factory
然后我們寫一個(gè)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進(jìn)程,然后在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
這里默認(rèn)記錄所有的非GET請(qǐng)求,如果不想將PUT請(qǐng)求記錄(PUT對(duì)應(yīng)更新),在配置文件里面更改一下:
Text代碼
[filter:audit] audit_methods=POST,DELETE
關(guān)于OpenStack中怎么擴(kuò)展自定義功能問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。