Debian Codegraph @

doc/source/reference/index.rst

raw
1 ..
2 Licensed under the Apache License, Version 2.0 (the "License"); you may
3 not use this file except in compliance with the License. You may obtain
4 a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 License for the specific language governing permissions and limitations
12 under the License.
13
14
15 Convention for heading levels in Neutron devref:
16 ======= Heading 0 (reserved for the title in a document)
17 ------- Heading 1
18 ~~~~~~~ Heading 2
19 +++++++ Heading 3
20 ''''''' Heading 4
21 (Avoid deeper levels because they do not render well.)
22
23 neutronclient Python API
24 ========================
25
26 Basic Usage
27 -----------
28
29 First create a client instance using a keystoneauth Session. For more
30 information on this keystoneauth API, see `Using Sessions`_.
31
32 .. _Using Sessions: https://docs.openstack.org/keystoneauth/latest/using-sessions.html
33
34 .. code-block:: python
35
36 from keystoneauth1 import identity
37 from keystoneauth1 import session
38 from neutronclient.v2_0 import client
39 username='username'
40 password='password'
41 project_name='demo'
42 project_domain_id='default'
43 user_domain_id='default'
44 auth_url='http://auth.example.com:5000/v3'
45 auth = identity.Password(auth_url=auth_url,
46 username=username,
47 password=password,
48 project_name=project_name,
49 project_domain_id=project_domain_id,
50 user_domain_id=user_domain_id)
51 sess = session.Session(auth=auth)
52 neutron = client.Client(session=sess)
53
54 If you are using Identity v2.0 API (DEPRECATED), create an auth plugin using
55 the appropriate parameters and `keystoneauth1.identity` will handle Identity
56 API version discovery. Then you can create a Session and a Neutronclient just
57 like the previous example.
58
59 .. code-block:: python
60
61 auth = identity.Password(auth_url=auth_url,
62 username=username,
63 password=password,
64 project_name=project_name)
65 # create a Session and a Neutronclient
66
67 Now you can call various methods on the client instance.
68
69 .. code-block:: python
70
71 network = {'name': 'mynetwork', 'admin_state_up': True}
72 neutron.create_network({'network':network})
73 networks = neutron.list_networks(name='mynetwork')
74 print networks
75 network_id = networks['networks'][0]['id']
76 neutron.delete_network(network_id)
77
78 Alternatively, you can create a client instance using an auth token
79 and a service endpoint URL directly.
80
81 .. code-block:: python
82
83 from neutronclient.v2_0 import client
84 neutron = client.Client(endpoint_url='http://192.168.206.130:9696/',
85 token='d3f9226f27774f338019aa2611112ef6')
86
87 You can get ``X-Openstack-Request-Id`` as ``request_ids`` from the result.
88
89 .. code-block:: python
90
91 network = {'name': 'mynetwork', 'admin_state_up': True}
92 neutron.create_network({'network':network})
93 networks = neutron.list_networks(name='mynetwork')
94 print networks.request_ids
95 # -> ['req-978a0160-7ab0-44f0-8a93-08e9a4e785fa']