LIBRADOS(PYTHON)
該rados
模塊是一個(gè)很薄的Python包裝器librados
。
安裝
要為Ceph安裝Python庫(kù),請(qǐng)參閱為Python獲取librados且轨。
入門(mén)
您可以使用Python創(chuàng)建自己的Ceph客戶(hù)端。以下教程將向您展示如何導(dǎo)入Ceph Python模塊睡互,連接到Ceph集群玻淑,并以client.admin
用戶(hù)身份執(zhí)行對(duì)象操作。
注意
要使用Ceph Python綁定礁扮,您必須有權(quán)訪問(wèn)正在運(yùn)行的Ceph集群知举。要快速設(shè)置瞬沦,請(qǐng)參閱入門(mén)。
<dl class="docutils" style="margin-bottom: 15px;">
<dt>首先雇锡,為您的Ceph客戶(hù)端創(chuàng)建一個(gè)Python源文件逛钻。::</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| linenos: | sudo vim client.py |
</dd>
</dl>
導(dǎo)入模塊
要使用該rados
模塊,請(qǐng)將其導(dǎo)入到源文件中锰提。
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 導(dǎo)入 rados
</pre>
|
配置群集句柄
在連接到Ceph存儲(chǔ)群集之前曙痘,創(chuàng)建一個(gè)群集句柄。默認(rèn)情況下欲账,集群句柄假定一個(gè)名為集群ceph
(即屡江,部署工具的默認(rèn)集合以及我們的入門(mén)指南)以及一個(gè) client.admin
用戶(hù)名。您可以更改這些默認(rèn)值以滿(mǎn)足您的需求赛不。
要連接Ceph存儲(chǔ)集群惩嘉,您的應(yīng)用程序需要知道在哪里可以找到Ceph Monitor。通過(guò)指定Ceph配置文件的路徑踢故,將該信息提供給您的應(yīng)用程序文黎,該文件包含初始Ceph監(jiān)視器的位置。
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1 2 3 4 五 6</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 導(dǎo)入 rados 殿较, sys
#創(chuàng)建句柄示例耸峭。
cluster = rados 。拉多什(的ConfFile = 'ceph.conf' )
簇 = 地區(qū)反興奮劑組織淋纲。拉多什(的ConfFile = SYS 劳闹。ARGV [ 1 ])
簇 = 地區(qū)反興奮劑組織。拉多什(的ConfFile = 'ceph.conf' 洽瞬, CONF = 字典 (鑰匙圈 = '/路徑/到/鑰匙圈' ))
</pre>
|
確保conffile
參數(shù)提供Ceph配置文件的路徑和文件名本涕。您可以使用該sys
模塊來(lái)避免硬編碼Ceph配置路徑和文件名。
您的Python客戶(hù)端還需要客戶(hù)端密鑰環(huán)伙窃。對(duì)于這個(gè)例子菩颖,我們client.admin
默認(rèn)使用這個(gè) 鍵。如果您想在創(chuàng)建群集句柄時(shí)指定密鑰環(huán)为障,則可以使用conf
參數(shù)晦闰。或者鳍怨,您可以在Ceph配置文件中指定密鑰環(huán)路徑呻右。例如,你可以添加如下行到你的Ceph配置文件:
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">keyring = / path / to / ceph 鞋喇∩模客戶(hù)。管理員确徙。鑰匙圈
</pre>
有關(guān)通過(guò)Python修改配置的更多詳細(xì)信息醒串,請(qǐng)參閱配置。
連接到群集
一旦配置了集群句柄鄙皇,就可以連接到集群芜赌。通過(guò)連接到集群,您可以執(zhí)行返回有關(guān)集群信息的方法伴逸。
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 1 2 3 4 五 6 7 8 9 10 11 12 13 14 15</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 導(dǎo)入 rados 缠沈, sys
cluster = rados 。拉多什(的ConfFile = 'ceph.conf' )
打印 “ \ n librados版本:” + STR (簇错蝴。版本())
打印 “將嘗試連接到:” + STR (簇洲愤。conf_get ('周一初始成員' ))
集群。connect () 打印 “ \ n 群集ID:” + 群集顷锰。get_fsid ()
打印 “ \ n \ n 群集統(tǒng)計(jì)”
打印 “==================”
cluster_stats = 群集柬赐。get_cluster_stats ()
對(duì)于 關(guān)鍵的, 價(jià)值 在 cluster_stats 官紫。iteritems ():
打印 鍵肛宋, 值
</pre>
|
默認(rèn)情況下,Ceph認(rèn)證是on
束世。您的應(yīng)用程序需要知道鑰匙圈的位置。該python-ceph
模塊沒(méi)有默認(rèn)位置,因此您需要指定密鑰環(huán)路徑仲智。指定密鑰環(huán)的最簡(jiǎn)單方法是將其添加到Ceph配置文件中屡萤。以下Ceph配置文件示例使用client.admin
您生成的密鑰環(huán) ceph-deploy
。
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1 2 3</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> [global]
#...省略配置
密鑰環(huán)= /path/to/keyring/ceph.client.admin.keyring
</pre>
|
管理池
當(dāng)連接到群集時(shí)贫堰,該Rados
API允許您管理池穆壕。您可以列出池,檢查是否存在池严嗜,創(chuàng)建池并刪除池粱檀。
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 1 2 3 4 五 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 打印 “ \ n \ n 池操作”
打印 “===============”
打印 “ \ n 可用池”
print “----------------”
pools = cluster 。list_pools ()用于池中的池:打印池
打印 “ \ n 創(chuàng)建”測(cè)試“池”
打印 “------------------”
群集漫玄。create_pool ('測(cè)試' )打印“ \ n 普爾名為'測(cè)試'存在:” + STR (簇茄蚯。pool_exists ('測(cè)試' ))打印“ \ n 驗(yàn)證'測(cè)試'池中存在” 打印“------- ------------------“ pools = cluster 。list_pools ()用于池中的池:
打印 “ \ n 刪除'測(cè)試'池'
打印 ”------------------“
群集睦优。delete_pool ('測(cè)試' )打印“ \ n 普爾名為'測(cè)試'存在:” + STR (簇渗常。pool_exists ('測(cè)試' ))
</pre>
|
輸入/輸出上下文
讀取和寫(xiě)入Ceph存儲(chǔ)集群需要輸入/輸出上下文(ioctx)。您可以用創(chuàng)建ioctx open_ioctx()
或 open_ioctx2()
該方法Rados
的類(lèi)汗盘。該ioctx_name
參數(shù)是池的名稱(chēng)皱碘,pool_id
是您希望使用的池的ID。
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> ioctx = 集群隐孽。open_ioctx ('data' )
</pre>
|
要么
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> ioctx = 集群癌椿。open_ioctx2 (pool_id )
</pre>
|
一旦擁有I / O上下文健蕊,就可以讀取/寫(xiě)入對(duì)象,擴(kuò)展屬性并執(zhí)行其他一些操作踢俄。完成操作后缩功,請(qǐng)確保關(guān)閉連接。例如:
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1 2</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 打印 “ \ n 關(guān)閉連接都办〉招浚”
ioctx 。close ()
</pre>
|
寫(xiě)入琳钉,讀取和刪除對(duì)象
一旦創(chuàng)建了I / O上下文势木,就可以將對(duì)象寫(xiě)入群集。如果你寫(xiě)一個(gè)不存在的對(duì)象歌懒,Ceph創(chuàng)建它啦桌。如果你寫(xiě)一個(gè)存在的對(duì)象,Ceph會(huì)覆蓋它(除非你指定一個(gè)范圍及皂,然后它只覆蓋范圍)震蒋。您可以從群集讀取對(duì)象(和對(duì)象范圍)。您也可以從群集中刪除對(duì)象躲庄。例如:
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1 2 3 4 五 6 7 8</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">打印 “ \ n 將內(nèi)容'Hello World'寫(xiě)入對(duì)象'hw'查剖!匯集“數(shù)據(jù)”≡刖剑“
ioctx 笋庄。write_full (“hw” , “Hello World倔监!” )
print “ \ n \ n 對(duì)象'hw'的內(nèi)容\ n ------------------------ \ n “
打印 ioctx 直砂。讀取(“hw” )
打印 “ \ n 刪除對(duì)象'hw'”
ioctx 浩习。remove_object (“hw” ) </pre>
|
寫(xiě)作和閱讀XATTRS
一旦創(chuàng)建了對(duì)象静暂,就可以將擴(kuò)展屬性(XATTR)寫(xiě)入對(duì)象并從對(duì)象中讀取XATTR。例如:
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">1 2 3 4 五</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">打印 “ \ n \ n 寫(xiě)入值為'en_US'的
XATTR'lang
'以反對(duì)' hw''ioctx 谱秽。set_xattr (“hw” 洽蛀,“l(fā)ang” ,“en_US” ) print “ \ n \ n 從對(duì)象'hw'獲取XATTR'lang' \ n ”
print ioctx 疟赊。get_xattr (“hw” 郊供, “l(fā)ang” ) </pre>
|
清單對(duì)象
如果要檢查池中對(duì)象的列表,可以檢索對(duì)象列表并使用對(duì)象迭代器對(duì)它們進(jìn)行迭代近哟。例如:
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 5px 0px; background-color: transparent; color: rgb(170, 170, 170); line-height: 1.2em; border: 0px; font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;"> 1 2 3 4 五 6 7 8 9 10</pre>
|
<pre style="overflow-x: auto; overflow-y: hidden; padding: 10px; background-color: white; color: rgb(34, 34, 34); line-height: 1.2em; border: 1px solid rgb(94, 106, 113); font-size: 1.1em; margin: 1.5em; box-shadow: rgb(230, 232, 232) 1px 1px 1px;">object_iterator = ioctx 驮审。list_objects ()
while True :
嘗試 :
rados_object = object_iterator 。next ()打印“Object contents =” + rados_object 。read ()除了StopIteration :break
</pre>
|
本Object
類(lèi)提供了一個(gè)類(lèi)似文件的接口的對(duì)象疯淫,使您可以讀取和寫(xiě)入的內(nèi)容和擴(kuò)展屬性地来。使用I / O上下文的對(duì)象操作提供了額外的功能和異步功能。
集群處理
本Rados
類(lèi)提供一個(gè)接口到Ceph的存儲(chǔ)守護(hù)進(jìn)程熙掺。
配置
本Rados
類(lèi)提供用于獲取和設(shè)置配置值靠抑,讀取Ceph的配置文件,并解析參數(shù)的方法适掰。您無(wú)需連接Ceph存儲(chǔ)群集即可調(diào)用以下方法。有關(guān)設(shè)置的詳情荠列,請(qǐng)參閱存儲(chǔ)群集配置类浪。
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.conf_get">Rados.``conf_get
(可選)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.conf_set">Rados.``conf_set
(option,*val *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.conf_read_file">Rados.``conf_read_file
(*path = None *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.conf_parse_argv">Rados.``conf_parse_argv
(*args *)</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Rados.conf_parse_argv(self肌似,args)
從參數(shù)中解析已知的參數(shù)并移除; 返回的參數(shù)只包含那些未知的ceph
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.version">Rados.``version
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Rados.version(個(gè)體經(jīng)營(yíng))
獲取librados
C庫(kù)的版本號(hào)费就。
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 返回: | librados版本組件的元組(major, minor, extra)
|
</dd>
</dl>
連接管理
一旦配置了集群句柄,就可以連接到集群川队,檢查集群fsid
力细,檢索集群統(tǒng)計(jì)信息,并從集群斷開(kāi)連接(關(guān)閉)固额。您也可以斷言群集句柄處于特定狀態(tài)(例如眠蚂,“配置”,“連接”等)斗躏。
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.connect">Rados.``connect
(*timeout = 0 *)</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Rados.connect(self逝慧,timeout = 0)
連接到群集。使用shutdown()釋放資源啄糙。
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.shutdown">Rados.``shutdown
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Rados.shutdown(個(gè)體經(jīng)營(yíng))
斷開(kāi)與群集的連接笛臣。當(dāng)不再使用Rados.connect()ed對(duì)象時(shí),明確地調(diào)用它隧饼。
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.get_fsid">Rados.``get_fsid
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Rados.get_fsid(個(gè)體經(jīng)營(yíng))
以十六進(jìn)制字符串形式獲取群集的fsid沈堡。
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 舉: | Error
|
| 返回: | str - cluster fsid |
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.get_cluster_stats">Rados.``get_cluster_stats
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Rados.get_cluster_stats(個(gè)體經(jīng)營(yíng))
閱讀有關(guān)群集的使用情況信息
這會(huì)告訴您總空間,使用空間燕雁,可用空間和對(duì)象數(shù)量诞丽。這些數(shù)據(jù)寫(xiě)入時(shí)不會(huì)立即更新,它們最終一致拐格。
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 返回: | 字典 - 包含以下鍵:
-
kb
(int) - 總空間 -
kb_used
(int) - 使用的空間 -
kb_avail
(int) - 可用空間 -
num_objects
(int) - 對(duì)象的數(shù)量
|
</dd>
</dl>
<dl class="class" style="margin-bottom: 15px;">
<dt id="rados.Rados">類(lèi)rados.``Rados
</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.require_state">require_state
(** args *)</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
檢查Rados對(duì)象是否處于特殊狀態(tài)
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 參數(shù): | 參數(shù) - 可以檢查為單獨(dú)參數(shù)的任意數(shù)量的狀態(tài) |
| 舉: | RadosStateError
|
</dd>
</dl>
</dd>
</dl>
池操作
要使用池操作方法率拒,您必須首先連接到Ceph存儲(chǔ)群集。您可以列出可用的池禁荒,創(chuàng)建池猬膨,檢查池是否存在以及刪除池。
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.list_pools">Rados.``list_pools
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Rados.list_pools(個(gè)體經(jīng)營(yíng))
獲取池名稱(chēng)的列表。
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 返回: | 列表 - 池名稱(chēng)勃痴。 |
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.create_pool">Rados.``create_pool
(pool_name谒所,auid = None,*crush_rule = None *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.pool_exists">Rados.``pool_exists
()</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.delete_pool">Rados.``delete_pool
(*pool_name *)</dt>
</dl>
輸入/輸出上下文
要將數(shù)據(jù)寫(xiě)入Ceph對(duì)象存儲(chǔ)并從中讀取數(shù)據(jù)沛申,您必須創(chuàng)建一個(gè)輸入/輸出上下文(ioctx)劣领。所述<cite>拉多什</cite>類(lèi)提供<cite>open_ioctx()</cite> 和<cite>open_ioctx2()</cite>方法。其余的ioctx
操作涉及調(diào)用<cite>Ioctx</cite>和其他類(lèi)的方法铁材。
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Rados.open_ioctx">Rados.``open_ioctx
(*ioctx_name *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.require_ioctx_open">Ioctx.``require_ioctx_open
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Ioctx.require_ioctx_open(個(gè)體經(jīng)營(yíng))
檢查rados.Ioctx對(duì)象狀態(tài)是否為'open'
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 舉: | IoctxStateError |
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.get_stats">Ioctx.``get_stats
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Ioctx.get_stats(個(gè)體經(jīng)營(yíng))
獲取池使用統(tǒng)計(jì)信息
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 返回: | 字典 - 包含以下鍵:
num_bytes
(int) - 池的大屑馓浴(以字節(jié)為單位)num_kb
(int) - 以千字節(jié)為單位的池大小num_objects
(int) - 池中的對(duì)象數(shù)num_object_clones
(int) - 對(duì)象克隆的數(shù)量num_object_copies
(int) - 對(duì)象副本的數(shù)量-
<dl class="first docutils" style="margin-bottom: 15px; margin-top: 0px !important;">
<dt>
num_objects_missing_on_primary
(int) - objets的數(shù)量</dt><dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">主要缺失</dd>
</dl>
num_objects_unfound
(int) - 未發(fā)現(xiàn)對(duì)象的數(shù)量num_objects_degraded
(int) - 降級(jí)對(duì)象的數(shù)量num_rd
(int) - 讀取字節(jié)num_rd_kb
(int) - 千字節(jié)讀取num_wr
(int) - 寫(xiě)入的字節(jié)num_wr_kb
(int) - 千字節(jié)寫(xiě)入
|
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.change_auid">Ioctx.``change_auid
(*auid *)</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Ioctx.change_auid(self,auid)
嘗試更改io上下文關(guān)聯(lián)的智能“所有者”著觉。
要求您對(duì)當(dāng)前和新的交易都有寫(xiě)入權(quán)限村生。
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 舉: | Error
|
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.get_last_version">Ioctx.``get_last_version
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Ioctx.get_last_version(個(gè)體經(jīng)營(yíng))
返回讀取或?qū)懭氲淖詈笠粋€(gè)對(duì)象的版本。
這暴露了通過(guò)這個(gè)IO上下文讀取或?qū)懭氲淖詈笠粋€(gè)對(duì)象的內(nèi)部版本號(hào)
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 返回: | 使用的最后一個(gè)對(duì)象的版本 |
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.close">Ioctx.``close
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Ioctx.close(個(gè)體經(jīng)營(yíng))
關(guān)閉一個(gè)rados.Ioctx對(duì)象饼丘。
這只是告訴librados你不再需要使用io上下文趁桃。如果有未處理的異步請(qǐng)求,它可能不會(huì)立即釋放肄鸽,但在調(diào)用此函數(shù)后不應(yīng)再使用io上下文卫病。
</dd>
</dl>
對(duì)象操作
Ceph存儲(chǔ)集群將數(shù)據(jù)存儲(chǔ)為對(duì)象。您可以同步或異步讀寫(xiě)對(duì)象典徘。您可以讀取和寫(xiě)入偏移量蟀苛。一個(gè)對(duì)象有一個(gè)名字(或關(guān)鍵字)和數(shù)據(jù)。
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.aio_write">Ioctx.``aio_write
(object_name逮诲,to_write屹逛,offset = 0,oncomplete = None汛骂,*onsafe = None *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.aio_write_full">Ioctx.``aio_write_full
(object_name罕模,to_write,oncomplete = None帘瞭,*onsafe = None *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.aio_append">Ioctx.``aio_append
(object_name淑掌,to_append,oncomplete = None蝶念,*onsafe = None *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.write">Ioctx.``write
(鍵抛腕,數(shù)據(jù),*偏移量= 0 *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.write_full">Ioctx.``write_full
(鍵媒殉,數(shù)據(jù))</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.aio_flush">Ioctx.``aio_flush
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Ioctx.aio_flush(個(gè)體經(jīng)營(yíng))
阻塞担敌,直到io上下文中的所有掛起寫(xiě)入都是安全的
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 舉: | Error
|
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.set_locator_key">Ioctx.``set_locator_key
(*loc_key *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.aio_read">Ioctx.``aio_read
(object_name,length廷蓉,offset全封,*oncomplete *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.read">Ioctx.``read
(key,length = 8192,*offset = 0 *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.stat">Ioctx.``stat
(重點(diǎn))</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.trunc">Ioctx.``trunc
(key刹悴,*size *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.remove_object">Ioctx.``remove_object
(重點(diǎn))</dt>
</dl>
對(duì)象擴(kuò)展屬性
您可以在對(duì)象上設(shè)置擴(kuò)展屬性(XATTR)行楞。您可以檢索對(duì)象或XATTR的列表并遍歷它們。
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.set_xattr">Ioctx.``set_xattr
(key土匀,xattr_name子房,*xattr_value *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.get_xattrs">Ioctx.``get_xattrs
(*oid *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.XattrIterator.next">XattrIterator.``__next__
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
獲取對(duì)象上的下一個(gè)xattr
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 舉: | 的StopIteration |
| 返回: | 配對(duì) - 下一個(gè)Xattr的名稱(chēng)和值 |
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.get_xattr">Ioctx.``get_xattr
(key,*xattr_name *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.rm_xattr">Ioctx.``rm_xattr
(key就轧,*xattr_name *)</dt>
</dl>
對(duì)象接口
從I / O上下文中证杭,您可以從池中檢索對(duì)象列表并遍歷它們。提供的對(duì)象接口使每個(gè)對(duì)象看起來(lái)像一個(gè)文件妒御,并且您可以對(duì)這些對(duì)象執(zhí)行同步操作解愤。對(duì)于異步操作,您應(yīng)該使用I / O上下文方法携丁。
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Ioctx.list_objects">Ioctx.``list_objects
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
Ioctx.list_objects(個(gè)體經(jīng)營(yíng))
在rados.Ictctx對(duì)象上獲取ObjectIterator。
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 返回: | ObjectIterator |
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.ObjectIterator.next">ObjectIterator.``__next__
()</dt>
<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; line-height: 1.5em;">
獲取池中的下一個(gè)對(duì)象名稱(chēng)和位置
<colgroup><col class="field-name" style="hyphens: manual;"><col class="field-body"></colgroup>
| 舉: | 的StopIteration |
| 返回: | 下一個(gè)rados.Ictctx對(duì)象 |
</dd>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.read">Object.``read
(*長(zhǎng)度= 1024 * 1024 *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.write">Object.``write
(*string_to_write *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.get_xattrs">Object.``get_xattrs
()</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.get_xattr">Object.``get_xattr
(*xattr_name *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.set_xattr">Object.``set_xattr
(xattr_name兰怠,*xattr_value *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.rm_xattr">Object.``rm_xattr
(*xattr_name *)</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.stat">Object.``stat
()</dt>
</dl>
<dl class="method" style="margin-bottom: 15px;">
<dt id="rados.Object.remove">Object.``remove
()</dt>
</dl>