简体   繁体   English

Openstack 图片上传

[英]Openstack Image upload

I'm new to openstack and i'm trying to access openstack services using python SDK .我是 openstack 的新手,我正在尝试使用 python SDK 访问 openstack 服务。 I tried to upload an image to openstack using create function with data (image to be written) of the image included as parameter , the script executed and there wasn't any error , but when I logged in and navigated to images tab in the openstack dashboard, image has been created but status of image was always in queued .我尝试使用create函数将图像上传到 openstack,其中包含图像的数据(要写入的图像)作为参数,脚本执行并且没有任何错误,但是当我登录并导航到 openstack 中的图像选项卡时仪表板,图像已创建,但图像状态始终处于排队状态 I tried adding the upload function from openstack library , this time the image's status changed to Active but size of the image was only in bytes (The original size of the image was 12 MB).我尝试从 openstack library 添加上传功能,这次图像的状态更改为Active但图像的大小仅以字节为单位(图像的原始大小为 12 MB)。 I'm not understanding where the data is getting missed .我不明白数据在哪里丢失。 I even tried logging in using keystone identity library , still the same scenario continues to happen .我什至尝试使用 keystone 身份库登录,但同样的情况仍在继续发生。 Any help would be greatly useful.任何帮助都会非常有用。 Thanks in advance提前致谢

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')

I did use openstack rest API's for uploading images.我确实使用了 openstack rest API 来上传图像。 It's steps are :-它的步骤是:-
Step 1. Create Image, it will create a image in queued state with all the required information but will not have image data. Step 1. Create Image,它将创建一个包含所有必需信息但没有图像数据的队列状态的图像。
Step 2. Read Image and Upload it's binary data on the created image.步骤 2. 读取图像并将其二进制数据上传到创建的图像上。

As you are using openstack python client library, in first step you are creating image but in step 2 i can't see you reading and uploading image data.当您使用 openstack python 客户端库时,第一步是创建图像,但在第 2 步中我看不到您正在读取和上传图像数据。 So your second function call should be -所以你的第二个函数调用应该是 -

glance.images.upload(image.id, open('<image-path>', 'rb'))

Since you are not mentioning image path.由于您没有提到图像路径。 In your case, image data is size of text "CirrOS.qcow2".在您的情况下,图像数据是文本“CirrOS.qcow2”的大小。

For more information, refer this link :- https://docs.openstack.org/python-glanceclient/latest/reference/apiv2.html有关更多信息,请参阅此链接:- https://docs.openstack.org/python-glanceclient/latest/reference/apiv2.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM