分布式存储——ceph 的 python 基础接口
python 使用 boto 库完成分布式存储读、写、判断接口
import boto
import boto.s3.connection
from boto.s3.key import Key
import os class ImageFeatIO:
__read_singleton = None
__write_singleton = None
__read_count =
__write_count = def __init__(self):
pass @staticmethod
def get_write_instance():
if ImageFeatIO.__write_singleton is None:
ImageFeatIO.__write_count +=
print("create write instance:{0}",ImageFeatIO.__write_count)
paras = get_config('config')
access_key = paras['access_key']
secret_key =paras['secret_key']
write_host=paras['file_write_host']
conn = boto.connect_s3(
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
host=write_host, is_secure=False,
calling_format=boto.s3.connection.OrdinaryCallingFormat()
)
bucket_name = paras['bucket_name']
bucket = conn.get_bucket(bucket_name)
ImageFeatIO.__write_singleton=bucket
return ImageFeatIO.__write_singleton @staticmethod
def get_read_instance():
if ImageFeatIO.__read_singleton is None:
ImageFeatIO.__read_count +=
print("create read instance:{0}", ImageFeatIO.__read_count)
paras = get_config('config')
access_key = paras['access_key']
secret_key = paras['secret_key']
read_host = paras['file_read_host']
conn = boto.connect_s3(
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
host=read_host, is_secure=False,
calling_format=boto.s3.connection.OrdinaryCallingFormat()
)
bucket_name = paras['bucket_name']
bucket = conn.get_bucket(bucket_name)
ImageFeatIO.__write_singleton = bucket
return ImageFeatIO.__read__singleton def write_image_feature_to_file(id, imageFeaturestring):
bucket = ImageFeatIO.get_write_instance()
k = Key(bucket)
k.key = id
res = k.set_contents_from_string(imageFeaturestring)
return res def read_image_feature_from_file(id):
bucket = ImageFeatIO.get_write_instance()
k = Key(bucket)
k.key=id
feature = k.get_contents_as_string()
return feature def if_image_feature_exist(id):
bucket = ImageFeatIO.get_write_instance()
key = bucket.get_key(id) return key is not None def get_config(config_file='config'):
paras = dict()
if os.path.exists(config_file):
f = open(config_file)
line = f.readline()
while line:
# print('line is ', line)
s = line.replace(' ', '').replace('\n','').split('=')
print(s, len(s))
paras[s[]] = s[]
line = f.readline()
# print(' paras: ', paras)
f.close()
else:
raise ValueError(config_file + ': file not exsit!')
return paras # if __name__ == "__main__":
# instance1 = ImageFeatIO.get_write_instance()
# instance2 = ImageFeatIO.get_write_instance()
# instance3 = ImageFeatIO.get_write_instance()
#
#
# print id(instance1)
# print id(instance2)
其中 config 文件为参数配置文件, 不同参数以回车键分割
分布式存储——ceph 的 python 基础接口的更多相关文章
- Python基础-接口与归一化设计、抽象类、继承顺序、子类调用父类,多态与多态性
一.接口与归一化设计 Java接口是一系列方法的声明,是一些方法特征的集合,一个接口只有方法的特征没有方法的实现,因此这些方法可以在不同的地方被不同的类实现,而这些实现可以具有不同的行为(功能). 由 ...
- python基础--接口与归一化设计、封装、异常、网络编程
1 接口与归一化设计 1.1 归一化概念: 归一化的好处: 1.归一化让使用者无需关心对象的类是什么,只需要知道这些对象都具备某些功能就可以了,这极大降低了使用者的使用难度. 2.归一化使得高层的外部 ...
- python基础一之课后作业:编写登录接口
1 # Author : Mamba 2 3 #python基础一之课后作业:编写登录接口 4 5 # 输入用户名密码 6 # 认证成功后显示欢迎信息 7 # 用户名3次输入错误后,退出程序 8 # ...
- python基础之继承派生、组合、接口和抽象类
类的继承与派生 经典类和新式类 在python3中,所有类默认继承object,但凡是继承了object类的子类,以及该子类的子类,都称为新式类(在python3中所有的类都是新式类) 没有继承obj ...
- Py修行路 python基础 (十五)面向对象编程 继承 组合 接口和抽象类
一.前提回忆: 1.类是用来描述某一类的事物,类的对象就是这一类事物中的一个个体.是事物就要有属性,属性分为 1:数据属性:就是变量 2:函数属性:就是函数,在面向对象里通常称为方法 注意:类和对象均 ...
- python基础练习-猜年龄、编写登陆接口小程序
python基础练习: 一.猜年龄 , 可以让用户最多猜三次! age=40 count = 1 while count <=3 : user_guess=int(input("i ...
- 全能成熟稳定开源分布式存储Ceph破冰之旅-上
@ 目录 概述 定义 传统存储方式及问题 优势 生产遇到问题 架构 总体架构 组成部分 CRUSH算法 数据读写过程 CLUSTER MAP 部署 部署建议 部署版本 部署方式 Cephadm部署 前 ...
- python之最强王者(2)——python基础语法
背景介绍:由于本人一直做java开发,也是从txt开始写hello,world,使用javac命令编译,一直到使用myeclipse,其中的道理和辛酸都懂(请容许我擦干眼角的泪水),所以对于pytho ...
- Python之路3【第一篇】Python基础
本节内容 Python简介 Python安装 第一个Python程序 编程语言的分类 Python简介 1.Python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum) ...
随机推荐
- Java 代码界 3% 的王者?看我是如何解错这 5 道题的
前些日子,阿里妹(妹子出题也这么难)发表了一篇文章<悬赏征集!5 道题征集代码界前 3% 的超级王者>——看到这个标题,我内心非常非常激动,因为终于可以证明自己技术很牛逼了. 但遗憾的是, ...
- PostgreSQL 窗口函数 ( Window Functions ) 如何使用?
一.为什么要有窗口函数 我们直接用例子来说明,这里有一张学生考试成绩表testScore: 现在有个需求,需要查询的时候多出一列subject_avg_score,为此科目所有人的平均成绩,好跟每个人 ...
- 详细记录登录过程的用户、IP地址、shell命令以及详细操作时间
将下面的代码添加到/etc/profile #history USER_IP=`>/dev/null|awk '{print $NF}'|sed -e 's/[()]//g'` HISTDIR= ...
- .NET Core CSharp初级篇 1-1
.NET Core CSharp初级篇 1-1 本节内容是对于C#基础类型的存储方式以及C#基础类型的理论介绍 基础数据类型介绍 例如以下这句话:"张三是一名程序员,今年15岁重50.3kg ...
- 【NOIP2018】标题统计-C++
描述 凯凯刚写了一篇美妙的作文,请问这篇作文的标题中有多少个字符? 注意:标题中可能包含大.小写英文字母.数字字符.空格和换行符.统计标题字符数时,空格和换行符不计算在内. 输入 输入文件名为 tit ...
- 从无到有构建vue实战项目(六)
十.徒手撸一个vue下拉左侧二级导航 先附上最终效果图: vue代码: <div class="dropdown-menu-explore" v-on:mouseover=& ...
- 洛谷P2472 [SCOI2007]蜥蜴 题解
题目链接: https://www.luogu.org/problemnew/show/P2472 分析: 这道题用最大流解决. 首先构建模型. 一根柱子可以跳入和跳出,于是拆成两个点:入点和出点. ...
- 反⑨baka拖更大队:临时约法
本团队中将不时发起团队讨论报道⑨baka无良~ 某无良⑨baka一直拖更引起广大人民群众不满 文文新闻:https://www.luogu.org/discuss/show/52654 反⑨baka的 ...
- [蓝桥杯] Fibonacci数列 入门
原题链接 import java.util.Scanner;//导入Scanner类 public class Main { public static void main(String[] args ...
- JavaScript ES6 Promiss对象
说明 Node.js中,以异步(Async)回调著称,使用了异步,提高了程序的执行效率,但是,代码可读性较差的. 假如有几个异步操作,后一个操作需要前一个操作的执行完毕之后返回的数据才能执行下去,如果 ...