Reputation: 5503
I'm trying to better automate my deployment of containers using the containers service available from IBM Bluemix. I'm currently at the point where I'd like to create a script to assign an IP address and then hit a REST endpoint to update the DNS entry.
Management of IP addresses can be done using the 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
command which has output that looks like this:
Number of allocated public IP addresses: 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
This is useful output to a human, but requires a lot of extra munging for a script to handle. Is there a way to simply have this command return the JSON output that is probably coming from the API? For regular CloudFoundry commands we can use cf curl
and get usable output, but there doesn't appear to be an analog here.
Upvotes: 0
Views: 49
Reputation: 4590
You can use the IBM Containers REST API for that:
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"
Example of output is (for privacy purposes I modified output below):
[
{
"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"
}
]
To get token for X-Auth-Token
and space ID for X-Auth-Project-Id
:
$ cf oauth-token
$ cf space <space-name> --guid
Upvotes: 3