refer to: glance client Python API v2
http://docs.openstack.org/developer/python-glanceclient/ref/v2/images.html

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.
Parameters:

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

Returns:

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, {})
#--end
-------------------------------------------------------------------------------------------------------------------

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,
Kristen



--
本信件可能包含工研院機密資訊,非指定之收件者,請勿使用或揭露本信件內容,並請銷毀此信件。 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.
__________________________________________________________________________
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Reply via email to