LIBRADOS

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í)贫堰,該RadosAPI允許您管理池穆壕。您可以列出池,檢查是否存在池严嗜,創(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_setoption,*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))

獲取libradosC庫(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_poolpool_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_writeobject_name逮诲,to_write屹逛,offset = 0oncomplete = None汛骂,*onsafe = None *)</dt>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt id="rados.Ioctx.aio_write_full">Ioctx.``aio_write_fullobject_name罕模,to_writeoncomplete = None帘瞭,*onsafe = None *)</dt>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt id="rados.Ioctx.aio_append">Ioctx.``aio_appendobject_name淑掌,to_appendoncomplete = 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_readobject_namelength廷蓉,offset全封,*oncomplete *)</dt>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt id="rados.Ioctx.read">Ioctx.``readkeylength = 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.``trunckey刹悴,*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_xattrkey土匀,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_xattrkey,*xattr_name *)</dt>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt id="rados.Ioctx.rm_xattr">Ioctx.``rm_xattrkey就轧,*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_xattrxattr_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>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末梦鉴,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子揭保,更是在濱河造成了極大的恐慌肥橙,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,539評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件秸侣,死亡現(xiàn)場(chǎng)離奇詭異存筏,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)味榛,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評(píng)論 3 396
  • 文/潘曉璐 我一進(jìn)店門(mén)椭坚,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人搏色,你說(shuō)我怎么就攤上這事善茎。” “怎么了频轿?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,871評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵垂涯,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我航邢,道長(zhǎng)耕赘,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,963評(píng)論 1 295
  • 正文 為了忘掉前任膳殷,我火速辦了婚禮操骡,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己当娱,他們只是感情好吃既,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,984評(píng)論 6 393
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著跨细,像睡著了一般鹦倚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上冀惭,一...
    開(kāi)封第一講書(shū)人閱讀 51,763評(píng)論 1 307
  • 那天震叙,我揣著相機(jī)與錄音,去河邊找鬼散休。 笑死媒楼,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的戚丸。 我是一名探鬼主播划址,決...
    沈念sama閱讀 40,468評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼限府!你這毒婦竟也來(lái)了夺颤?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,357評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤胁勺,失蹤者是張志新(化名)和其女友劉穎世澜,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體署穗,經(jīng)...
    沈念sama閱讀 45,850評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡寥裂,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,002評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了案疲。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片封恰。...
    茶點(diǎn)故事閱讀 40,144評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖褐啡,靈堂內(nèi)的尸體忽然破棺而出俭驮,到底是詐尸還是另有隱情,我是刑警寧澤春贸,帶...
    沈念sama閱讀 35,823評(píng)論 5 346
  • 正文 年R本政府宣布混萝,位于F島的核電站,受9級(jí)特大地震影響萍恕,放射性物質(zhì)發(fā)生泄漏逸嘀。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,483評(píng)論 3 331
  • 文/蒙蒙 一允粤、第九天 我趴在偏房一處隱蔽的房頂上張望崭倘。 院中可真熱鬧翼岁,春花似錦、人聲如沸司光。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,026評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)残家。三九已至榆俺,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間坞淮,已是汗流浹背茴晋。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,150評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留回窘,地道東北人诺擅。 一個(gè)月前我還...
    沈念sama閱讀 48,415評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像啡直,于是被迫代替她去往敵國(guó)和親烁涌。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,092評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容