|
如之前讨论,openstack提供一套接口给运维管理平台,运维管理平台通过获取到的IP地址对主机进行监控。
接口名 | 请求地址 | 请求方法 | 请求cookie | 请求头 | 返回值 | 返回值使用 | 登录接口 | osbc.timanetworks.com/ | POST | | username='admin'&password='veM]HQ~P' | response.body={"code": 200,'tenant_name':tenant_name},cookie:token_idresponse.body={"code": 200,'tenant_name':tenant_name},cookie:token_id | response.body里的code可以判定请求是否成功,cookie默认是1天过期,这里的token_id是作为后面所有请求的一种凭证。 | 服务器列表接口 | osbc.timanetworks.com/api | POST | 需要登录接口cookie token_id | type='instance_list' | | 返回值是一个json字符串,解析可获取几乎主机所有详情。 | 提供ajax请求代码作为参考:
$.ajax({
url:"",
type:"POST",
data:"username="+username+"&password="+password,
cache:false,
success:function(data){
var t = eval(data);
if(t.code === 200){
window.location.href = "/main";
var tenant_name = data.tenant_name;
$.cookie("tenant_name", tenant_name, {expires:1});
}else if(t.code === 401 ){
$("#error").html('<p>用户没有权限登陆或者账号密码错误,错误号' + t.code + '</p>');
}else{
$("#error").html('<p>系统错误,请联系管理员。错误号' + t.code + '</p>');
}
}
}) |
$.ajax({
async:true,
url:"/api",
type:"POST",
data:"type=instance_list",
success:function(t){
var server_name = t.servers[0].name;
}
}) | 如在开发中有任何问题,请及时联系。 |
|
|