代码如下:
#!/usr/bin/python
from keystoneclient.auth.identity import v3
from keystoneclient import session
from keystoneclient.v3 import client as keystoneapi
from novaclient import client as novapi
auth_url = ''
username = 'admin'
user_domain_name = 'Default'
project_name = 'admin'
project_domain_name = 'Default'
password = 'admin'
auth = v3.Password(auth_url=auth_url,
username=username,
password=password,
project_name=project_name,
project_domain_name=project_domain_name,
user_domain_name=user_domain_name)
sess = session.Session(auth=auth)
keystone = keystoneapi.Client(session=sess)
#print keystone.projects.list()
nova = novapi.Client(2, session=keystone.session)
#nova.images.list() 列出所有镜像
image = nova.images.find(name='cirros-0.3.4-x86_64-uec')
#nova.flavors.list() 列出所有主机类型
flavor = nova.flavors.find(name='m1.tiny')
#nova.networks.list() 列出所有网络
network = nova.networks.find(label='ext')
#创建虚拟机
server = nova.servers.create(name="vm_api", image=image, flavor=flavor,nics=[{'net-id':network.id}])
print server
http://www.cnblogs.com/juandx/p/4953191.html
阅读(2877) | 评论(0) | 转发(0) |