閱讀932 返回首頁    go 網易 go 網易蜂巢


容器API

目錄

查看容器鏡像列表

請求 header

GET /api/v1/containers/images
Authorization:Token xxxxxxxxxxxxxx
Content-Type:application/json

返回

{
  "custom_images": [
    {
      "tag": "v1",
      "desc": "v1",
      "weight": 0,
      "id": 30202,
      "name": "4638_tomcat2",
      "constraint": null
    }
  ],
  "public_images": [
    {
      "tag": "latest",
      "desc": "",
      "weight": 3,
      "id": 10005,
      "name": "centos",
      "constraint”: {
        "min_combo": 20,
        "max_combo": 50,
        "min_machine_spec": 10,
        "max_machine_spec": 40
      }
    }
  ]
}
參數說明 描述 類型
custom_images 自定義鏡像 json array
public_images 官方鏡像 json array
tag 鏡像 tag string
desc 鏡像描述 string
weight 權重 int
id 鏡像 id long
name 鏡像名稱 string
constraint 鏡像限製 json
min_combo 最小套餐 int
max_combo 最大套餐 int
min_machine_spec 最小機器規格 int
min_machine_spec 最小機器規格 int

創建容器

請求 header

POST /api/v1/containers
Authorization:Token xxxxxxxxxxxxxx
Content-Type:application/json

請求 payload

{
  "charge_type": 1,
  "spec_id": 1,
  "image_type": 1,
  "image_id": 2,    //可參考 [[容器API#查看容器鏡像列表|查看容器鏡像列表]] 獲取
  "name": "name",
  "desc": "desc",
  "ssh_key_ids": [
    1,
    2
  ],
  "env_var": {
    "key": "value"
  },
  "use_public_network": 1,
  "network_charge_type": 1,
  "bandwidth": 100
}
參數說明 描述 類型 是否必填
charge_type 計費類型,1 (按套餐計費) / 2 (按需計費) int 必填
spec_id 容器規格 id,1 (微小型) / 10 (小型) / 20 (中型) / 30 (大型) / 40 (豪華型) / 50 (旗艦型) int 必填
image_type 鏡像類型,1 (官方鏡像) / 2 (自定義鏡像) int 必填
image_id 鏡像 id,可通過 查看容器鏡像列表 所述方法獲取 int 必填
name 容器名稱 string 必填
desc 容器描述 string 可填
ssh_key_ids ssh key id 列表 json 可填
env_var 環境變量 json 可填
use_public_network 是否使用公網,1 (使用) / 0 (不使用) int 按需計費必填
network_charge_type 1 (按帶寬) / 2 (按流量) int 按需計費且使用公網必填
bandwidth 帶寬大小,單位 Mbps,(0,100],針對按需計費,使用公網並且按照帶寬計費 int 按需計費,使用公網並且按照帶寬計費必填
響應
  • 成功響應
    201 Created
    {
     "id":100
    }
    
  • 參數說明 描述 類型
    id 容器 id long
  • 失敗響應 詳情請參見 錯誤返回碼

修改容器

請求 header

PUT /api/v1/containers/{containerId}
Authorization:Token xxxxxxxxxxxxxx
Content-Type:application/json

請求 payload

{
  "charge_type":1,
  "desc":"desc",
  "network_charge_type":1,
  "bandwidth":100
}
參數說明 描述 類型 是否必填
containerId 容器 id long 必填
charge_type 計費類型,1 (按套餐計費) / 2 (按需計費) int 可填
desc 容器描述 string 可填
network_charge_type 1 (按帶寬) / 2 (按流量) int 按需計費且使用公網必填
bandwidth 帶寬大小,單位 Mbps,(0,100],針對按需計費,使用公網並且按照帶寬計費 int 按需計費,使用公網並且按照帶寬計費必填
響應

容器列表

請求 header

GET /api/v1/containers
Authorization:Token xxxxxxxxxxxxxx
Content-Type:application/json

請求參數

limit=20&offset=0
參數說明 描述 類型 是否必填
limit 大於 0 小於等於 30,默認 20 int 可填
offset 偏移量,大於等於 0,默認 0 int 可填
響應
  • 成功響應
    200 Ok
    {
      "total": 1,
      "containers": [
        {
          "id": 100,
          "name": "name",
          "desc": "desc",
          "status": "create_fail",
          "bandwidth": 100,
          "replicas": 1,
          "charge_type": 1,
          "spec_id": 1,
          "created_at": "2016-03-19T05:44:17Z",
          "updated_at": "2016-03-19T05:44:17Z",
          "public_ip": null,
          "private_ip": null,
          "ssh_key_ids": [
            1,
            2
          ],
          "network_charge_type": 2,
          "image_id": 2,
          "use_public_network": 1,
          "env_var": {
            "key": "value"
          }
        }
      ]
    }
    
  • 參數說明 描述 類型
    id 容器 id long
    charge_type 計費類型,1 (按套餐計費) / 2 (按需計費) int
    spec_id 容器規格id,1 (微小型) / 10 (小型) / 20 (中型) / 30 (大型) / 40 (豪華型) / 50 (旗艦型) int
    name 容器名稱 string
    desc 容器描述 string
    ssh_key_ids ssh key id 列表 json
    env_var 環境變量 json
    image_id 鏡像 id int
    use_public_network 是否使用公網,1 (使用) / 0 (不使用) int
    network_charge_type 1 (按帶寬) / 2 (按流量) int
    bandwidth 帶寬大小,單位 Mbps int
    created_at 創建時間,使用 UTC(世界標準時間)時間,用 ISO8601 進行格式化 string
    updated_at 修改時間,使用 UTC(世界標準時間)時間,用 ISO8601 進行格式化 string
    status 容器狀態,一共 create、update、resize、delete 四種操作,每種對應著 ing (創建中) / succ (創建成功) / fail (創建失敗) / timeout (超時)四種狀態。 string
    private_ip 內網 ip string
    public_ip 外網 ip string
  • 失敗響應 詳情請參見 錯誤返回碼

查看容器

請求 header

GET /api/v1/containers/{containerId}
Authorization:Token xxxxxxxxxxxxxx
Content-Type:application/json
參數說明 描述 類型 是否必填
containerId 容器 id long 必填
響應
  • 成功響應
    200 Ok
    {
      "id": 10615,
      "name": "name",
      "desc": "desc",
      "status": "creating",
      "bandwidth": 100,
      "replicas": 1,
      "charge_type": 1,
      "spec_id": 1,
      "created_at": "2016-03-15T04:26:23Z",
      "updated_at": "2016-03-15T04:26:23Z",
      "public_ip": null,
      "private_ip": null,
      "ssh_key_ids": "2947",
      "network_charge_type": 2,
      "image_id": 2,
      "use_public_network": 1,
      "env_var": {
          "key": "value"
      }
    }
    
  • 參數說明 描述 類型
    id 容器 id long
    charge_type 計費類型,1 (按套餐計費) / 2 (按需計費) int
    spec_id 容器規格id,1 (微小型) / 10 (小型) / 20 (中型) / 30 (大型) / 40 (豪華型) / 50 (旗艦型) int
    name 容器名稱 string
    desc 容器描述 string
    ssh_key_ids ssh key id 列表 json
    env_var 環境變量 json
    image_id 鏡像 id int
    bandwidth 帶寬大小,單位 Mbps int
    network_charge_type 1 (按帶寬) / 2 (按流量) int
    use_public_network 是否使用公網,1 (使用) / 0 (不使用) int
    created_at 創建時間,使用 UTC(世界標準時間)時間,用 ISO8601 進行格式化 string
    updated_at 修改時間,使用 UTC(世界標準時間)時間,用 ISO8601 進行格式化 string
    status 容器狀態,creating (創建中) / create_succ (創建成功) / create_fail (創建失敗) string
    public_ip 外網 ip string
    private_ip 內網 ip string
  • 失敗響應 詳情請參見 錯誤返回碼

刪除容器

請求 header

DELETE /api/v1/containers/{containerId}
Authorization:Token xxxxxxxxxxxxxx
Content-Type:application/json
參數說明 描述 類型 是否必填
containerId 容器 id long 必填
響應

重啟容器

請求 header

PUT /api/v1/containers/{containerId}/actions/restart
Authorization:Token xxxxxxxxxxxxxx
Content-Type: application/json
參數說明 描述 類型 是否必填
containerId 容器 id long 必填
響應

容器保存為鏡像

請求 header

POST /api/v1/containers/{containerId}/tag
Authorization: token xxxxxxxxxxxxxx
Content-Type: application/json

請求 payload

{
  "repo_name": "cluster",
  "tag": "1.2.6"
}
參數說明 描述 類型 是否必填
containerId 容器 id long 必填
repo_name 鏡像倉庫名稱 string 必填
tag 鏡像Tag string 必填
響應
  • 成功響應
    201 Created
    {
      image_id: “409”
    }
    
  • 參數說明 描述 類型
    image_id 容器轉為的鏡像的鏡像Id string
  • 失敗響應 詳情請參見 錯誤返回碼

獲取容器流量數據

描述

提供查詢指定容器在某段時間範圍內流量使用情況服務,接收起始時間和終止時間參數(起始時間和終止時間參數可選,如果不傳入起始時間和終止時間,則默認查詢從創建到目前的容器流量,如果起始時間或終止時間是負值,則默認使用容器創建時間或當前時間),向客戶端返回200狀態碼和容器在該段時間內使用的流量值。

請求 header

GET /api/v1/containers/{containerId}/flow?from_time=1111&to_time=111111
Authorization: token xxxxxxxxxxxxxx
Content-Type: application/json
參數說明 描述 類型 是否必填
containerId 容器 id long 必填
from_time 起始時間,默認為容器創建時間 long 可選
to_time 終止時間,默認為係統當前時間 long 可選
響應
  • 成功響應
    200 OK
    {
      "container_up_flow": "1234.0MB",
      "container_down_flow": "111111.0MB"
    }
    
  • 參數說明 描述 類型
    container_up_flow 容器使用的上行流量 string
    container_down_flow 容器使用的下行流量 string
  • 失敗響應 詳情請參見 錯誤返回碼

最後更新:2017-01-03 10:48:53

  上一篇:go 桶的操作
  下一篇:go 個人網站名稱要求