Bluemix 容器 IP 分配的返回状态为 JSON
Returning status of Bluemix container IP allocation as JSON
我正在尝试使用 containers service available from IBM Bluemix 更好地自动化我的容器部署。我目前正处于我想创建一个脚本来分配 IP 地址然后点击 REST 端点以更新 DNS 条目的地步。
可以使用 IBM Containers plug-in with commands such as cf ic ip bind
. However, before executing that command, I'd like to know which IP addresses are available. This is commonly done with the cf ic ip list
命令来管理 IP 地址,该命令的输出如下所示:
分配的 public 个 IP 地址数: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-012345678912
2.1.1.3
2.1.1.4
1.1.1.3
2.1.1.5
这对人类来说是有用的输出,但需要大量额外的修改才能让脚本处理。有没有办法让这个命令 return 输出可能来自 API 的 JSON?对于常规的 CloudFoundry 命令,我们可以使用 cf curl
并获得可用的输出,但这里似乎没有模拟。
您可以为此使用 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-Token
的令牌和 X-Auth-Project-Id
的 space ID:
$ cf oauth-token
$ cf space <space-name> --guid
我正在尝试使用 containers service available from IBM Bluemix 更好地自动化我的容器部署。我目前正处于我想创建一个脚本来分配 IP 地址然后点击 REST 端点以更新 DNS 条目的地步。
可以使用 IBM Containers plug-in with commands such as cf ic ip bind
. However, before executing that command, I'd like to know which IP addresses are available. This is commonly done with the cf ic ip list
命令来管理 IP 地址,该命令的输出如下所示:
分配的 public 个 IP 地址数: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-012345678912
2.1.1.3
2.1.1.4
1.1.1.3
2.1.1.5
这对人类来说是有用的输出,但需要大量额外的修改才能让脚本处理。有没有办法让这个命令 return 输出可能来自 API 的 JSON?对于常规的 CloudFoundry 命令,我们可以使用 cf curl
并获得可用的输出,但这里似乎没有模拟。
您可以为此使用 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-Token
的令牌和 X-Auth-Project-Id
的 space ID:
$ cf oauth-token
$ cf space <space-name> --guid