openstack swift middleware开发

首先MiddleWare核心代码,这段代码卸载swift的源代码目录下,~/swift/swift/common/middleware下新建deletionpreventing.py:

import os
from swift.common.swob import Request, Response

class DeletionPreventingMiddleware(object):
    def __init__(self, app,conf):
        self.app = app
        print "vincent middleware"
        print app
    def __call__(self, env, start_response):
        print "it in deletionprevention middleware"
        if env[‘REQUEST_METHOD‘] != ‘DELETE‘:
            print "not put method"
            return self.app(env, start_response)
        return Response( status=403, body="Delete prohibited", content_type="text/plain")(env, start_response)
def filter_factory(global_conf, **local_conf):
    conf = global_conf.copy()
    conf.update(local_conf)
    print conf
    def deletionpreventing_filter(app):
        print "deletion"
        return DeletionPreventingMiddleware(app, conf)
    return deletionpreventing_filter

在/etc/swift/proxy-server.conf中添加中间件

[pipeline:main]
pipeline = catch_errors healthcheck cache ratelimit tempauth deletionpreventing proxy-logging proxy-server

[filter:deletionpreventing]
  use = egg:swift#deletionpreventing
  myconf=value1

其中deletionpriventing就是我们自己定义的中间件

然后在~/swift/swift.egg-info目录下的entry_point.txt中添加中间件:

deletionpreventing = swift.common.middleware.deletionpreventing:filter_factory

在~/swift/setup.cfg中添加中间件

deletionpreventing = swift.common.middleware.deletionpreventing:filter_factory

测试运行:

[email protected] ~/swift $ curl -v -H "X-Storage-User:test:tester" -H "X-Storage-Pass:testing" http://127.0.0.1:8080/auth/v1.0
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /auth/v1.0 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Storage-User:test:tester
> X-Storage-Pass:testing
>
< HTTP/1.1 200 OK
< X-Storage-Url: http://127.0.0.1:8080/v1/AUTH_test
< X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
< Content-Type: text/html; charset=UTF-8
< X-Storage-Token: AUTH_tkf36387dd367b474383cfac60979bed45
< X-Trans-Id: tx0b4c7f7dee284e0d9dd5b-005630e592
< Content-Length: 0
< Date: Wed, 28 Oct 2015 15:11:14 GMT
<
* Connection #0 to host 127.0.0.1 left intact
[email protected] ~/swift $ 

查看列表:

[email protected] ~/swift $ curl -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /v1/AUTH_test/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
>
< HTTP/1.1 200 OK
< Content-Length: 20
< X-Account-Object-Count: 2
< X-Account-Storage-Policy-Policy-0-Bytes-Used: 12
< X-Account-Storage-Policy-Policy-0-Container-Count: 4
< X-Timestamp: 1444721178.82674
< X-Account-Storage-Policy-Policy-0-Object-Count: 2
< X-Account-Bytes-Used: 12
< X-Account-Container-Count: 4
< Content-Type: text/plain; charset=utf-8
< Accept-Ranges: bytes
< X-Trans-Id: tx1533138aaa0c4c6b99dfc-005630e60f
< Date: Wed, 28 Oct 2015 15:13:19 GMT
<
ab
ab2
hello
hello1
* Connection #0 to host 127.0.0.1 left intact
[email protected] ~/swift $ 

测试PUT请求:

[email protected] ~/swift $ curl -X PUT -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/ab3
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> PUT /v1/AUTH_test/ab3 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
>
< HTTP/1.1 201 Created
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
< X-Trans-Id: tx6010eaabf2e64f4fa69dd-005630e642
< Date: Wed, 28 Oct 2015 15:14:10 GMT
<
* Connection #0 to host 127.0.0.1 left intact
[email protected] ~/swift $ curl -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /v1/AUTH_test/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
>
< HTTP/1.1 200 OK
< Content-Length: 24
< X-Account-Object-Count: 2
< X-Account-Storage-Policy-Policy-0-Bytes-Used: 12
< X-Account-Storage-Policy-Policy-0-Container-Count: 5
< X-Timestamp: 1444721178.82674
< X-Account-Storage-Policy-Policy-0-Object-Count: 2
< X-Account-Bytes-Used: 12
< X-Account-Container-Count: 5
< Content-Type: text/plain; charset=utf-8
< Accept-Ranges: bytes
< X-Trans-Id: tx6c0f7ff0121740a190b6f-005630e646
< Date: Wed, 28 Oct 2015 15:14:14 GMT
<
ab
ab2
ab3
hello
hello1
* Connection #0 to host 127.0.0.1 left intact

PUT成功

测试DELETE请求:

[email protected] ~/swift $ curl -X DELETE -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/ab3
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> DELETE /v1/AUTH_test/ab3 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
>
< HTTP/1.1 403 Forbidden
< Content-Length: 17
< Content-Type: text/plain
< X-Trans-Id: tx5426c7feb84c41f29b837-005630e66f
< Date: Wed, 28 Oct 2015 15:14:55 GMT
<
* Connection #0 to host 127.0.0.1 left intact
Delete [email protected] ~/swift $ 

DELETE请求失败,说明中间件起作用了

时间: 2024-10-27 09:42:26

openstack swift middleware开发的相关文章

OpenStack Swift client开发

如果你搭建好了Swift环境 ,你应该可以通过Swift 命令 来尝试去测试上传下载等功能,这是因为在安装Swift的时候,通常会安装一个python-swiftclient客户端,这个一个python的开源 项目 同样使用apache2.0许可,是Swift的client端,如果你使用java PHP  在github上同样有对应的client端,但是功能有局限性. 开源的好处就是,可以方便学习,第一次看python代码,整理出来流程,加上自己的环境,可以马上就开始应用起来. Swift 基于

Linux # 部署OpenStack Swift 开发环境

blog.csdn.net/lzueclipse/article/details/26405753#1536434-qzone-1-61807-cac534f6a16e831f54c45c717ec6acf9 部署OpenStack Swift 开发环境--SAIO - Swift All In One,遇到的问题和解决 - 坚持学习 lzueclipse 一个小白的分布式存储之路 [email protected] - 博客频道 - CSDN.NET blog.sina.com.cn/s/bl

[转载] 对象存储(2):OpenStack Swift——概念、架构与规模部署

原文: http://www.testlab.com.cn/Index/article/id/1085.html#rd?sukey=fc78a68049a14bb228cb2742bdec2b9498806815fcb59399eee501874bb9e9086bce3050baf1438179330d72d2508871 摘要:开源的最大魅力,是能够满足人们的探索欲和求知欲,让我们可以很深入地了解一个系统,如果我们发现它的设计或者实现中有任何不合理的或者错误的地方,我们可以提出自己的想法并且实

OpenStack Swift集群部署流程与简单使用

转载:http://www.cnblogs.com/fczjuever/p/3224022.html 之前介绍了<OpenStack Swift All In One安装部署流程与简单使用>,那么接下来就说一说Swift集群部署吧. 1. 简介 本文档详细描述了使用两台PC部署一个小型Swift集群的过程,并给出一些简单的使用实例.本文档假定如下前提条件: 使用Ubuntu操作系统. 每台机器都运行Swift的所有服务,既是Proxy Server,又是Storage Server,用户可以向

理解 OpenStack Swift (2):架构、原理及功能 [Architecture, Implementation and Features]

本系列文章着重学习和研究OpenStack Swift,包括环境搭建.原理.架构.监控和性能等. (1)OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置 (2)原理.架构和性能 (3)监控 1. 架构 1.1 总体架构 Swift 的总体架构非常的清晰和独立: # 分层(Tier) 组件(Service) 功能(Function) 特性 部署考量 1 访问层(Access Tier) Load Balancer 硬件(比如F5)或者软件(比如HAPro

理解 OpenStack Swift (3):监控和一些影响性能的因素 [Monitoring and Performance]

本系列文章着重学习和研究OpenStack Swift,包括环境搭建.原理.架构.监控和性能等. (1)OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置 (2)原理.架构和性能 (3)监控 对 Swift 集群的监控是必要的,特别是集群规模很大的时候. 1. 监控目标 主要的监控目标包括: 硬件故障 操作系统故障 Swift 集群健康状态 Swift 集群状态 2. Swift 提供的工具 2.1 Swift 自带的各种 Audit 工具 2.1.1

理解 OpenStack Swift (1):OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置

本系列文章着重学习和研究OpenStack Swift,包括环境搭建.原理.架构.监控和性能等. (1)OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置 (2)Swift 原理和架构 (3)Swift 监控 (4)Swift 性能 要实现的系统的效果图: 特点: 使用三个对等物理节点,每个节点上部署所有Swift 服务 使用开源的 UCARP 控制一个 VIP,它会被绑定到三个物理网卡中的一个. 使用开源的 HAProxy 做负载均衡 开启 Swift

Android &amp;Swift iOS开发:语言与框架对比

转载自:http://www.infoq.com/cn/articles/from-android-to-swift-ios?utm_campaign=rightbar_v2&utm_source=infoq&utm_medium=articles_link&utm_content=link_text 从Android到Swift iOS开发:语言与框架对比 我从2009年开始做Android开发,开始接触Swift是在2014年底,当时组里曾经做过一个Demo App,感觉技术还

openstack swift节点安装手册3-最后的安装配置及验证

以下步骤都在controller节点上执行 1.远程获取/etc/swift/swift.conf文件: curl -o /etc/swift/swift.conf https://git.openstack.org/cgit/openstack/swift/plain/etc/swift.conf-sample?h=stable/newton 2.修改/etc/swift/swift.conf配置文件: [swift-hash] ... swift_hash_path_suffix = HAS