ceph rbd 封装api
1.安装python,uwsgi,nginx环境
pip安装省略
yumgroupinstall"Developmenttools"
yuminstallzlib-develbzip2-develpcre-developenssl-develncurses-develsqlite-develreadline-develtk-devel
yuminstallpython-devel
pipinstalluwsgi
2.明白 Restful API
http://www.ruanyifeng.com/blog/2014/05/restful_api.html
3.了解flask框架
http://www.pythondoc.com/flask-restful/first.html
4.调用python插件库
http://docs.ceph.org.cn/rbd/librbdpy/
5.写接口程序
#!/usr/bin/env python
# -*- coding: utf-8 -*- from flask import Flask, jsonify, make_response
import rados
import rbd
from flask.ext.httpauth import HTTPBasicAuth
import time
'''
ceph 接口封装,主要实现 CRD 功能
curl xxx.xx.xx.xx2/ceph/v1.0/rbd -u admin:d41d8cd98f00b204e9fdsafdsafdasf333f
curl -X POST xxx.xx.xx.xx/ceph/v1.0/rbd/images/V0/10234556 -u admin:d8cd98f00b204e9fdsafdsafdasf333f
curl -X DELETE xxx.xx.xx.xx/ceph/v1.0/rbd/images/cai-ceph-a3 -u admin:d8cd98f00b204e9fdsafdsafdasf333f
作者: 蔡锡生
''' auth = HTTPBasicAuth()
application = Flask(__name__)
application.debug = True def connect_ceph():
cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
cluster.connect()
ioctx = cluster.open_ioctx('rbd')
return ioctx @auth.get_password
def get_password(username):
if username == 'admin':
return 'd8cd98f00b204e9fdsafdsafdasf333f'
return None @auth.error_handler
def unauthorized():
return make_response(jsonify({'error': 'Unauthorized access'}), 401) @application.route('/')
def index():
return "Hello, world" @application.route('/ceph/v1.0/rbd', methods=['GET'])
@auth.login_required
def get_rbd_list():
ioctx = connect_ceph()
rbd_inst = rbd.RBD()
images = rbd_inst.list(ioctx)
return jsonify({"code": 200, "info": images}) @application.route('/ceph/v1.0/rbd/images/<image_name>/<int:size>', methods=['POST'])
@auth.login_required
def create_volume(image_name, size):
ioctx = connect_ceph()
rbd_inst = rbd.RBD()
try:
rbd_inst.create(ioctx, image_name, size)
return jsonify({"code": 200, "info": "create volume success"})
except Exception as e:
return jsonify({"code": 400, "info": "create volume failure\r\n"+e.message}) @application.route('/ceph/v1.0/rbd/images/<image_name>',methods=['DELETE'])
@auth.login_required
def delete_rbd_image(image_name):
if image_name == '' or len(image_name) == 0:
return jsonify({"code": 400, "info": "parameter can't be null"})
ioctx = connect_ceph()
print dir(rbd)
rbd_inst = rbd.RBD()
if image_name in rbd_inst.list(ioctx):
try:
time.sleep(3)
rbd_inst.remove(ioctx, image_name)
return jsonify({"code": 200, "info": "delete success"})
except Exception as e:
if e.message == 'error removing image':
delete_rbd_image(image_name)
return jsonify({"code": 400, "info": e.message})
else:
return jsonify({"code": 403, "info": "requests image_name not be exist"}) if __name__ == '__main__':
application.run(host='0.0.0.0', port=80)
6.uwsgi 配置
vim uwsgi.ini
[uwsgi]
master=true
wsgi-file=manage.py
callable=application
socket=/opt/soft/python-ceph-api/ceph-api.sock
chmod-socket=664
processes=10
threads=4
buffer-size=32768
touch-reload=/opt/soft/python-ceph-api
module=rbd_ap
7.nginx 配置
vim /etc/nging/conf.d/ceph_api.conf
upstreamscloud_django{
#serverunix:///path/to/your/mysite/mysite.sock;#forafilesocket
serverunix:///opt/soft/python-ceph-api/ceph-api.sock;#forawebportsocket(we'llusethisfirst)
}
server{
#theportyoursitewillbeservedon
listen20000;
#thedomainnameitwillservefor
#server_namewww.scloud.cn;#substituteyourmachine'sIPaddressorFQDN
charsetutf-8;
#maxuploadsize
client_max_body_size75M;#adjusttotaste
#Djangomedia
location/media{
#alias/opt/soddft/scloud/media;#yourDjangoproject'smediafiles-amendasrequired
}
location/static{
#alias/opt/soft/scloud/static;#yourDjangoproject'sstaticfiles-amendasrequired
}
#Finally,sendallnon-mediarequeststotheDjangoserver.
location/{
uwsgi_passscloud_django;
include/etc/nginx/uwsgi_params;#theuwsgi_paramsfileyouinstalled
}
}
ceph rbd 封装api的更多相关文章
- 理解 OpenStack + Ceph (3):Ceph RBD 接口和工具 [Ceph RBD API and Tools]
本系列文章会深入研究 Ceph 以及 Ceph 和 OpenStack 的集成: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 ...
- 理解 QEMU/KVM 和 Ceph(1):QEMU-KVM 和 Ceph RBD 的 缓存机制总结
本系列文章会总结 QEMU/KVM 和 Ceph 之间的整合: (1)QEMU-KVM 和 Ceph RBD 的 缓存机制总结 (2)QEMU 的 RBD 块驱动(block driver) (3)存 ...
- Ceph RBD CephFS 存储
Ceph RBD CephFS 存储 环境准备: (这里只做基础测试, ceph-manager , ceph-mon, ceph-osd 一共三台) 10.6.0.140 = ceph-manag ...
- rexray在CentOS上不能创建ceph rbd的docker volume问题定位
背景 我们通过docker的rexray插件来创建ceph rbd设备的docker volume,但总提示创建失败. # docker volume create --driver=rexray - ...
- CentOS7 下安装 iSCSI Target(tgt) ,使用 Ceph rbd
目录 一.iSCSI 介绍 1. iSCSI 定义 2. 几种常见的 iSCSI Target 3. 优缺点比较 二.安装步骤 1. 关闭防火墙 2. 关闭selinux 3. 通过 yum 安装 t ...
- kubernetes挂载ceph rbd和cephfs的方法
目录 k8s挂载Ceph RBD PV & PVC方式 创建secret 创建PV 创建PVC 创建deployment挂载PVC StorageClass方式 创建secret 创建Stor ...
- vue项目,封装api并使用
封装api index.js let uploadBase = '' if(process.env.NODE_ENV === 'production'){ uploadBase = 'https:// ...
- SUSE CaaS Platform 4 - 使用 Ceph RBD 作为持久存储(动态)
图1 架构图 图2 各存储插件对动态供给方式的支持状况 1.所有节点安装 # yum install ceph-common 复制 ceph.conf 到 worker 节点上 # scp admin ...
- SUSE CaaS Platform 4 - Ceph RBD 作为 Pod 存储卷
RBD存储卷 目前 CaaSP4 支持多种 Volume 类型,这里选择 Ceph RBD(Rados Block Device),主要有如下好处: Ceph 经过多年开发,已经非常熟,社区也很活跃: ...
随机推荐
- async await promise
async 异步函数,以后可能会用得很广. 1.箭头函数: 没有{ }时不写return 也有返回值 2.Promise : 异步神器,很多异步api都是基于Promise 3.new Promise ...
- javascript 之作用域链-10
前言 在<执行环境>文中说到,当JavaScript代码执行一段可执行代码时,会创建对应的执行上下文(execution context). 变量对象(Variable object,VO ...
- BASIC-2 01字串
基础练习 01字串 时间限制:1.0s 内存限制:256.0MB 问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能.它们的前几个是: 00000 ...
- Java框架之Hibernate(四)
本文主要介绍: 1 悲观锁和乐观锁 2 使用版本号控制并发访问 3 flush方法和批量更新的问题 4 DetachedCriteria 5 N + 1 次查询 6 使用sql进行查询 7 注解方式 ...
- 微信小程序节点查询方法:wx.createSelectorQuery()的使用场景与注意事项
小程序由于内置于微信,这使得它有了得天独厚的宣传和使用优势,本着学习的心态,我在官网上看了一遍开发文档,大致得出小程序框架的设计模式与使用注意事项(重点来了,其实开发文档某些方面叙述的并不仔细,甚至存 ...
- iOS项目开发常用功能静态库
YHDeveloperTools iOS项目开发常用功能静态库 查看源码 功能方法: 1.字符检查 [NSString checkStringWithType:Email andTargetStrin ...
- 2017 年的 人生 hard 模式终于结束了,2018年回归初心(二)
今天周末, 深圳的天气简直好的不像话.好了,我们继续之前的话题往下聊. >>>猎头 : 关于猎头这个行业,以笔者的感觉来说 一般你工作年限未超过三年的话,你是很难遇到猎头来推送你的简 ...
- beef配合ettercap批量劫持内网的浏览器
先更改首先先打开ettercap的DNS文件进行编辑,在kali linux2.0下的文件路径为/etc/ettercap/etter.dns 在对应的位置添加对应的 标识和IP地址 * 代表所有域名 ...
- 【批处理学习笔记】第十三课:常用dos命令(3)
网络命令ping 进行网络连接测试.名称解析ftp 文件传输net 网络命令集及用户管理telnet 远程登陆ipconfig显示.修改TCP/IP设置msg 给用户发送消息arp 显示.修改局域网的 ...
- [51nod1310]Chandrima and XOR
有这样一个小到大排列的无穷序列S:1, 2, 4, 5, 8......,其中任何一个数转为2进制不包括2个连续的1.给出一个长度为N的正整数数组A,A1, A2......An记录的是下标(下标从1 ...