Horizon/RESTAPI
目录
Horizon REST API
从 Kilo 版本开始,Horizon 具有一个 REST API,允许客户端代码通过 Horizon 服务器进行 API 调用,而无需 Django 服务器端渲染。这是为了支持 Horizon 中正在进行的 angular 工作。它处理诸如跨域资源脚本问题,以及利用已经存在的身份验证和授权库等问题。
这些 API 仅供 Horizon 开发使用,目前不打算对外开放。
它们还处于开发的早期阶段,旨在支持树内开发。在进一步通知之前,如果需要更改,将不会有弃用期。
状态
Liberty
Server sideː [1] Client sideː [2]
Kilo
Summit Talkː [3] Server sideː [4] Client sideː [5]
测试
要使用 POSTMAN(Chrome 插件)测试 Horizon REST API,请正常登录,访问您将在 POSTMAN 中使用的确切 API 地址(或 localhost)。登录后,您的浏览器将拥有一个访问 cookie,它将在所有请求中传递。
您还需要安装 POSTMAN 拦截器,并从浏览器登录到 Horizon。
GET 请求
输入 URL。
例如:http://127.0.0.1:8005/api/glance/images
设置以下头部
| 头部 | 值 |
|---|---|
| X-Requested-With | XMLHttpRequest |
GET 请求应包含一个 csrftoken cookie(例如:csrftoken=onXnBfMqIxuFGr437P91Uuxdl09t2ykQ)。如果需要执行任何 POST 请求,您应该将其复制下来。
POST 请求
输入 URL。
例如:http://127.0.0.1:8005/api/nova/keypairs/
设置以下头部
| 头部 | 值 |
|---|---|
| X-Requested-With | XMLHttpRequest |
| Content-Type | application/json |
| X-CSRFToken | 您在对相同地址的任何 GET 请求中看到的 csrftoken cookie 的值。您可以从上述 GET 调用中的 REQUEST 头部发送的 cookie 中获取该 token。 |
将原始内容设置为 JSON 格式。
示例:
{
"name":"foo"
}
Postman Collections
以下是一些可以帮助测试的 POSTMAN Collections。列出了它们有效日期,以及 collection 内容。
2016-04-18
Cinder Horizonː https://www.getpostman.com/collections/342a35ae1063767049ed Glance Directː https://www.getpostman.com/collections/2ec9be630bc6b860e31d Glance Horizonː https://www.getpostman.com/collections/0fb61d16402b0b2bb640 Keystone Directː https://www.getpostman.com/collections/a8364572e67c0f067c2e Keystone Horizonː https://www.getpostman.com/collections/3fe2767e50acf34893fc Network Abstraction Horizonː https://www.getpostman.com/collections/165869c840477c8b22a7 Neutron Directː https://www.getpostman.com/collections/96ced18cd6483318ccf1 Neutron Horizonː https://www.getpostman.com/collections/f372f0480ada8fdb61ed Nova Directː https://www.getpostman.com/collections/127fc0afe0dacd4806d5 Nova Horizonː https://www.getpostman.com/collections/b5d0ed70a0c7b5f82d03 Horizon Policyː https://www.getpostman.com/collections/dd65a2cc201169bcab91 Searchlight Directː https://www.getpostman.com/collections/4165d893505350d5761a Searchlight Horizonː https://www.getpostman.com/collections/2c1fa8a695303122ad7a
使用此页面底部的以下 Postman 环境。
2015-04-06
Keystone: https://www.getpostman.com/collections/311080eb87c7bca1b7b1 Neutron: https://www.getpostman.com/collections/401a40ae526887e378ef Network: https://www.getpostman.com/collections/be29e7af5243d09d8b99 Nova Direct: https://www.getpostman.com/collections/0b6e8b0eb23687bfeec0 Nova Horizon: https://www.getpostman.com/collections/1c24ae62ea46c8a56791 Policy: https://www.getpostman.com/collections/acf134dde5c77ad81a1b Cinder: https://www.getpostman.com/collections/6c7391cd25603c2218fe Config: https://www.getpostman.com/collections/b64d279e663de38897c8 Glance: https://www.getpostman.com/collections/2dd5e5e2e849bf3880fc
POSTMAN 环境
{ "name": "OpenStack @ 192.168.200.200", "values": [ { "key": "IP", "value": "127.0.0.1", "type": "text", "name": "IP", "enabled": true }, { "key": "HORIZON_PORT", "value": "8005", "type": "text", "name": "HORIZON_PORT", "enabled": true }, { "key": "TOKEN", "value": "REPLACE̞ME", "type": "text", "name": "TOKEN", "enabled": true }, { "key": "KEYSTONE_PORT", "value": "5000", "type": "text", "name": "KEYSTONE_PORT", "enabled": true }, { "key": "OS_TENANT_NAME", "value": "demo", "type": "text", "name": "OS_TENANT_NAME", "enabled": true }, { "key": "OS_TENANT_ID", "value": "REPLACE̠ME", "type": "text", "name": "OS_TENANT_ID", "enabled": true }, { "key": "OS_USERNAME", "value": "admin", "type": "text", "name": "OS_USERNAME", "enabled": true }, { "key": "OS_PASSWORD", "value": "REPLACE̙ME", "type": "text", "name": "OS_PASSWORD", "enabled": true }, { "key": "NOVA_V2_PORT", "value": "8774", "type": "text", "name": "NOVA_V2_PORT", "enabled": true }, { "key": "SEARCHLIGHT_V1_PORT", "value": "9393", "type": "text", "name": "SEARCHLIGHT_V1_PORT", "enabled": true }, { "key": "OS_DOMAIN_NAME", "value": "admin", "type": "text", "name": "OS_DOMAIN_NAME", "enabled": true }, { "key": "OS_DOMAIN_ID", "value": null, "type": "text", "name": "OS_DOMAIN_ID", "enabled": true }, { "key": "GLANCE_V2_PORT", "value": "9292", "type": "text", "name": "GLANCE_V2_PORT", "enabled": true }, { "key": "HORIZON_LOCAL_IP", "value": "127.0.0.1", "type": "text", "name": "HORIZON_LOCAL_IP", "enabled": true }, { "key": "SEARCHLIGHT_LOCAL_IP", "value": "127.0.0.1", "type": "text", "enabled": true } ], "team": null, "timestamp": 1461035969136, "synced": false, "syncedFilename": "", "isDeleted": false }