2011-02-26 05:04:40 -04:00
|
|
|
The :mod:`novaclient` Python API
|
2015-09-09 14:02:42 +03:00
|
|
|
================================
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-02-26 05:04:40 -04:00
|
|
|
.. module:: novaclient
|
2011-02-08 09:27:22 -04:00
|
|
|
:synopsis: A client for the OpenStack Nova API.
|
2011-08-08 13:20:44 -07:00
|
|
|
|
2011-02-26 05:04:40 -04:00
|
|
|
.. currentmodule:: novaclient
|
2011-01-25 14:01:22 -06:00
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
2013-12-16 14:07:24 +08:00
|
|
|
First create a client instance with your credentials::
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2015-01-30 19:28:38 +01:00
|
|
|
>>> from novaclient import client
|
|
|
|
>>> nova = client.Client(VERSION, USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2015-09-09 14:02:42 +03:00
|
|
|
Here ``VERSION`` can be a string or ``novaclient.api_versions.APIVersion`` obj.
|
|
|
|
If you prefer string value, you can use ``1.1`` (deprecated now), ``2`` or
|
|
|
|
``2.X`` (where X is a microversion).
|
|
|
|
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2015-12-10 13:49:14 -05:00
|
|
|
Alternatively, you can create a client instance using the keystoneauth
|
2014-07-01 16:36:46 +01:00
|
|
|
session API::
|
|
|
|
|
2015-12-10 13:49:14 -05:00
|
|
|
>>> from keystoneauth1 import loading
|
|
|
|
>>> from keystoneauth1 import session
|
2015-01-30 19:28:38 +01:00
|
|
|
>>> from novaclient import client
|
2015-12-10 13:49:14 -05:00
|
|
|
>>> loader = loading.get_plugin_loader('password')
|
2016-03-02 14:21:41 +02:00
|
|
|
>>> auth = loader.load_from_options(auth_url=AUTH_URL,
|
|
|
|
... username=USERNAME,
|
|
|
|
... password=PASSWORD,
|
|
|
|
... project_id=PROJECT_ID)
|
2014-07-01 16:36:46 +01:00
|
|
|
>>> sess = session.Session(auth=auth)
|
|
|
|
>>> nova = client.Client(VERSION, session=sess)
|
|
|
|
|
2015-12-10 13:49:14 -05:00
|
|
|
If you have PROJECT_NAME instead of a PROJECT_ID, use the project_name
|
|
|
|
parameter. Similarly, if your cloud uses keystone v3 and you have a DOMAIN_NAME
|
|
|
|
or DOMAIN_ID, provide it as `user_domain_(name|id)` and if you are using a
|
|
|
|
PROJECT_NAME also provide the domain information as `project_domain_(name|id)`.
|
2014-07-01 16:36:46 +01:00
|
|
|
|
2015-12-10 13:49:14 -05:00
|
|
|
For more information on this keystoneauth API, see `Using Sessions`_.
|
|
|
|
|
|
|
|
.. _Using Sessions: http://docs.openstack.org/developer/keystoneauth/using-sessions.html
|
2014-07-01 16:36:46 +01:00
|
|
|
|
2015-09-09 14:02:42 +03:00
|
|
|
It is also possible to use an instance as a context manager in which case
|
|
|
|
there will be a session kept alive for the duration of the with statement::
|
|
|
|
|
|
|
|
>>> from novaclient import client
|
|
|
|
>>> with client.Client(VERSION, USERNAME, PASSWORD,
|
|
|
|
... PROJECT_ID, AUTH_URL) as nova:
|
|
|
|
... nova.servers.list()
|
|
|
|
... nova.flavors.list()
|
|
|
|
...
|
|
|
|
|
|
|
|
It is also possible to have a permanent (process-long) connection pool,
|
|
|
|
by passing a connection_pool=True::
|
|
|
|
|
|
|
|
>>> from novaclient import client
|
|
|
|
>>> nova = client.Client(VERSION, USERNAME, PASSWORD, PROJECT_ID,
|
|
|
|
... AUTH_URL, connection_pool=True)
|
|
|
|
|
2013-12-16 14:07:24 +08:00
|
|
|
Then call methods on its managers::
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-02-08 09:27:22 -04:00
|
|
|
>>> nova.servers.list()
|
2011-01-25 14:01:22 -06:00
|
|
|
[<Server: buildslave-ubuntu-9.10>]
|
|
|
|
|
2011-02-08 09:27:22 -04:00
|
|
|
>>> nova.flavors.list()
|
2011-01-25 14:01:22 -06:00
|
|
|
[<Flavor: 256 server>,
|
|
|
|
<Flavor: 512 server>,
|
|
|
|
<Flavor: 1GB server>,
|
|
|
|
<Flavor: 2GB server>,
|
|
|
|
<Flavor: 4GB server>,
|
|
|
|
<Flavor: 8GB server>,
|
|
|
|
<Flavor: 15.5GB server>]
|
|
|
|
|
2011-02-08 09:27:22 -04:00
|
|
|
>>> fl = nova.flavors.find(ram=512)
|
|
|
|
>>> nova.servers.create("my-server", flavor=fl)
|
2011-01-25 14:01:22 -06:00
|
|
|
<Server: my-server>
|
|
|
|
|
2015-09-09 14:02:42 +03:00
|
|
|
.. warning:: Direct initialization of ``novaclient.v2.client.Client`` object
|
|
|
|
can cause you to "shoot yourself in the foot". See launchpad bug-report
|
|
|
|
`1493576`_ for more details.
|
|
|
|
|
|
|
|
.. _1493576: https://launchpad.net/bugs/1493576
|
|
|
|
|
|
|
|
|
2013-12-16 14:07:24 +08:00
|
|
|
Reference
|
|
|
|
---------
|
|
|
|
|
2011-01-25 14:01:22 -06:00
|
|
|
For more information, see the reference:
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
2011-08-08 13:20:44 -07:00
|
|
|
|
2011-02-08 09:27:22 -04:00
|
|
|
ref/index
|
2015-02-03 02:32:58 +02:00
|
|
|
ref/v2/index
|