是否有使用 IBM Bluemix Container API 的示例代码?

Is there a sample code for using IBM Bluemix Container API?

我正在尝试使用 API 在 bluemix 中创建容器,就像 http://ccsapi-doc.mybluemix.net 在文档中提到的那样:

在新模型中使用 API 时,应提供以下 HTTP headers: X-Auth-Token = Bluemix JWT 令牌 X-Auth-Project-Id = Space GUID

但我不知道如何获取或生成 Bluemix JWT 令牌。有人可以帮助我吗?

尝试展开该页面上的身份验证部分和 "Get TLS Certificate" 以显示更多信息

当您输入值并单击 "try it out" 时,您将看到使用令牌信息生成的额外输出。

您可以通过cf oauth-token命令获得X-Auth-Token。然后复制并粘贴 bearer 之后的其余部分。您还可以通过 cf space --guid <space Name> 获得 X-Auth-Project-Id。请参阅以下命令;

$ cf login -a api.<region>.bluemix.net -u <space name> -o <org name> -s <space name>

$ cf ic login

$ cf oauth-token

$ cf space <space-name> --guid (space name where the container exists)

这是另一种方法:

您可以使用以下命令检索 X-Auth-TokenX-Auth-Project-Id

cf login
CF_TRACE=true cf ic login

复制 .txt 文件中的所有输出并搜索 X-Auth-Token 和 X-Auth-Project-Id

这里有一个简单的例子:

curl -X GET --header "Accept: application/json" --header "X-Auth-Token: asdlkfajdfdkaldkjfskl239049283049jsdfjksl29304" --header "X-Auth-Project-Id: sdfadf-0090-43ef-22932-23434234" "https://containers-api.ng.bluemix.net/v3/containers/quota"


Response:
The output of API is like this:
{
  "account_type": "TRIAL",
  "country_code": "ITA",
  "org_quota": {
    "floating_ips_max": "2",
    "floating_ips_space_default": "2",
    "floating_ips_usage": 2,
    "ram_max": "2048",
    "ram_space_default": "2048",
    "ram_usage": 2048,
    "subnet_usage": -1,
    "subnets_default": "5",
    "subnets_max": 0
  },
  "space_quota": {
    "floating_ips_max": 2,
    "ram_max": 2048,
    "subnets_max": -1
  }