2016-03-05 51 views
0

我正試圖使用​​containers service available from IBM Bluemix更好地自動化我的容器部署。我目前正在創建一個腳本來分配IP地址,然後點擊REST端點來更新DNS條目。將Bluemix容器IP分配的狀態返回爲JSON

IP地址的管理可以使用IBM Containers plug-in使用cf ic ip bind等命令完成。但是,在執行該命令之前,我想知道哪些IP地址可用。 已分配的公網IP地址:這通常與具有輸出看起來像這樣的cf ic ip list命令完成8

Listing the IP addresses in this space... 
IP Address  Container ID 
1.1.1.1  
1.1.1.2   
2.1.1.1  
2.1.1.2   deadbeef-aaaa-4444-bbbb-
2.1.1.3   
2.1.1.4   
1.1.1.3  
2.1.1.5 

這是有用的輸出到一個人,但需要很多額外的改寫(munging)的一個腳本處理。有沒有辦法簡單地讓這個命令返回可能來自API的JSON輸出?對於普通的CloudFoundry命令,我們可以使用cf curl並獲得可用的輸出,但在這裏似乎沒有模擬。

回答

3

您可以使用該IBM Containers REST API

curl -X GET --header "Accept: application/json" --header "X-Auth-Token: xxxxxxxx" --header "X-Auth-Project-Id: xxxxxxxx" "https://containers-api.ng.bluemix.net/v3/containers/floating-ips?all=true" 

輸出的例子是(出於隱私目的,我修改了下面的輸出):

[ 
    { 
     "Bindings": { 
      "ContainerId": null 
     }, 
     "IpAddress": "111.111.1111.1111", 
     "MetaId": "607c9e7afaf54f89b4d1c926", 
     "PortId": null, 
     "Status": "DOWN" 
    }, 
    { 
     "Bindings": { 
      "ContainerId": "abcdefg-123" 
     }, 
     "IpAddress": "111.111.1111.1112", 
     "MetaId": "607c9e7afaf54f89b4d1c9262d", 
     "PortId": "8fa30c31-1128-43da-b709", 
     "Status": "ACTIVE" 
    }, 
    { 
     "Bindings": { 
      "ContainerId": "abcdefg-123" 
     }, 
     "IpAddress": "111.111.1111.1113", 
     "MetaId": "607c9e7afaf54f89b4d1c9262", 
     "PortId": "6f698778-94f6-43d0-95d1", 
     "Status": "ACTIVE" 
    }, 
    { 
     "Bindings": { 
      "ContainerId": null 
     }, 
     "IpAddress": "111.111.1111.1114", 
     "MetaId": "607c9e7afaf54f89b4d1c926", 
     "PortId": null, 
     "Status": "DOWN" 
    } 
] 

要獲得令牌的X-Auth-TokenX-Auth-Project-Id空間ID :

$ cf oauth-token 
$ cf space <space-name> --guid