简体   繁体   中英

Openstack Image upload

I'm new to openstack and i'm trying to access openstack services using python SDK . 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 . 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). 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 . 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. 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 2. Read Image and Upload it's binary data on the created image.

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. 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".

For more information, refer this link :- https://docs.openstack.org/python-glanceclient/latest/reference/apiv2.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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