dc10f44128
The current python binding examples have prompts of python interactive mode, but these prompts make it difficult to copy-and-paste the examples. This commit removes them. Change-Id: Ia5d35fbb585ed0d0d11c8d035196981e9dd46785
3.4 KiB
3.4 KiB
neutronclient Python API
Basic Usage
First create a client instance using a keystoneauth Session. For more information on this keystoneauth API, see Using Sessions.
from keystoneauth1 import identity
from keystoneauth1 import session
from neutronclient.v2_0 import client
='username'
username='password'
password='demo'
project_name='default'
project_domain_id='default'
user_domain_id='http://auth.example.com:5000/v3'
auth_url= identity.Password(auth_url=auth_url,
auth =username,
username=password,
password=project_name,
project_name=project_domain_id,
project_domain_id=user_domain_id)
user_domain_id= session.Session(auth=auth)
sess = client.Client(session=sess) neutron
If you are using Identity v2.0 API (DEPRECATED), create an auth plugin using the appropriate parameters and keystoneauth1.identity will handle Identity API version discovery. Then you can create a Session and a Neutronclient just like the previous example.
= identity.Password(auth_url=auth_url,
auth =username,
username=password,
password=project_name)
project_name# create a Session and a Neutronclient
Now you can call various methods on the client instance.
= {'name': 'mynetwork', 'admin_state_up': True}
network 'network':network})
neutron.create_network({= neutron.list_networks(name='mynetwork')
networks print networks
= networks['networks'][0]['id']
network_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
= client.Client(endpoint_url='http://192.168.206.130:9696/',
neutron ='d3f9226f27774f338019aa2611112ef6') token
You can get X-Openstack-Request-Id
as
request_ids
from the result.
= {'name': 'mynetwork', 'admin_state_up': True}
network 'network':network})
neutron.create_network({= neutron.list_networks(name='mynetwork')
networks print networks.request_ids
# -> ['req-978a0160-7ab0-44f0-8a93-08e9a4e785fa']