Skip to content

Instantly share code, notes, and snippets.

@hackerain
Last active August 29, 2015 14:00
Show Gist options
  • Save hackerain/11390974 to your computer and use it in GitHub Desktop.
Save hackerain/11390974 to your computer and use it in GitHub Desktop.
在某一个计算节点上同时创建多台虚拟机
通过availability_zone参数可以将虚拟机强制调度到指定的计算节点,但是默认的该参数只能由admin使用,若要普通用户使用,在nova的policy.json中,将"compute:create:forced_host": "is_admin:True",这条规则改为"compute:create:forced_host": ""
命令行:
nova boot --image c796de54-25f8-405e-afdd-e03003a9e62a --nic net-id=ba05e057-1eb8-4cb2-af58-9b99a72df5ed --flavor 2 --availability_zone nova:server-76 vm
API:
1. 首先获得token
POST http://10.1.0.39:35357/v3/auth/tokens
{
"auth":{
"identity": {
"methods": ["password"],
"password": {
"user": {
"domain": {
"id": "7a84434c3283421cac31d98e65ac5d72"
},
"name": "guangyu_7a84434c3283421cac31d98e65ac5d72",
"password": "rachel"
}
}
},
"scope":{
"project": {
"domain": {
"id": "7a84434c3283421cac31d98e65ac5d72"
},
"id": "6366f4fe38f54c3a96c62e90c088490a"
}
}
}
}
返回的token在response的header中。
2. 在server-76上同时创建3台虚拟机:
POST http://10.1.0.39:8774/v2/6366f4fe38f54c3a96c62e90c088490a/servers
header:
X-Auth-Token = e4ddd10f49fa44ceae7791f5b8360dbb
Content-Type = application/json
body:
{
"server":{
"name":"test_slow",
"imageRef":"c796de54-25f8-405e-afdd-e03003a9e62a",
"flavorRef":"c40bf599-a979-4404-8332-5a23f75a66cd",
"max_count":3,
"min_count":3,
"networks":[
{
"uuid":"ba05e057-1eb8-4cb2-af58-9b99a72df5ed"
}
],
"availability_zone": "nova:server-76"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment