API获取信息流程:
#curl -k -X 'POST' -v http://172.16.9.60:5000/v2.0/tokens -d '{"auth":{"passwordCredentials":{"username": "admin", "password":"admin_pass"}, "tenantid":""}}' -H 'Content-type: application/json'
这里解释下关于curl的命令(是用来模拟http/https或者FTP请求的工具)
k表示不需要确认安全认证
X表示使用何种命令
v表示显示更多的交互信息(比如下面的POST...到Date数据就是交互信息)
d表示http POST 过去的data
H表示只是模拟的HTTP/HTTPS请求
返回并且打印在界面的数据:
> POST /v2.0/tokens HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: 172.16.9.60:5000
> Accept: */*
> Content-type: application/json
> Content-Length: 94
>
* upload completely sent off: 94out of 94 bytes
< HTTP/1.1 200 OK
< Vary: X-Auth-Token
< Content-Type: application/json
< Content-Length: 1133
< Date: Mon, 19 Aug 2013 06:23:48 GMT
{"access": {"token": {"issued_at": "2013-08-19T06:23:48.695306", "expires": "2013-08-20T06:23:48Z", "id": "MIICbgYJKoZIhvcNAQcCoIICXzCCAlsCAQExCTAHBgUrDgMCGjCCAUcGCSqGSIb3DQEHAaCCATgEggE0eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAiMjAxMy0wOC0xOVQwNjoyMzo0OC42OTUzMDYiLCAiZXhwaXJlcyI6ICIyMDEzLTA4LTIwVDA2OjIzOjQ4WiIsICJpZCI6ICJwbGFjZWhvbGRlciJ9LCAic2VydmljZUNhdGFsb2ciOiBbXSwgInVzZXIiOiB7InVzZXJuYW1lIjogImFkbWluIiwgInJvbGVzX2xpbmtzIjogW10sICJpZCI6ICJjMDRjMmM5ODA0MWM0YTAwYTIzMjYwN2E4MjUwYjVmNCIsICJyb2xlcyI6IFtdLCAibmFtZSI6ICJhZG1pbiJ9LCAibWV0YWRhdGEiOiB7ImlzX2FkbWluIjogMCwgInJvbGVzIjogW119fX0xgf8wgfwCAQEwXDBXMQswCQYDVQQGEwJVUzEOMAwGA1UECBMFVW5zZXQxDjAMBgNVBAcTBVVuc2V0MQ4wDAYDVQQKEwVVbnNldDEYMBYGA1UEAxMPd3d3LmV4YW1wbGUuY29tAgEBMAcGBSsOAwIaMA0GCSqGSIb3DQEBAQUABIGAOLyKFaSXJ-B-+1NeXf+zWyI3tq2JRAcq8afYaj-XQCXWmEsF75X7ZPVMOlQGfbWQCJdDMQLswtT97Erd5q6NTLjM0lnQeuC+IbPEYijaDC+d+P660vntzC6pyneoLVKFvXXcCr85tV1Vw3OvYH2obkjN97VE2OOUnfi65py8NHc="}, "serviceCatalog": [], "user": {"username": "admin", "roles_links": [], "id": * Connection #0 to host 172.16.9.60 left intact
* Closing connection #0
"c04c2c98041c4a00a232607a8250b5f4", "roles": [], "name": "admin"}, "metadata": {"is_admin": 0, "roles": []}}}
这里会获得一个24小时的token,通过token我们调用其他的API,另外我们也可以知道登陆openstack的角色
#curl -H "X-Auth-Token:MIICbgYJKoZIhvcNAQcCoIICXzCCAlsCAQExCTAHBgUrDgMCGjCCAUcGCSqGSIb3DQEHAaCCATgEggE0eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAiMjAxMy0wOC0xOVQwNjoyMzo0OC42OTUzMDYiLCAiZXhwaXJlcyI6ICIyMDEzLTA4LTIwVDA2OjIzOjQ4WiIsICJpZCI6ICJwbGFjZWhvbGRlciJ9LCAic2VydmljZUNhdGFsb2ciOiBbXSwgInVzZXIiOiB7InVzZXJuYW1lIjogImFkbWluIiwgInJvbGVzX2xpbmtzIjogW10sICJpZCI6ICJjMDRjMmM5ODA0MWM0YTAwYTIzMjYwN2E4MjUwYjVmNCIsICJyb2xlcyI6IFtdLCAibmFtZSI6ICJhZG1pbiJ9LCAibWV0YWRhdGEiOiB7ImlzX2FkbWluIjogMCwgInJvbGVzIjogW119fX0xgf8wgfwCAQEwXDBXMQswCQYDVQQGEwJVUzEOMAwGA1UECBMFVW5zZXQxDjAMBgNVBAcTBVVuc2V0MQ4wDAYDVQQKEwVVbnNldDEYMBYGA1UEAxMPd3d3LmV4YW1wbGUuY29tAgEBMAcGBSsOAwIaMA0GCSqGSIb3DQEBAQUABIGAOLyKFaSXJ-B-+1NeXf+zWyI3tq2JRAcq8afYaj-XQCXWmEsF75X7ZPVMOlQGfbWQCJdDMQLswtT97Erd5q6NTLjM0lnQeuC+IbPEYijaDC+d+P660vntzC6pyneoLVKFvXXcCr85tV1Vw3OvYH2obkjN97VE2OOUnfi65py8NHc=" http://172.16.9.60:5000/v2.0/tenants
返回值
{"tenants_links": [], "tenants": [{"description": "", "enabled": true, "id": "934ab93843e74c5b99c951fcf3762239", "name": "admin"}]}
通过知道user的tenant-id我们接下来就可以去请求相应的service
#curl -k -X 'POST' -v http://172.16.9.60:5000/v2.0/tokens -d '{"auth":{"passwordCredentials":{"username":"admin","password":"admin_pass"},"tenantId":"934ab93843e74c5b99c951fcf3762239"}}' -H 'Content-type: application/json'
返回值:
> POST /v2.0/tokens HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: 172.16.9.60:5000
> Accept: */*
> Content-type: application/json
> Content-Length: 123
>
* upload completely sent off: 123out of 123 bytes
< HTTP/1.1 200 OK
< Vary: X-Auth-Token
< Content-Type: application/json
< Content-Length: 6159
< Date: Mon, 19 Aug 2013 06:41:50 GMT
<
{"access": {"token": {"issued_at": "2013-08-19T06:41:50.182111", "expires": "2013-08-20T06:41:50Z", "id": "MIIK2AYJKoZIhvcNAQcCoIIKyTCCCsUCAQExCTAHBgUrDgMCGjCCCbEGCSqGSIb3DQEHAaCCCaIEggmeeyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAiMjAxMy0wOC0xOVQwNjo0MTo1MC4xODIxMTEiLCAiZXhwaXJlcyI6ICIyMDEzLTA4LTIwVDA2Oj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YDVQQGEwJVUzEOMAwGA1UECBMFVW5zZXQxDjAMBgNVBAcTBVVuc2V0MQ4wDAYDVQQKEwVVbnNldDEYMBYGA1UEAxMPd3d3LmV4YW1wbGUuY29tAgEBMAcGBSsOAwIaMA0GCSqGSIb3DQEBAQUABIGAH-6xchS74MqXTrHCfiTVymPUCrkeLiKB6Q6LuIL4SVamvNGRgk3MHhMkGRoTjJElSJcjAMsbn6nHN7huND2B35bKIBoF9bI+4H1D8StsNZWFjHNT27yn3Le0wS3W5xNTwaW9gyFiqBNs3dVAZuj+CcPolzykomH+veZQ1obYrW0=", "tenant": {"description": "", "enabled": true, "id": "934ab93843e74c5b99c951fcf3762239", "name": "admin"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://10.30.30.51:8774/v2/934ab93843e74c5b99c951fcf3762239", "region": "RegionOne", "internalURL": "http://10.30.30.51:8774/v2/934ab93843e74c5b99c951fcf3762239", "id": "1ea66f3fd38c42c5a40964911ef2ad28", "publicURL": "http://172.16.9.60:8774/v2/934ab93843e74c5b99c951fcf3762239"}], "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": "http://10.30.30.51:9696/", "region": "RegionOne", "internalURL": "http://10.30.30.51:9696/", "id": "3e6b9d2c43d3454e8910bf6504a03a4b", "publicURL": "http://172.16.9.60:9696/"}], "endpoints_links": [], "type": "network", "name": "quantum"}, {"endpoints": [{"adminURL": "http://10.30.30.51:9292/", "region": "RegionOne", "internalURL": "http://10.30.30.51:9292/", "id": "547398ec0e504233ac6d232877e86546", "publicURL": "http://172.16.9.60:9292/"}], "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": "http://10.30.30.51:8776/v1/934ab93843e74c5b99c951fcf3762239", "region": "RegionOne", "internalURL": "http://10.30.30.51:8776/v1/934ab93843e74c5b99c951fcf3762239", "id": "1d06c2a9c37d45e8a1b15c93c92ebe61", "publicURL": "http://172.16.9.60:8776/v1/934ab93843e74c5b99c951fcf3762239"}], "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": [{"adminURL": "http://10.30.30.51:8773/services/Admin", "region": "RegionOne", "internalURL": "http://10.30.30.51:8773/services/Cloud", "id": "4643ff3d237c45e1b4766237903934b8", "publicURL": "http://172.16.9.60:8773/services/Cloud"}], "endpoints_links": [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://10.30.30.51:35357/v2.0", "region": "RegionOne", "internalURL": "http://10.30.30.51:5000/v2.0", "id": "02cc684b24ba468ab8acf91f7944bda6", "publicURL": "http://172.16.9.60:5000/v2.0"}], "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": "admin", "roles_links": [], "id": "c04c2c98041c4a00a232607a8250b5f4", "roles": [{"name": "KeystoneAdmin"}, {"name": "KeystoneServiceAdmin"}, {"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles": ["cfc1dde103e9487e92dcb00c61435695", "2130a114f9ac45e58989f3b9a1c6ec5f", "f413450df2b54ec3b7f5ed* Connection #0 to host 172.16.9.60 left intact
* Closing connection #0
017c3d80a0"]}}}
我们可以看到在json数据的最后有一系列的server的endpoint,这个就是我们需要的!(比如需要显示有多少service);另外把token换成上面这个方法获取的token的id
以上获取信息的token是可以用来调用nova API的结构:
curl -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2//servers/detail?project_id=
"servers": [
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-SRV-ATTR:host": "grizzly-compute",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "grizzly-compute.hengtiansoft.com",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000013",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"net_proj_one": [
{
"OS-EXT-IPS:type": "fixed",
"addr": "50.50.1.9",
"version": 4
}
]
},
"config_drive": "",
"created": "2013-08-20T09:47:37Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "3d06da1739cd1d26e55ddf60e9a98c0a5f5330b7d16207c3fadb60fa",
"id": "60d0e2de-5e66-4267-b6d0-6abbaf68aa08",
"image": {
"id": "f30de903-6491-4683-992b-67294337d02a",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/f30de903-6491-4683-992b-67294337d02a",
"rel": "bookmark"
}
]
},
"key_name": null,
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/60d0e2de-5e66-4267-b6d0-6abbaf68aa08",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/60d0e2de-5e66-4267-b6d0-6abbaf68aa08",
"rel": "bookmark"
}
],
"metadata": {},
"name": "test6",
"progress": 0,
"security_groups": [
{
"name": "default"
}
],
"status": "ACTIVE",
"tenant_id": "51f084cf981b4e28a9909f9f77313ecc",
"updated": "2013-08-20T09:47:46Z",
"user_id": "5eaf859febff4d76be6187966a4ba6ac"
},
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-SRV-ATTR:host": "grizzly-compute",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "grizzly-compute.hengtiansoft.com",
"OS-EXT-SRV-ATTR:instance_name": "instance-0000000c",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"net_proj_one": [
{
"OS-EXT-IPS:type": "fixed",
"addr": "50.50.1.8",
"version": 4
}
]
},
"config_drive": "",
"created": "2013-08-19T08:50:21Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "3d06da1739cd1d26e55ddf60e9a98c0a5f5330b7d16207c3fadb60fa",
"id": "c8e73f60-da62-4ab5-9f38-ffaecbccced3",
"image": {
"id": "f30de903-6491-4683-992b-67294337d02a",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/f30de903-6491-4683-992b-67294337d02a",
"rel": "bookmark"
}
]
},
"key_name": null,
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/c8e73f60-da62-4ab5-9f38-ffaecbccced3",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/c8e73f60-da62-4ab5-9f38-ffaecbccced3",
"rel": "bookmark"
}
],
"metadata": {},
"name": "test5",
"progress": 0,
"security_groups": [
{
"name": "default"
}
],
"status": "ACTIVE",
"tenant_id": "51f084cf981b4e28a9909f9f77313ecc",
"updated": "2013-08-19T08:50:29Z",
"user_id": "5eaf859febff4d76be6187966a4ba6ac"
},
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-SRV-ATTR:host": "grizzly-compute",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "grizzly-compute.hengtiansoft.com",
"OS-EXT-SRV-ATTR:instance_name": "instance-0000000b",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"net_proj_one": [
{
"OS-EXT-IPS:type": "fixed",
"addr": "50.50.1.7",
"version": 4
}
]
},
"config_drive": "",
"created": "2013-08-19T08:49:04Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "3d06da1739cd1d26e55ddf60e9a98c0a5f5330b7d16207c3fadb60fa",
"id": "bef3d87c-bd18-4b6a-abfd-65fda7b523ae",
"image": {
"id": "b2115dd6-cb34-4e02-a5da-4e5a49aebd6b",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/b2115dd6-cb34-4e02-a5da-4e5a49aebd6b",
"rel": "bookmark"
}
]
},
"key_name": null,
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/bef3d87c-bd18-4b6a-abfd-65fda7b523ae",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/bef3d87c-bd18-4b6a-abfd-65fda7b523ae",
"rel": "bookmark"
}
],
"metadata": {},
"name": "test4",
"progress": 0,
"security_groups": [
{
"name": "default"
}
],
"status": "ACTIVE",
"tenant_id": "51f084cf981b4e28a9909f9f77313ecc",
"updated": "2013-08-19T08:49:10Z",
"user_id": "5eaf859febff4d76be6187966a4ba6ac"
},
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-SRV-ATTR:host": "grizzly-compute",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "grizzly-compute.hengtiansoft.com",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000009",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"net_proj_one": [
{
"OS-EXT-IPS:type": "fixed",
"addr": "50.50.1.3",
"version": 4
},
{
"OS-EXT-IPS:type": "floating",
"addr": "172.16.7.103",
"version": 4
}
]
},
"config_drive": "",
"created": "2013-08-19T08:13:18Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "3d06da1739cd1d26e55ddf60e9a98c0a5f5330b7d16207c3fadb60fa",
"id": "5a271996-ec25-4ea1-a725-1472517b2aed",
"image": {
"id": "f30de903-6491-4683-992b-67294337d02a",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/f30de903-6491-4683-992b-67294337d02a",
"rel": "bookmark"
}
]
},
"key_name": null,
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/5a271996-ec25-4ea1-a725-1472517b2aed",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/5a271996-ec25-4ea1-a725-1472517b2aed",
"rel": "bookmark"
}
],
"metadata": {},
"name": "test1",
"progress": 0,
"security_groups": [
{
"name": "default"
}
],
"status": "ACTIVE",
"tenant_id": "51f084cf981b4e28a9909f9f77313ecc",
"updated": "2013-08-19T08:50:10Z",
"user_id": "5eaf859febff4d76be6187966a4ba6ac"
},
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-SRV-ATTR:host": "grizzly-compute",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "grizzly-compute.hengtiansoft.com",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000004",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"net_proj_one": [
{
"OS-EXT-IPS:type": "fixed",
"addr": "50.50.1.6",
"version": 4
}
]
},
"config_drive": "",
"created": "2013-08-19T08:04:01Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "3d06da1739cd1d26e55ddf60e9a98c0a5f5330b7d16207c3fadb60fa",
"id": "29cb9865-baec-44d4-8285-12bf9a2f5fd6",
"image": {
"id": "f30de903-6491-4683-992b-67294337d02a",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/f30de903-6491-4683-992b-67294337d02a",
"rel": "bookmark"
}
]
},
"key_name": null,
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/29cb9865-baec-44d4-8285-12bf9a2f5fd6",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/29cb9865-baec-44d4-8285-12bf9a2f5fd6",
"rel": "bookmark"
}
],
"metadata": {},
"name": "test3",
"progress": 0,
"security_groups": [
{
"name": "default"
}
],
"status": "ACTIVE",
"tenant_id": "51f084cf981b4e28a9909f9f77313ecc",
"updated": "2013-08-19T08:50:04Z",
"user_id": "5eaf859febff4d76be6187966a4ba6ac"
},
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-SRV-ATTR:host": "grizzly-compute",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "grizzly-compute.hengtiansoft.com",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000003",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"net_proj_one": [
{
"OS-EXT-IPS:type": "fixed",
"addr": "50.50.1.5",
"version": 4
}
]
},
"config_drive": "",
"created": "2013-08-19T07:39:45Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "3d06da1739cd1d26e55ddf60e9a98c0a5f5330b7d16207c3fadb60fa",
"id": "4430f9c3-a192-4d2a-8361-9259e1b3c2a3",
"image": {
"id": "2c1e5627-07a0-4a7e-9fde-1e91a8f06085",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/2c1e5627-07a0-4a7e-9fde-1e91a8f06085",
"rel": "bookmark"
}
]
},
"key_name": null,
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/4430f9c3-a192-4d2a-8361-9259e1b3c2a3",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/4430f9c3-a192-4d2a-8361-9259e1b3c2a3",
"rel": "bookmark"
}
],
"metadata": {},
"name": "test2",
"progress": 0,
"security_groups": [
{
"name": "default"
}
],
"status": "ACTIVE",
"tenant_id": "51f084cf981b4e28a9909f9f77313ecc",
"updated": "2013-08-19T08:50:00Z",
"user_id": "5eaf859febff4d76be6187966a4ba6ac"
},
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-SRV-ATTR:host": "grizzly-compute",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "grizzly-compute.hengtiansoft.com",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000002",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"net_proj_one": [
{
"OS-EXT-IPS:type": "fixed",
"addr": "50.50.1.4",
"version": 4
},
{
"OS-EXT-IPS:type": "floating",
"addr": "172.16.7.104",
"version": 4
}
]
},
"config_drive": "",
"created": "2013-08-19T05:54:48Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "3d06da1739cd1d26e55ddf60e9a98c0a5f5330b7d16207c3fadb60fa",
"id": "a183f10a-9a20-41a2-b693-f1a94cfa1554",
"image": {
"id": "67488e39-2aef-4b8c-bccc-ab97f5c930f6",
"links": [
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/67488e39-2aef-4b8c-bccc-ab97f5c930f6",
"rel": "bookmark"
}
]
},
"key_name": null,
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/a183f10a-9a20-41a2-b693-f1a94cfa1554",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/a183f10a-9a20-41a2-b693-f1a94cfa1554",
"rel": "bookmark"
}
],
"metadata": {},
"name": "cacti",
"progress": 0,
"security_groups": [
{
"name": "default"
}
],
"status": "ACTIVE",
"tenant_id": "51f084cf981b4e28a9909f9f77313ecc",
"updated": "2013-08-19T08:51:08Z",
"user_id": "5eaf859febff4d76be6187966a4ba6ac"
}
]
}
暂停一台虚拟机:
curl -X POST -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/bef3d87c-bd18-4b6a-abfd-65fda7b523ae/action -d '{"pause": null}' -H 'Content-type:application/json'
Unpause一台虚拟机:
curl -X POST -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/bef3d87c-bd18-4b6a-abfd-65fda7b523ae/action -d '{"unpause": null}' -H 'Content-type:application/json'
创建一台虚拟机:
curl -X POST -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers -d '{"server":{"flavorRef":"http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1","imageRef":"http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/b2115dd6-cb34-4e02-a5da-4e5a49aebd6b","name":"test_api_create"}}' -H 'Content-type:application/json'
返回数据:
{"server": {"security_groups": [{"name": "default"}], "OS-DCF:diskConfig": "MANUAL", "id": "dddc0d48-0180-4e22-bd04-014d96912443", "links": [{"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/dddc0d48-0180-4e22-bd04-014d96912443", "rel": "self"}, {"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/servers/dddc0d48-0180-4e22-bd04-014d96912443", "rel": "bookmark"}], "adminPass": "NaN9kr8kFZEC"}}
列出image列表
curl -X GET -H "X-Auth-Token: $token_id" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/images
返回数据:
{
"images": [
{
"id": "4e52de01-f879-45ad-95ea-8ed36c46fe20",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/images/4e52de01-f879-45ad-95ea-8ed36c46fe20",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/4e52de01-f879-45ad-95ea-8ed36c46fe20",
"rel": "bookmark"
},
{
"href": "http://172.16.7.220:9292/51f084cf981b4e28a9909f9f77313ecc/images/4e52de01-f879-45ad-95ea-8ed36c46fe20",
"rel": "alternate",
"type": "application/vnd.openstack.image"
}
],
"name": "cirror-32"
},
{
"id": "f30de903-6491-4683-992b-67294337d02a",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/images/f30de903-6491-4683-992b-67294337d02a",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/f30de903-6491-4683-992b-67294337d02a",
"rel": "bookmark"
},
{
"href": "http://172.16.7.220:9292/51f084cf981b4e28a9909f9f77313ecc/images/f30de903-6491-4683-992b-67294337d02a",
"rel": "alternate",
"type": "application/vnd.openstack.image"
}
],
"name": "instance-snmp"
},
{
"id": "2c1e5627-07a0-4a7e-9fde-1e91a8f06085",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/images/2c1e5627-07a0-4a7e-9fde-1e91a8f06085",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/2c1e5627-07a0-4a7e-9fde-1e91a8f06085",
"rel": "bookmark"
},
{
"href": "http://172.16.7.220:9292/51f084cf981b4e28a9909f9f77313ecc/images/2c1e5627-07a0-4a7e-9fde-1e91a8f06085",
"rel": "alternate",
"type": "application/vnd.openstack.image"
}
],
"name": "snmptemplate"
},
{
"id": "67488e39-2aef-4b8c-bccc-ab97f5c930f6",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/images/67488e39-2aef-4b8c-bccc-ab97f5c930f6",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/67488e39-2aef-4b8c-bccc-ab97f5c930f6",
"rel": "bookmark"
},
{
"href": "http://172.16.7.220:9292/51f084cf981b4e28a9909f9f77313ecc/images/67488e39-2aef-4b8c-bccc-ab97f5c930f6",
"rel": "alternate",
"type": "application/vnd.openstack.image"
}
],
"name": "cacti"
},
{
"id": "b2115dd6-cb34-4e02-a5da-4e5a49aebd6b",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/images/b2115dd6-cb34-4e02-a5da-4e5a49aebd6b",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/images/b2115dd6-cb34-4e02-a5da-4e5a49aebd6b",
"rel": "bookmark"
},
{
"href": "http://172.16.7.220:9292/51f084cf981b4e28a9909f9f77313ecc/images/b2115dd6-cb34-4e02-a5da-4e5a49aebd6b",
"rel": "alternate",
"type": "application/vnd.openstack.image"
}
],
"name": "myFirstImage"
}
]
}
列出flavor列表:
curl -X GET -H "X-Auth-Token: $token_id" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/flavors
返回数据:
{
"flavors": [
{
"id": "1",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/1",
"rel": "bookmark"
}
],
"name": "m1.tiny"
},
{
"id": "2",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/flavors/2",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/2",
"rel": "bookmark"
}
],
"name": "m1.small"
},
{
"id": "3",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/flavors/3",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/3",
"rel": "bookmark"
}
],
"name": "m1.medium"
},
{
"id": "4",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/flavors/4",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/4",
"rel": "bookmark"
}
],
"name": "m1.large"
},
{
"id": "5",
"links": [
{
"href": "http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/flavors/5",
"rel": "self"
},
{
"href": "http://172.16.7.220:8774/51f084cf981b4e28a9909f9f77313ecc/flavors/5",
"rel": "bookmark"
}
],
"name": "m1.xlarge"
}
]
}
删除一台虚拟机:
curl -X DELETE -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/dddc0d48-0180-4e22-bd04-014d96912443
重启一台虚拟机:(分为2种类型的重启一种是SOFT一种是HARD---修改type的值就可以了)
curl -X POST -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/1abef5a7-abed-46a9-a5cb-f6923bd1627a/action -d '{"reboot":{"type":"SOFT"}}' -H 'Content-type:application/json'
挂起一台虚拟机:
curl -X POST -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/bef3d87c-bd18-4b6a-abfd-65fda7b523ae/action -d '{"suspend": null}' -H 'Content-type:application/json'
唤醒一台虚拟机:
curl -X POST -H "X-Auth-Token: $token" http://172.16.7.220:8774/v2/51f084cf981b4e28a9909f9f77313ecc/servers/bef3d87c-bd18-4b6a-abfd-65fda7b523ae/action -d '{"resume": null}' -H 'Content-type:application/json'
以上只是我实验用的api,openstack各个组件还有很多API,需要了解可以去openstack官网上的文档去寻找