1. 写openstack swift的middleware 首先要确定swift用的是哪个middleware文件。 比如healthcheck这个中间件,在机器上有很多同名文件如下,
这两行可能是源代码 /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后,在这个目录下尝试创建一个文件,然后配置。
首先,创建一个中间件文件。我是把一个现成的中间件文件copy过来。当然要改里面的类名之类的信息。
其次在/etc/swift/proxy-server.conf里做如下配置。myck是我的中间件文件
pipeline = catch_errors healthcheck myck cache authtoken keystoneauth proxy-server
除了上面一行还有下面一行
[filter:myck] paste.filter_factory = swift.common.middleware.myck:filter_factory
OK 重启swift即可看到新的中间件生效
swift-init all restart
[email protected]:~# 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
时间: 2024-11-04 04:37:26