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 经过多年开发,已经非常熟,社区也很活跃: ...
随机推荐
- Head First设计模式之访问者模式
一.定义 定义:表示一个作用于某对象结构中的各元素的操作.它使你可以在不改变各元素类的前提下定义作用于这些元素的新操作. 访问者模式适用于数据结构相对稳定的系统, 它把数据结构和作用于数据结构之上的操 ...
- Java工程读取resources中资源文件路径问题
正常在Java工程中读取某路径下的文件时,可以采用绝对路径和相对路径,绝对路径没什么好说的,相对路径,即相对于当前类的路径.在本地工程和服务器中读取文件的方式有所不同,以下图配置文件为例. 本地读取资 ...
- 【转】 Git——如何将本地项目提交至远程仓库
1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...
- 第二章:Python基础の快速认识基本数据类型和操作实战
本课主题 字符串和操作实战 二进制操作实战 List 列表和操作实战 Tuple 元組和操作实战 Dict 字典和操作实战 作業需求 引言 这遍文章简单介绍了 Python 字符串和集合的方法和应用, ...
- windows 配置接收报文是否中断
作用:网络编程的时候,编程接收报文,可以不用循环等待并判断是否报文接收完整.配置了windows禁用网络中端后,自己写的程序一次接收,便是整条报文. 步骤: 1."打开网络和共享中心&quo ...
- iOS开发的另类神器:libimobiledevice开源包【类似android adb 方便获取iOS设备信息】
简介 libimobiledevice又称libiphone,是一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备.由于苹果官方并不支持Linux系统,但是Linux上 ...
- 安装adb之后出现 找不到设备的情况
adb 地址 https://pan.baidu.com/s/1sln2IZF 安装adb之后出现 找不到设备的情况 1.配置adb的环境变量 2.修改android_winusb.inf ...
- 搬个小板凳,我们扯扯Docker的前生
一.新瓶装旧酒 首先我们需要知道,Docker是一个"箩筐": 1.存储:Device Mapper.BtrFS.AUFS 2.名字空间:UTS.IPC.Mount.PID.Net ...
- 如何获取离线安装Chrome扩展程序的包
最近工作环境限制,有些机器文件只能拿进去,不能拿出来.网络也是内部网络,没法下载东西.工作中常用的一些Chrome扩展应用也没法使用,对于我这类工具爱好者,打击够大.后来想想,既然扩展应用能开发打包上 ...
- python requirements使用方法
记得导入导出包的时候要想激活虚拟环境. 1.导出requirements方法 pip freeze > requirements.txt 2.安装requirements方法 pip insta ...