Restful api/request to create/upload image in openStack

asked 2014-11-27 00:42:55 -0500

Awadhesh Gupta gravatar image

updated 2014-11-27 03:03:37 -0500

I am trying to create/upload image in openstack using python urllib2 library.

Request :

    sampleResquest = urllib2.Request('http://192.168.1.112:9292/v1/images')
    sampleResquest.add_header("X-Auth-Token", tokenID)
    sampleResquest.add_header("Accept-Encoding", "gzip, deflate")
    sampleResquest.add_header("x-image-meta-container_format", "ami")
    sampleResquest.add_header("Accept","*/*")
    sampleResquest.add_header("Content-Type", "application/json")
    sampleResquest.add_header("X-Image-Meta-Name", "testImage")
    sampleResquest.add_header("x-image-meta-disk_format", "ami")
    sampleResquest.add_header("x-image-meta-is_public", "True")
    sampleResquest.add_header("X-Image-Meta-Status", "active")
    sampleResquest.add_header("X-Image-Meta-Size", "13147648")
    sampleResquest.add_header("name", "fileUpload")
    sampleResquest.add_header("filename", "cirros-032")
    sampleResquest.add_header("Accept-Language", "en-US,en;q=0.8")
    jsonPayload = json.dumps({"image":{"name": "My Image" }})
    url_req = urllib2.urlopen(sampleResquest,jsonPayload)
    print json.loads(url_req.read())

Response: urllib2.HTTPError: HTTP Error 400: Bad Request

Is there something i am missing ?? Could you suggest any correction ?

edit retag flag offensive close merge delete

Comments

I think you'll want to use v2 for glance. Verify the latest version of the API. Some of the options for v2 may not be available in the v1 API.

mpetason gravatar imagempetason ( 2014-12-02 16:22:49 -0500 )edit