zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    php配置GD库
    Linux 安装 Apache2+php5+gd+freetype2
    gd库
    数组和链表的区别
    python 整数中1出现的次数
    python栈--字符串反转,括号匹配
    Linux基础知识
    操作系统
    后台面试问题
    python 面向对象
  • 原文地址:https://www.cnblogs.com/wangjq19920210/p/13372073.html
Copyright © 2011-2022 走看看