文档章节

openstack swift middleware开发

Vincent-Duan
 Vincent-Duan
发布于 2016/10/12 23:46
字数 683
阅读 35
收藏 0

首先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

测试运行:

swift@vincent-virtual-machine ~/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
swift@vincent-virtual-machine ~/swift $

查看列表:

swift@vincent-virtual-machine ~/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
swift@vincent-virtual-machine ~/swift $

测试PUT请求:

swift@vincent-virtual-machine ~/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
swift@vincent-virtual-machine ~/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请求:

swift@vincent-virtual-machine ~/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 prohibitedswift@vincent-virtual-machine ~/swift $

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

© 著作权归作者所有

共有 人打赏支持
Vincent-Duan

Vincent-Duan

粉丝 9
博文 307
码字总数 101182
作品 0
海淀
私信 提问
OpenStack Identity(Keystone)身份服务-体系结构与中间件

OpenStack Identity(Keystone)服务为运行OpenStack Compute上的OpenStack云提供了认证和管理用户、帐号和角色信息服务,并为OpenStack Object Storage提供授权服务。 Keystone体系结构 Ke...

三毛々
2012/10/18
0
0
安装Openstack的Mitaka版本的swift服务时,swift服务无法启动

你好,我在安装并且配置好Openstack的Mitaka版本的swift服务后,swift服务无法启动。proxy服务运行在controller node上,并且已经正常运行,chrony服务正常同步时间。 swift服务安装环境如下...

jokk
2016/08/19
608
0
浅谈OpenStack平台的安全问题及措施

OpenStack的优势与劣势 Openstack具有三大特点:免费开源、强大的兼客性以及开放性。 Openstack 本身是一个开源、免费的软件,同商业软件相比它给了客户足够的自由度,可以在任何场合使用,O...

凌洛
2018/05/12
0
0
使用 OpenStack 实现云计算和存储

Infrastructure as a Service (IaaS) 云平台种类繁多,例如像 Nebula 和 Eucalyptus 这样为人熟知的解决方案。而此领域的一个新来者已展示了其不俗的增长,不仅包括用户数量的增长,还包括支...

IBMdW
2012/09/11
18.1K
14
openstack学习之路-level1-1

Openstack各组件介绍 Dashboard 项目名horizon 提供openstack的交互界面,可以在交互界面中管理openstack,比如启动一个实例,配置IP地址,配置用户认证等 Compute 项目名nova 负责openstack...

gyj0825
2018/06/26
0
0

没有更多内容

加载失败,请刷新页面

加载更多

centos7重置密码、单用户模式、救援模式、ls命令、chmod命令

在工作当中如果我们错误的配置了文件使服务器不能正常启动或者忘记密码不能登录系统,如何解决这些问题呢?重装系统是可以实现的,但是往往不能轻易重装系统的,下面用忘记密码作为例子讲解如...

李超小牛子
29分钟前
0
0
Python如何开发桌面应用程序?Python基础教程,第十三讲,图形界面

当使用桌面应用程序的时候,有没有那么一瞬间,想学习一下桌面应用程序开发?行业内专业的桌面应用程序开发一般是C++,C#来做,Java开发的也有,但是比较少。本节课会介绍Python的GUI(图形用...

程序员补给栈
今天
5
0
kafka在的使用

一、基本概念 介绍 Kafka是一个分布式的、可分区的、可复制的消息系统。它提供了普通消息系统的功能,但具有自己独特的设计。 这个独特的设计是什么样的呢? 首先让我们看几个基本的消息系统...

狼王黄师傅
今天
3
0
Android JNI总结

0x01 JNI介绍 JNI是Java Native Interface的缩写,JNI不是Android专有的东西,它是从Java继承而来,但是在Android中,JNI的作用和重要性大大增强。 JNI在Android中起着连接Java和C/C++层的作...

天王盖地虎626
昨天
3
0
大数据教程(11.8)Hive1.2.2简介&初体验

上一篇文章分析了Hive1.2.2的安装,本节博主将分享Hive的体验&Hive服务端和客户端的使用方法。 一、Hive与hadoop直接的关系 Hive利用HDFS存储数据,利用MapReduce查询数据。 二、Hive与传统数...

em_aaron
昨天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部