Files
python-neutronclient/doc/source/usage/library.rst
Hirofumi Ichihara 65118c09eb Add wrapper classes for return-request-id-to-caller
Added wrapper classes which are inherited from base data types tuple, dict
and str. Each of these wrapper classes contain a 'request_ids' attribute
which is populated with a 'x-openstack-request-id' received in a header
from a response body.

This change is required to return 'request_id' from client to log
request_id mappings of cross projects[1].

[1]: http://specs.openstack.org/openstack/openstack-specs/specs/return-request-id.html

Change-Id: I55fcba61c4efb308f575e95e154aba23e5dd5245
Implements: blueprint return-request-id-to-caller
2016-02-26 16:16:55 +09:00

2.4 KiB

neutronclient Python API

Basic Usage

First create a client instance.

>>> from neutronclient.v2_0 import client
>>> username='adminUser'
>>> password='secretword'
>>> tenant_name='openstackDemo'
>>> auth_url='http://192.168.206.130:5000/v2.0'
>>> neutron = client.Client(username=username,
...                         password=password,
...                         tenant_name=tenant_name,
...                         auth_url=auth_url)

Now you can call various methods on the client instance.

>>> network = {'name': 'mynetwork', 'admin_state_up': True}
>>> neutron.create_network({'network':network})
>>> networks = neutron.list_networks(name='mynetwork')
>>> print networks
>>> network_id = networks['networks'][0]['id']
>>> neutron.delete_network(network_id)

Alternatively, you can create a client instance using an auth token and a service endpoint URL directly.

>>> from neutronclient.v2_0 import client
>>> neutron = client.Client(endpoint_url='http://192.168.206.130:9696/',
...                         token='d3f9226f27774f338019aa2611112ef6')

You can get X-Openstack-Request-Id as request_ids from the result.

>>> network = {'name': 'mynetwork', 'admin_state_up': True}
>>> neutron.create_network({'network':network})
>>> networks = neutron.list_networks(name='mynetwork')
>>> print networks.request_ids
['req-978a0160-7ab0-44f0-8a93-08e9a4e785fa']