清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#coding:utf-8 from novaclient.v2.client import Client from novaclient import utils username='admin' password='admin_pass' tenant_name='admin' auth_url='http://controller:5000/v2.0' nvclient = Client(username, password, tenant_name, auth_url) def server_list(): print nvclient.servers.list() def server_create(): kwargs=dict( name='server_name', image=utils.find_resource(nvclient.images,'cirros-0.3.3-x86_64'), flavor=utils.find_resource(nvclient.flavors,'1'), meta=dict(meta_data1='meata_data1_value'), userdata="echo hello_world > /tmp/hello.txt", reservation_id=None, availability_zone='nova', nics=[{'net-id':'9043ef57-c0ee-4c26-9765-8feba66ea777'}], #TODO 后面加上测试 block_device_mapping_v2=None, ) print nvclient.servers.create(**kwargs) if __name__=='__main__': server_create()