python_swift_project_middleware

1. 寫openstack swift的middleware 首先要肯定swift用的是哪一個middleware文件。 好比healthcheck這個中間件,在機器上有不少同名文件以下,python

這兩行多是源代碼
/etc/swift/swift-src/swift/common/middleware/healthcheck.py
/etc/swift/swift-src/build/lib.linux-x86_64-2.7/swift/common/middleware/healthcheck.py


這行不知道幹嗎的
/usr/share/pyshared/swift/common/middleware/healthcheck.py
這行連接到上一行
/usr/lib/python2.7/dist-packages/swift/common/middleware/healthcheck.py
/usr/lib/python2.7/dist-packages/swift/common/middleware/healthcheck.pyc

這行是真正用的。而且在修改這個文件後不須要compile成pyc直接重啓 swift便可
/usr/local/lib/python2.7/dist-packages/swift/common/middleware/healthcheck.py
/usr/local/lib/python2.7/dist-packages/swift/common/middleware/healthcheck.pyc

2. 肯定了middleware文件的位置爲/usr/local後,在這個目錄下嘗試建立一個文件,而後配置。linux

首先,建立一箇中間件文件。我是把一個現成的中間件文件copy過來。固然要改裏面的類名之類的信息。swift

其次在/etc/swift/proxy-server.conf裏作以下配置。myck是個人中間件文件curl

pipeline = catch_errors healthcheck myck cache authtoken keystoneauth proxy-server

除了上面一行還有下面一行ui

[filter:myck]
paste.filter_factory = swift.common.middleware.myck:filter_factory

OK 重啓swift便可看到新的中間件生效this

swift-init all restarturl

root@A071103070098:~# curl -D- -H 'X-Storage-User: admin:admin' -H 'X-Storage-Pass: root1234' http://10.194.148.102:8080/myck
HTTP/1.0 200 OK
Content-Type: text/plain
X-Trans-Id: tx5421cc00cae8401682b42-00540a6ceb
Date: Sat, 06 Sep 2014 02:09:47 GMT
Content-Length: 83
Age: 0
X-Cache: MISS from NS-M46903639710
X-Cache-Lookup: MISS from NS-M46903639710:8080
Connection: close

OK this is from /usr/local. Do not need to recompile this file,just restart swift 
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息