码迷,mamicode.com
首页 > 编程语言 > 详细

The novaclient Python API

时间:2014-11-09 08:38:02      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   os   sp   for   div   on   cti   

The novaclient Python API

Usage

First create a client instance with your credentials:

>>> from novaclient.client import Client
>>> nova = Client(VERSION, USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)

Here VERSION can be: 1.12 and 3.

Alternatively, you can create a client instance using the keystoneclient session API:

>>> from keystoneclient.auth.identity import v2
>>> from keystoneclient import session
>>> from novaclient.client import Client
>>> auth = v2.Password(auth_url=AUTH_URL,
                       username=USERNAME,
                       password=PASSWORD,
                       tenant_name=PROJECT_ID)
>>> sess = session.Session(auth=auth)
>>> nova = client.Client(VERSION, session=sess)

For more information on this keystoneclient API, see Using Sessions.

Then call methods on its managers:

>>> nova.servers.list()
[<Server: buildslave-ubuntu-9.10>]

>>> nova.flavors.list()
[<Flavor: 256 server>,
 <Flavor: 512 server>,
 <Flavor: 1GB server>,
 <Flavor: 2GB server>,
 <Flavor: 4GB server>,
 <Flavor: 8GB server>,
 <Flavor: 15.5GB server>]

>>> fl = nova.flavors.find(ram=512)
>>> nova.servers.create("my-server", flavor=fl)
<Server: my-server>


Reference

For more information, see the reference:

 

The novaclient Python API

标签:http   io   ar   os   sp   for   div   on   cti   

原文地址:http://www.cnblogs.com/csjsias/p/4084386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!