利用OpenStack Rest API 建立映象

振宇要低調發表於2015-05-25

服務端點:

    image

API:

    POST     /v2/images

Request1:

    Method:Post

    Url: http://192.168.31.147:9292/v2/images

    Headers:

Content-Type: application/json
X-Auth-Token: 4e045ef71a994f8d8caeeab683a11419

    Body:

{
    "name": "registry:5000/centos:v1.0",
    "container_format": "docker",
    "disk_format": "raw"
}

Reponse1:

    Headers:

Status Code: 201 

    Body:

{
    "status": "queued",
    "name": "registry:5000/centos:v1.0",
    "tags": [],
    "container_format": "docker",
    "created_at": "2015-05-22T06:38:10Z",
    "disk_format": "raw",
    "updated_at": "2015-05-22T06:38:10Z",
    "visibility": "private",
    "self": "/v2/images/0482eff2-8406-46a7-8bbb-d43e1ca9c14f",
    "min_disk": 0,
    "protected": false,
    "id": "0482eff2-8406-46a7-8bbb-d43e1ca9c14f",
    "file": "/v2/images/0482eff2-8406-46a7-8bbb-d43e1ca9c14f/file",
    "owner": "67f095375f414c3b8fde844a5e08b88e",
    "min_ram": 0,
    "schema": "/v2/schemas/image"
}

 

Request2:

$ curl -i -X PUT -H "X-Auth-Token: 94f2b7bf4cee4f2c9d2bbe1f2ca785a2" -H "Content-Type: application/octet-stream"  --upload-file /home/centos.tar http://192.168.31.147:9292/v2/images/0482eff2-8406-46a7-8bbb-d43e1ca9c14f/file

Reponse2:

    Headers:

HTTP/1.1 100 Continue

HTTP/1.1 204 No Content
Content-Type: text/html; charset=UTF-8
Content-Length: 0
X-Openstack-Request-Id: req-98582037-dca6-4792-8d4a-a76d04464834
Date: Fri, 22 May 2015 06:38:47 GMT

 

    個人感想:Openstack官網對建立映象的API描述真心的少啊,而且只有第一步,就是上文提到的request1。request2是筆者廢了九牛二虎之力才找到的,且一開始資料來源的上傳用的是 -d @/home/centos.tar  這個選項,但是經過反覆試驗,這個選項TM上傳檔案不完整,800M的檔案只能上傳230M,反覆查詢問題也找不到,最終換成--upload-file選項,上傳成功,且根據此映象可正常啟動例項。

 

    另外,對於curl 中 --upload-file選項該如何轉變為正常的httpClient請求,筆者至今還沒有頭緒,請大家幫忙

 

相關文章