[openstack-dev] How to create a image using http img file

kristen at itri.org.tw kristen at itri.org.tw
Wed Aug 3 01:27:25 UTC 2016

refer to: glance client Python API v2

add_location(image_id, url, metadata)
Add a new location entry to an image’s list of locations.
It is an error to add a URL that is already present in the list of locations.

·         image_id – ID of image to which the location is to be added.
·         url – URL of the location to add.
·         metadata – Metadata associated with the location.


The updated image

#--source code--
from glanceclient.v2.client import Client
url = 'http://xxxx/ubuntu1604.qcow2'
image = self.glance.images.create(name="myNewImage")
self.glance.images.add_location(image.id, url, {})

I am sure the images.create is work.
I got image .id  ‘be416e4a-f266-4ad5-a62f-979242d23633’.
I don’t Know which data should be assign to metadata.
Then I got :

    self.glance.images.add_location(image.id, url, {})
  File "/usr/lib/python2.7/dist-packages/glanceclient/v2/images.py", line 311, in add_location
    self._send_image_update_request(image_id, add_patch)
  File "/usr/lib/python2.7/dist-packages/glanceclient/v2/images.py", line 296, in _send_image_update_request
    self.http_client.patch(url, headers=hdrs, data=json.dumps(patch_body))
  File "/usr/lib/python2.7/dist-packages/glanceclient/common/http.py", line 284, in patch
    return self._request('PATCH', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/glanceclient/common/http.py", line 267, in _request
    resp, body_iter = self._handle_response(resp)
  File "/usr/lib/python2.7/dist-packages/glanceclient/common/http.py", line 83, in _handle_response
    raise exc.from_response(resp, resp.content)
HTTPBadRequest: 400 Bad Request: Properties disk_format, container_format must be set prior to saving data. (HTTP 400)

Best Regards,

本信件可能包含工研院機密資訊,非指定之收件者,請勿使用或揭露本信件內容,並請銷毀此信件。 This email may contain confidential information. Please do not use or disclose it in any way and delete it if you are not the intended recipient.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20160803/97489925/attachment.html>

More information about the OpenStack-dev mailing list