为什么80%的码农都做不了架构师?>>>   

感谢朋友支持本博客,欢迎共同探讨交流,由于能力和时间有限,错误之处在所难免,欢迎指正!
如果转载,请保留作者信息。
博客地址:http://blog.csdn.net/qq_21398167

原博文地址:http://blog.csdn.net/qq_21398167/article/details/46531193

import sys

import time
 import keystoneclient.v2_0.client as keystoneclient
 import novaclient.v1_1.client as novaclient
 import neutronclient.v2_0.client as neutronclient
 from credentials import *
 
 
 '''
     Creates a network and a COUNT of instances
     using the user / project configured in stackrc file  
 '''
 
 
 INSTANCE_NAME = 'fiva'
 NETWORK_NAME='route-66'
 SUBNET_CIDR='10.2.33.0/24'
 INSTANCE_COUNT = 3
 
 
 kcreds = get_keystone_creds()
 
 
 print "Connecting to keystone"
 keystone = keystoneclient.Client(**kcreds)
 tokenlen=len(keystone.auth_token)
 print keystone.auth_token[0:20] + "..." + keystone.auth_token[tokenlen-20:tokenlen]
 
 
 ncreds = get_nova_creds()
 nova = novaclient.Client(**ncreds)
 
 
 flavors = nova.flavors.list(is_public=True)
 print flavors
 
 
 images = nova.images.list(detailed=False)
 print images  
 
 
 # get networks from quantum
 print "Find or create network..."
 network_url = keystone.service_catalog.url_for(service_type='network')
 neutron = neutronclient.Client(endpoint_url=network_url, token=keystone.auth_token)
 networks = neutron.list_networks()['networks']
 print "Networks: "
 print [(nw['name'],nw['id'])for nw in networks]

net = None
 net_id = None
 networks =  neutron.list_networks(name=NETWORK_NAME)['networks']
 if len(networks)>0 and networks[0]['name'] == NETWORK_NAME :  
     net_id = networks[0]['id']
     print "Network found ", NETWORK_NAME, net_id
 else:
     net = neutron.create_network({'network':  
               {'name': NETWORK_NAME,'admin_state_up': True} })
     print "Created network ", net
     net_id = net['network']['id']
     sub = neutron.create_subnet({'subnet': {
               'name': 'subnet',
               'network_id': net_id,
               'ip_version': 4,
               'cidr': SUBNET_CIDR
               }  
           })
     print "Created subnet ", sub
 
 
 print "List instances: "
 # check what we get so far for instances
 instances = nova.servers.list()
 
 
 for instance in instances:
     print 'name: ', instance.name
     print 'host id: ', instance.hostId
 
 
 
 
 print "Creating instances: "
 instance = nova.servers.create(INSTANCE_NAME, images[0], flavors[0]
                 # The actual number will be based on the quota.  
                 # see http://www.gossamer-threads.com/lists/openstack/dev/17629
                 ,min_count=1, max_count=INSTANCE_COUNT
                 # if nics not specified, will connect to all project networks
                 ,nics=[{'net-id': net_id}]
           )
 
 # Poll at 5 second intervals, until the status is no longer 'BUILD'
 status = instance.status
 sys.stdout.write('Building...')
 while status == 'BUILD':
     time.sleep(1)
     sys.stdout.write(".")
     sys.stdout.flush()
     # Retrieve the instance again so the status field updates
     instance = nova.servers.get(instance.id)
     status = instance.status
 
 
 print "status: %s" % status

转载于:https://my.oschina.net/shadai/blog/698966

《openstack-nova》use-novaclient 创建虚拟机(createvms.py)相关推荐

  1. OpenStack 创建虚拟机错误:Exceeded maximum number of retries. Exhausted all hosts available for retrying bui

    错误 Ubuntu 20.04 下手动安装 OpenStack Xena 版 在创建虚拟机的时候总是失败 openstack server create --flavor m1.nano --imag ...

  2. openstack之创建虚拟机

    1.创建网络和子网 [root@controller ~]# source admin-openrc.sh [root@controller ~]# neutron net-create flat - ...

  3. nova创建虚拟机源码分析系列之六 api入口create方法

    openstack 版本:Newton 注:博文图片采用了很多大牛博客图片,仅作为总结学习,非商用. 该图全面的说明了nova创建虚机的过程,从逻辑的角度清晰的描述了前端请求创建虚拟机之后发生的一系列 ...

  4. nova 创建虚拟机流程

    1   Nova创建虚机流程 Openstack创建虚拟机的整个流程如图1所示.前端horizon发送创建虚机的请求之后,novaapi接收请求,并作处理,详见1.1节.注:Nova schedule ...

  5. Openstack Nova 源码分析 — 使用 VCDriver 创建 VMware Instance

    目录 目录 前言 流程图 nova-compute vCenter 前言 在上一篇 Openstack Nova 源码分析 - Create instances (nova-conductor阶段) ...

  6. openstack从iso创建虚拟机

    前言 .iso是电脑上光盘镜像(CD Mirror)的存储格式之一,因为其是根据ISO-9660有关CD-ROM文件系统标准存储的文件,所以通常在电脑中以后缀.iso命名,俗称iso镜像文件. ope ...

  7. 用OpenStack界面轻松创建虚拟机的你,看得懂虚拟机启动的这24个参数么?

    用OpenStack界面轻松创建虚拟机的你,看得懂虚拟机启动的这24个参数么? 看这篇文章之前,保证看过以下文章: 我是虚拟机内核我困惑?! Qemu,KVM,Virsh傻傻的分不清 裸用KVM创建虚 ...

  8. Nova创建虚拟机流程解读

    一 介绍 创建一个虚拟机至少需要指定的参数有3个:虚拟机名字,镜像,Flavor.执行"nova image-list"命令可以看到目前可用的虚拟机镜像. 命令执行结果如下: [r ...

  9. openstack nova 源码分析3-nova目录下的service.py

    nova下的service.py的源码,今天阅读之后 直接就把我理解的以注释的形式添加到了源码中,有些地方不好或者是错了,希望大家帮我指出! import inspect import os impo ...

  10. openstack nova 源码分析4-nova目录下的driver.py

    还是有许多地方可能错了 希望大婶们 看见 给予意见 ! 这个文件位于\nova\virt,是一个底层的driver.py,源代码如下(和以前一样添加了些注释,另外把我 觉得比较重要的computerD ...

最新文章

  1. 计算机二级公共基础知识证书,计算机二级公共基础知识
  2. 代码详解:最全面的卷积神经网络介绍,都在这里了
  3. 四川网络推广介绍什么样的网站架构更能吸引蜘蛛爬行抓取?
  4. UA MATH563 概率论的数学基础1 概率空间3 概率测度
  5. 2021年CISCN初赛re
  6. 一个创业者的妥协与希望
  7. php mssql 新 id,MSSQL获取当前插入数据的id
  8. Java基础篇:什么是异常,异常处理的基础是什么?
  9. 2021年中国研究生数学建模竞赛B题参考思路
  10. 如何用计算机应用于中医方剂,方剂“组方配伍网络”分析方法研究——以名老中医门诊处方数据为例...
  11. SQLite数据库导出Excel教程
  12. 银行争夺又一万亿市场:汽车金融
  13. 给大家分享一篇 tkinter python(图形开发界面)
  14. php开发桌面应用程序_使用PHP开发跨平台桌面应用程序的3种方法
  15. SqueezeNet: Alexnet-level accuracy whith 50x Fewer Parameters And 0.5MB Model Size
  16. 沧小海读《图解TCP/IP》笔记——第六章 TCP与UDP
  17. python 进程生命周期_计算客户生命周期价值的python解决方案
  18. 如果你也被pyinstaller折磨,建议阅读,pyinstaller打包教程。
  19. modbus tcp通讯modbus4j使用说明
  20. 无锡会计计算机培训,无锡会计电脑账实操培训

热门文章

  1. 如何学习才能成为优秀的Web前端开发工程师?
  2. C++基础教程之数组
  3. C++学到什么程度才算是精通?
  4. win32截屏并rgb24转yuv420
  5. win10调整分区后盘符不见的文件怎样找回
  6. 基于Swoole和beanstalkd实现多进程处理消息队列。
  7. 怎么把AI文件导入到PS里面
  8. how bootstrap fit into our website design?
  9. Camel In Action 读书笔记 (8)
  10. Syntaxhighligher 使用中的一些问题