[root@controller ~]# cat vm.py
import requests
import json
headers = {"a":"b"}
body = {
"auth": {
"identity": {
"methods": ['password'],
"password": {
"user": {
"domain": {
"name": "demo"
},
"name": "admin",
"password": "000000"
}
}
},
"scope": {
"project": {
"domain": {
"name": "demo"
},
"name": "admin"
}
}
}
}
headers["X-Auth-Token"] = requests.post("http://192.168.100.10:5000/v3/auth/tokens",headers=headers,json=body).headers["X-Subject-Token"]
data = {
"server": {
"name": "vm",
"imageRef": "8f1036fe-ce55-480d-9215-d57ccc527ccf",
"flavorRef": "666",
"networks": [{
"uuid": "ca58a9d7-54e9-4cc5-9e48-d90b47f16b1a"
}],
"security_groups": [
{
"name": "default"
}
]
}
}
requests.post("http://192.168.100.10:8774/v2.1/servers",headers=headers,json=data).json()
print('云主机创建成功')
openstack调用api创建云主机
最新推荐文章于 2024-09-11 13:41:17 发布
该Python脚本通过发送POST请求到OpenStack的认证端点获取授权令牌,然后利用该令牌创建一个新的云主机。请求中包含了身份验证信息(用户名、密码和项目域),以及服务器配置如名称、镜像ID、flavorID、网络UUID和安全组。
摘要由CSDN通过智能技术生成