用pycurl直接认证keystone curl创建虚拟机

来源:互联网 发布:qq for mac版什么意思 编辑:程序博客网 时间:2024/06/08 15:25
#!/usr/bin/python
import json
import pycurl

c = pycurl.Curl()
c.setopt(c.URL, 'http://192.168.1.12:5000/v2.0/tokens')

post_data = {"auth":{"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "password"}}}
postfields = json.dumps(post_data)
c.setopt(c.POSTFIELDS, postfields)
c.setopt(c.HTTPHEADER, ["Content-type: application/json"])
c.perform()

c.close()

---------------

curl创建虚拟机:

获取token_id
curl -d '{"auth":{"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "password"}}}' -H "Content-type: application/json" http://192.168.1.12:5000/v2.0/tokens
获取images
curl -i -H "X-Auth-Token:$toke" http://192.168.1.12:8774/v2/$tenant_id/images
获取flavors
curl -i -H "X-Auth-Token:$toke" http://192.168.1.12:8774/v2/$tenant_id/flavors
获取网络
curl -i -H "X-Auth-Token:$toke" http://192.168.1.12:9696/v2.0/networks
创建虚拟机
curl -i -H "X-Auth-Token:$toke" -H "Content-type: application/json" -d '{"server": {"name": "instance1", "imageRef": $imageRef, "key_name": "", "flavorRef": "1", "networks": [{"uuid":$uuid}],"max_count": 1, "min_count": 1}}'  http://192.168.1.12:8774/v2/$tenant_id/servers

0 0