以前一直想写博客,但因各种因素一直没写。最近在做OpenStack,而OpenStack对外提供REST API,今天就简要介绍一下OpenStack REST API 使用,关于什么是REST API可以参考以下两篇博文:
http://www.choudan.net/2013/07/28/OpenStack-Restful-API.html
http://www.ruanyifeng.com/blog/2011/09/restful.html
简单的来说,一切都是资源,每个资源对应一个URI。
我们可以使用linux curl命令使用REST API向OpenStack发送请求,例如根据用户名、密码和tenant得到token:
curl -i 'http://127.0.0.1:5000/v2.0/tokens' -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "secretsecret"}}}'
但是我觉得用curl命令不太方便,而且有时候返回结果很长很长的时候不太好看,所以就使用了RESTClient,因为是在CentOS环境下工作,于是在火狐下装了个RESTClient插件,像上面的请求可以轻松搞定,加入两个Header,如果要访问其他资源,则还另外需要一个Header:x-auth-token,选择一个Method,然后在Body里面写下需要的东西,截图如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7IAAAGvCAIAAADpNX7PAAAgAElEQVR4nO3dv2sjab7o4fljTrDBBDZMMA0T3M6W4QZDgYM9cIO7cBPBBsZRY05waE4wFBsYbrLgznqTplBwWU5gUAcD1YFBHTRoggkqUFCBAwUdKOjkvUFJpSpV6act64efhw/neGWpVJbk1ndel6TvRgAA8OJ9t+8dAACA/auMxQ+jfJhnAABw0vJhPnpYNBY/jMbjcfgWJEmSpBNu/HU8+DIYfBnkw7wxFj+M9r5/kiRJ0rOVfkr7n/vVyfg768SSJEl6aY2/jnt3vcGXQXk0xXf5MN/7bkmSJEnPXNJN0k9puWD8XZZle98nSZIk6ZlLPiS9j70sy4zFkiRJerm9/+f73p2xWJIkSS87Y7EkSZJ06mNxnueDL4P+576equJd/fZ+z7r3JUlap8c/cY8+9rM//3v/7PXxlv3530cf+yt/0lMei/M8z/7IxqPx+OvLrf+5v+UnHi7yMBr8fgSTsXtfkvRsPf2z7RN69BP34MefR3/56+j/dI64v/x18NPPK3/S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gAAIKxGAAAgrEYAACCsRgAAIKxGAAAgrEYAACCsRgAAIKxGAAAgrEYAACCsRgAAIKxGAAAgrEYAACCsRgAAIKxGAAAgrEYAACCsRgAAIKxGAAAgrEYAACCsRgAAIKxGAAAgrEYAACCsRgAgJek97HX+9hr+YaxGACAl8NYDAAAixmLAQDAWAwAwImrHjjhIAoAAF4oYzEAAKzHWAwAAMZiAABO0KIDJxxEAQDAC2IsBgCAzRmLAQDAWAwAAI8fi7+GbBSyB2MxAADH7Fu4uhtnDyEbhfzr5mNxuWBsLAYA4IhNx+JiqXjdsTiMw3gcxsZiAABOQ30sHn8N43EIq8fixoKxsRgAgCP2LVzdjVuXileMxXMvvLu6G0uSJElHXfPFdpuNxcVr74qjKYoGuSRJknToleNrPn2l3fZj8dxknI8m700hSZIkHXqjyQQ7NxNvNhY314zn5mNJkiTpoPtam2ObA/HGY/HcyrEkSZJ0LM0NtFuOxcX7tTXn41lfJUmSpINpwdRajrVrjcXjr+P2yXjx+rEkSZJ0sK0ebr+Okw9J72NlLM6H+eDLYOUlJUmSpJOp97GXdJP0U5oP88lYPHoYDb4M0k/pOmvGkiRJ0lE3/jrufewlH5LeXW/w+2D0MJqOxaNRnuf9z/3eXS/pJsmH5P0/30uSJEknWfIhSbpJ767X/9zP88lS8WQsLibjYs24d9eTJEmSTrj0Uzr4MqjOxLOxeDQa5cN88Pug/7nfv5ckSZJOtM/9we+D8pDilrEYAABerP8PYV0t/4CqlbQAAAAASUVORK5CYII=" alt="" />
Body:
{
"auth":{
"passwordCredentials":{
"username":"admin",
"password":""
},
"tenantName":"admin"
}
}
OpenStack的API大多都在官方文档中写了,为什么说大多,而不是全部,是因为有些真没写,我觉得其中没写的分两类:
- 没有及时更新。
- 觉得没必要写,认为大家可以猜到,或者可以从源码中找到蛛丝马迹。毕竟搞OpenStack还是得要两把刷子。
举几个目前API文档中没写或者没有详细说明用法的API,比如:
- OpenStack中的admin用户如何获得所有tenant(project)下的虚机信息。具体的做法是加上query参数all_tenants,即:/v2/{tenant_id}/servers/detail?all_tenants=true
- 延伸第一条,admin如何获取某个tenant下的虚机。/v2/{tenant_id}/servers/detail?all_tenants=true&project_id=XXX
还有好多可以加query参数的API,就不一一列举了。
还有一个问题,在API文档中只有URL的后半部分,那么前半部分去哪了,前半部分就在当初安装OpenStack时创建的endpoint中,我们可以使用以下命令找到:
keystone endpoint-list
keystone endpoint-get --service=XXX
在实际的编码中我们当然不能在代码里把URL写死,应该通过查数据表得到各个服务的endpoint,然后生成完整的URL。细心的同学就会发现,在每次认证的时候不仅会返回token而且会返回serviceCatalog,里面就有我们想要的endpoint,就不必再单独再去查一次数据库了。
有个问题没太弄懂,不知是否有人解答一下:
keystone两个端口,一个是5000,一个是35357(adminURL)。两个权限不一样,创建用户什么的必须用35357。我知道OpenStack采用Policy来管理某个用户在某个tenant下的权限。但后台具体是如何区分5000和35357的呢,怎样让35357可以创建用户而5000创建不了用户。