Files
python-neutronclient/doc/source/usage/library.rst
Dariusz Smigiel 343e4b186f Update for API bindings
All occurrences of tenant replaced with project (where applicable).

Partially Implements blueprint: keystone-v3

Change-Id: I4919745aa59863f99c7740e730d8cbfd91c2f646
2016-05-26 08:48:18 -05:00

2.4 KiB

neutronclient Python API

Basic Usage

First create a client instance.

>>> from neutronclient.v2_0 import client
>>> username='adminUser'
>>> password='secretword'
>>> project_name='openstackDemo'
>>> auth_url='http://192.168.206.130:5000/v2.0'
>>> neutron = client.Client(username=username,
...                         password=password,
...                         project_name=project_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']