我是 openstack 新手,我正在嘗試使用 python SDK 訪問 openstack 服務(wù)。我嘗試使用create函數(shù)將圖像上傳到 openstack ,其中包含圖像的數(shù)據(jù)(要寫入的圖像)作為參數(shù),腳本執(zhí)行并且沒有任何錯(cuò)誤,但是當(dāng)我登錄并導(dǎo)航到 openstack 中的圖像選項(xiàng)卡時(shí)儀表板,圖像已創(chuàng)建,但圖像狀態(tài)始終處于queued狀態(tài) 。我嘗試從 openstack 庫添加上傳功能,這次圖像的狀態(tài)變?yōu)锳ctive但圖像的大小僅以字節(jié)為單位(圖像的原始大小為 12 MB)。我不明白數(shù)據(jù)在哪里丟失。我什至嘗試使用 keystone 身份庫登錄,但同樣的情況仍在繼續(xù)發(fā)生。任何幫助都會(huì)非常有用。提前致謝def upload_image(): # imagefile = 'CirrOS.qcow2' # loader = loading.get_plugin_loader('password') auth = v3.Password(user_domain_name='******', username='***', password='***', project_domain_name='******', project_name='***', auth_url='http://*.*.*.**:****/v3') sess = session.Session(auth=auth) glance = client.Client(session=sess) # with open(imagefile, 'rb'): image = glance.images.create(name="my_image", is_public='True', disk_format="qcow2", container_format="bare", data='CirrOS.qcow2') glance.images.upload(image.id, image_data='CirrOS.qcow2')
1 回答

不負(fù)相思意
TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊
我確實(shí)使用 openstack rest API 來上傳圖像。它的步驟是:-
第 1 步。創(chuàng)建圖像,它將創(chuàng)建一個(gè)處于排隊(duì)狀態(tài)的圖像,其中包含所有必需的信息,但沒有圖像數(shù)據(jù)。
步驟 2. 讀取圖像并將其二進(jìn)制數(shù)據(jù)上傳到創(chuàng)建的圖像上。
當(dāng)您使用 openstack python 客戶端庫時(shí),在第一步中您正在創(chuàng)建圖像,但在第 2 步中我看不到您讀取和上傳圖像數(shù)據(jù)。所以你的第二個(gè)函數(shù)調(diào)用應(yīng)該是 -
glance.images.upload(image.id, open('<image-path>', 'rb'))
由于您沒有提到圖像路徑。在您的情況下,圖像數(shù)據(jù)是文本“ CirrOS.qcow2”的大小。
有關(guān)更多信息,請參閱此鏈接:- https://docs.openstack.org/python-glanceclient/latest/reference/apiv2.html
添加回答
舉報(bào)
0/150
提交
取消