ceph rbd 패키지 api
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.html4.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//', 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
"+e.message})
@application.route('/ceph/v1.0/rbd/images/',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
}
}
다음으로 전송:https://www.cnblogs.com/waken-captain/p/8322249.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.