@@ -20,6 +20,8 @@ https://docs.openstack.org/openstacksdk/latest/contributor/history.html
20
20
Getting started
21
21
---------------
22
22
23
+ .. rubric :: Authentication and connection management
24
+
23
25
openstacksdk aims to talk to any OpenStack cloud. To do this, it requires a
24
26
configuration file. openstacksdk favours ``clouds.yaml `` files, but can also
25
27
use environment variables. The ``clouds.yaml `` file should be provided by your
@@ -38,29 +40,43 @@ cloud provider or deployment tooling. An example:
38
40
39
41
openstacksdk will look for ``clouds.yaml `` files in the following locations:
40
42
43
+ * If set, the path indicated by the ``OS_CLIENT_CONFIG_FILE `` environment
44
+ variable
41
45
* ``. `` (the current directory)
42
46
* ``$HOME/.config/openstack ``
43
47
* ``/etc/openstack ``
44
48
45
- openstacksdk consists of three layers. Most users will make use of the *proxy *
46
- layer. Using the above ``clouds.yaml ``, consider listing servers:
49
+ You can create a connection using the ``openstack.connect `` function. The cloud
50
+ name can be either passed directly to this function or specified using the
51
+ ``OS_CLOUD `` environment variable. If you don't have a ``clouds.yaml `` file and
52
+ instead use environment variables for configuration then you can use the
53
+ special ``envvars `` cloud name to load configuration from the environment. For
54
+ example:
47
55
48
56
.. code-block :: python
49
57
50
58
import openstack
51
59
52
- # Initialize and turn on debug logging
53
- openstack.enable_logging( debug = True )
60
+ # Initialize connection from a clouds.yaml by passing a cloud name
61
+ conn_from_cloud_name = openstack.connect( cloud = ' mordred ' )
54
62
55
- # Initialize connection
56
- conn = openstack.connect(cloud = ' mordred ' )
63
+ # Initialize connection from a clouds.yaml using the OS_CLOUD envvar
64
+ conn_from_os_cloud = openstack.connect()
57
65
58
- # List the servers
59
- for server in conn.compute.servers():
60
- print (server.to_dict())
66
+ # Initialize connection from environment variables
67
+ conn_from_env_vars = openstack.connect(cloud = ' envvars' )
68
+
69
+ .. note ::
61
70
62
- openstacksdk also contains a higher-level *cloud * layer based on logical
63
- operations:
71
+ How this is all achieved is described in more detail `below
72
+ <openstack.config> `__.
73
+
74
+ .. rubric :: The cloud layer
75
+
76
+ openstacksdk consists of four layers which all build on top of each other. The
77
+ highest level layer is the *cloud * layer. Cloud layer methods are available via
78
+ the top level ``Connection `` object returned by ``openstack.connect ``. For
79
+ example:
64
80
65
81
.. code-block :: python
66
82
@@ -76,8 +92,10 @@ operations:
76
92
for server in conn.list_servers():
77
93
print (server.to_dict())
78
94
79
- The benefit of this layer is mostly seen in more complicated operations that
80
- take multiple steps and where the steps vary across providers. For example:
95
+ The cloud layer is based on logical operations that can potentially touch
96
+ multiple services. The benefit of this layer is mostly seen in more complicated
97
+ operations that take multiple steps and where the steps vary across providers.
98
+ For example:
81
99
82
100
.. code-block :: python
83
101
@@ -101,9 +119,38 @@ take multiple steps and where the steps vary across providers. For example:
101
119
conn.create_server(
102
120
' my-server' , image = image, flavor = flavor, wait = True , auto_ip = True )
103
121
104
- Finally, there is the low-level *resource * layer. This provides support for the
105
- basic CRUD operations supported by REST APIs and is the base building block for
106
- the other layers. You typically will not need to use this directly:
122
+ .. rubric :: The proxy layer
123
+
124
+ The next layer is the *proxy * layer. Most users will make use of this layer.
125
+ The proxy layer is service-specific, so methods will be available under
126
+ service-specific connection attributes of the ``Connection `` object such as
127
+ ``compute ``, ``block_storage ``, ``image `` etc. For example:
128
+
129
+ .. code-block :: python
130
+
131
+ import openstack
132
+
133
+ # Initialize and turn on debug logging
134
+ openstack.enable_logging(debug = True )
135
+
136
+ # Initialize connection
137
+ conn = openstack.connect(cloud = ' mordred' )
138
+
139
+ # List the servers
140
+ for server in conn.compute.servers():
141
+ print (server.to_dict())
142
+
143
+ .. note ::
144
+
145
+ A list of supported services is given `below <supported-services >`__.
146
+
147
+ .. rubric :: The resource layer
148
+
149
+ Below this there is the *resource * layer. This provides support for the basic
150
+ CRUD operations supported by REST APIs and is the base building block for the
151
+ other layers. You typically will not need to use this directly but it can be
152
+ helpful for operations where you already have a ``Resource `` object to hand.
153
+ For example:
107
154
108
155
.. code-block :: python
109
156
@@ -121,6 +168,34 @@ the other layers. You typically will not need to use this directly:
121
168
for server in openstack.compute.v2.server.Server.list(session = conn.compute):
122
169
print (server.to_dict())
123
170
171
+ .. rubric :: The raw HTTP layer
172
+
173
+ Finally, there is the *raw HTTP * layer. This exposes raw HTTP semantics and
174
+ is effectively a wrapper around the `requests `__ API with added smarts to
175
+ handle stuff like authentication and version management. As such, you can use
176
+ the ``requests `` API methods you know and love, like ``get ``, ``post `` and
177
+ ``put ``, and expect to receive a ``requests.Response `` object in response
178
+ (unlike the other layers, which mostly all return objects that subclass
179
+ ``openstack.resource.Resource ``). Like the *resource * layer, you will typically
180
+ not need to use this directly but it can be helpful to interact with APIs that
181
+ have not or will not be supported by openstacksdk. For example:
182
+
183
+ .. code-block :: python
184
+
185
+ import openstack
186
+
187
+ # Initialize and turn on debug logging
188
+ openstack.enable_logging(debug = True )
189
+
190
+ # Initialize connection
191
+ conn = openstack.connect(cloud = ' mordred' )
192
+
193
+ # List servers
194
+ for server in openstack.compute.get(' /servers' ).json():
195
+ print (server)
196
+
197
+ .. __ : https://requests.readthedocs.io/en/latest/
198
+
124
199
.. _openstack.config :
125
200
126
201
Configuration
@@ -145,14 +220,14 @@ environment by running ``openstack.config.loader``. For example:
145
220
146
221
More information at https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html
147
222
223
+ .. _supported-services :
224
+
148
225
Supported services
149
226
------------------
150
227
151
228
The following services are currently supported. A full list of all available
152
229
OpenStack service can be found in the `Project Navigator `__.
153
230
154
- .. __ : https://www.openstack.org/software/project-navigator/openstack-components#openstack-services
155
-
156
231
.. note ::
157
232
158
233
Support here does not guarantee full-support for all APIs. It simply means
@@ -302,6 +377,8 @@ OpenStack service can be found in the `Project Navigator`__.
302
377
- ✔
303
378
- ✔ (``openstack.instance_ha ``)
304
379
380
+ .. __ : https://www.openstack.org/software/project-navigator/openstack-components#openstack-services
381
+
305
382
Links
306
383
-----
307
384
0 commit comments