当前位置:天才代写 > tutorial > Python教程 > python 创建openstack云主机

python 创建openstack云主机

2018-05-17 08:00 星期四 所属: Python教程 浏览:466

python">#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()

标签:python

 

    关键字:

天才代写-代写联系方式