nova 通过 python curl 创建虚拟机---keystone v3

#! /bin/python
#coding=utf-8

import urllib2
import json
import requests

# token
post_url = 'http://10.249.104.81:35357/v3/auth/tokens'
postData = {
    "auth": {
        "identity": {
            "methods": [
                "password"
            ],
            "password": {
                "user": {
                        "domain":{
                                "name":"default"
                        },
                        "name": "admin",
                        "password": "Qihoo360"
                }
            }
        },
        "scope": {
            "project": {
                "domain":{
                        "name":"default"
                },
                "name": "admin"
            }
        }
    }
}

data = json.dumps(postData)
req = urllib2.Request(post_url)
req.add_header('Content-Type','application/json')
response = urllib2.urlopen(req, data=data)

header = response.headers
token_id = header['X-Subject-Token']
print token_id

post_url = 'http://10.249.104.81:8774/v2/7fc59737268940cd950e0b5b4faaa2e7/servers'

DICT_CREATE_INSTANCE = {
    "server": {
        "name": "test-test",
        "imageRef": "29d2631a-9002-4368-a1f0-48804442c52b",
        "flavorRef": "m1",
        "networks": [{
            "uuid" : "23f48b65-4174-4fc2-8512-34004563ba0b"
        }],
    }
}

data = json.dumps(DICT_CREATE_INSTANCE)
req = urllib2.Request(post_url)
req.add_header('Content-Type','application/json')
req.add_header('X-Auth-Token',token_id)
response = urllib2.urlopen(req, data=data)
response.read()
print data

 

posted @ 2020-07-24 15:14  salami_china  阅读(179)  评论(0编辑  收藏  举报