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的更多相关文章

  1. 理解 OpenStack + Ceph (3):Ceph RBD 接口和工具 [Ceph RBD API and Tools]

    本系列文章会深入研究 Ceph 以及 Ceph 和 OpenStack 的集成: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 ...

  2. 理解 QEMU/KVM 和 Ceph(1):QEMU-KVM 和 Ceph RBD 的 缓存机制总结

    本系列文章会总结 QEMU/KVM 和 Ceph 之间的整合: (1)QEMU-KVM 和 Ceph RBD 的 缓存机制总结 (2)QEMU 的 RBD 块驱动(block driver) (3)存 ...

  3. Ceph RBD CephFS 存储

    Ceph RBD  CephFS 存储 环境准备: (这里只做基础测试, ceph-manager , ceph-mon, ceph-osd 一共三台) 10.6.0.140 = ceph-manag ...

  4. rexray在CentOS上不能创建ceph rbd的docker volume问题定位

    背景 我们通过docker的rexray插件来创建ceph rbd设备的docker volume,但总提示创建失败. # docker volume create --driver=rexray - ...

  5. CentOS7 下安装 iSCSI Target(tgt) ,使用 Ceph rbd

    目录 一.iSCSI 介绍 1. iSCSI 定义 2. 几种常见的 iSCSI Target 3. 优缺点比较 二.安装步骤 1. 关闭防火墙 2. 关闭selinux 3. 通过 yum 安装 t ...

  6. kubernetes挂载ceph rbd和cephfs的方法

    目录 k8s挂载Ceph RBD PV & PVC方式 创建secret 创建PV 创建PVC 创建deployment挂载PVC StorageClass方式 创建secret 创建Stor ...

  7. vue项目,封装api并使用

    封装api index.js let uploadBase = '' if(process.env.NODE_ENV === 'production'){ uploadBase = 'https:// ...

  8. SUSE CaaS Platform 4 - 使用 Ceph RBD 作为持久存储(动态)

    图1 架构图 图2 各存储插件对动态供给方式的支持状况 1.所有节点安装 # yum install ceph-common 复制 ceph.conf 到 worker 节点上 # scp admin ...

  9. SUSE CaaS Platform 4 - Ceph RBD 作为 Pod 存储卷

    RBD存储卷 目前 CaaSP4 支持多种 Volume 类型,这里选择 Ceph RBD(Rados Block Device),主要有如下好处: Ceph 经过多年开发,已经非常熟,社区也很活跃: ...

随机推荐

  1. css实现椭圆、半椭圆

    一.自适应的椭圆 1. 椭圆 css .ellipse{ width: 250px; height: 150px; margin: 50px; background: #FFD900; border- ...

  2. Windows下搭建Redis服务器

    Redis服务器是当下比较流行的缓存服务器,Redis通常被人拿来和Memcached进行对比.在我看来,应当是各具优势吧,虽然应用场景基本类似,但总会根据项目的不同来进行不通的选用. 我们今天主要讲 ...

  3. python1数据链接总结

    本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 定义列表 ...

  4. python实现XSS过滤(BeautifulSoup和白名单处理)

    下面我做的莫名其妙的代码格式化是因为这个 --.-- 首先大致说一下XSS,就是在HTML里插入恶意的javascript代码,使得在该HTML加载时执行恶意代码,达到攻击的目的. 可能存在的地方呢, ...

  5. 修改MySQL 5.7.9版本的root密码方法以及一些新变化整理

    MySQL 5.7版本开始,增强密码验证机制,网上说安装的时候会在/root/.mysql_secret  文件中生成默认密码,这一点自 5.7.6版本以后也去掉了. 针对如果生成默认密码,网上有一个 ...

  6. js 前端操作的分页路由设计

    //分页条获得分页数字,然后跳转到拼接字符串的页面 function getPage(page) { var window_href = location.pathname; var newWindo ...

  7. 微信小程序之自定义toast弹窗

    微信小程序里面的自带弹窗icon只有两种,success和loading.有时候用户输入错误的时候想加入一个提醒图标,也可以使用wx.showToast中的image来添加图片达到使用自定义图标的目的 ...

  8. keepalived配置文件详解(2)

    全局配置 global_defs { notification_email { #指定keepalived在发生切换时需要发送email到的对象,一行一个邮件地址 xuequn@.com } noti ...

  9. Asp.net SignalR 让实时通讯变得简单

    巡更项目中,需要发送实时消息,以及需要任务开始提醒,于是便有机会接触到SignalR,在使用过程中,发现用SignalR实现通信非常简单,下面我思明将从三个方面分享一下: 一.SignalR是什么 A ...

  10. ogg-oracle to sqlserver

    环境: source:  54     Centos7  oracle12.2           ogg12.3 target  :    52 Windows sqlserver2012      ...