1============
2openstacksdk
3============
4
5openstacksdk is a client library for building applications to work
6with OpenStack clouds. The project aims to provide a consistent and
7complete set of interactions with OpenStack's many services, along with
8complete documentation, examples, and tools.
9
10It also contains an abstraction interface layer. Clouds can do many things, but
11there are probably only about 10 of them that most people care about with any
12regularity. If you want to do complicated things, the per-service oriented
13portions of the SDK are for you. However, if what you want is to be able to
14write an application that talks to any OpenStack cloud regardless of
15configuration, then the Cloud Abstraction layer is for you.
16
17More information about the history of openstacksdk can be found at
18https://docs.openstack.org/openstacksdk/latest/contributor/history.html
19
20Getting started
21---------------
22
23openstacksdk aims to talk to any OpenStack cloud. To do this, it requires a
24configuration file. openstacksdk favours ``clouds.yaml`` files, but can also
25use environment variables. The ``clouds.yaml`` file should be provided by your
26cloud provider or deployment tooling. An example:
27
28.. code-block:: yaml
29
30    clouds:
31      mordred:
32        region_name: Dallas
33        auth:
34          username: 'mordred'
35          password: XXXXXXX
36          project_name: 'demo'
37          auth_url: 'https://identity.example.com'
38
39openstacksdk will look for ``clouds.yaml`` files in the following locations:
40
41* ``.`` (the current directory)
42* ``$HOME/.config/openstack``
43* ``/etc/openstack``
44
45openstacksdk consists of three layers. Most users will make use of the *proxy*
46layer. Using the above ``clouds.yaml``, consider listing servers:
47
48.. code-block:: python
49
50    import openstack
51
52    # Initialize and turn on debug logging
53    openstack.enable_logging(debug=True)
54
55    # Initialize connection
56    conn = openstack.connect(cloud='mordred')
57
58    # List the servers
59    for server in conn.compute.servers():
60        print(server.to_dict())
61
62openstacksdk also contains a higher-level *cloud* layer based on logical
63operations:
64
65.. code-block:: python
66
67    import openstack
68
69    # Initialize and turn on debug logging
70    openstack.enable_logging(debug=True)
71
72    # Initialize connection
73    conn = openstack.connect(cloud='mordred')
74
75    # List the servers
76    for server in conn.list_servers():
77        print(server.to_dict())
78
79The benefit of this layer is mostly seen in more complicated operations that
80take multiple steps and where the steps vary across providers. For example:
81
82.. code-block:: python
83
84    import openstack
85
86    # Initialize and turn on debug logging
87    openstack.enable_logging(debug=True)
88
89    # Initialize connection
90    conn = openstack.connect(cloud='mordred')
91
92    # Upload an image to the cloud
93    image = conn.create_image(
94        'ubuntu-trusty', filename='ubuntu-trusty.qcow2', wait=True)
95
96    # Find a flavor with at least 512M of RAM
97    flavor = conn.get_flavor_by_ram(512)
98
99    # Boot a server, wait for it to boot, and then do whatever is needed
100    # to get a public IP address for it.
101    conn.create_server(
102        'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)
103
104Finally, there is the low-level *resource* layer. This provides support for the
105basic CRUD operations supported by REST APIs and is the base building block for
106the other layers. You typically will not need to use this directly:
107
108.. code-block:: python
109
110    import openstack
111    import openstack.config.loader
112    import openstack.compute.v2.server
113
114    # Initialize and turn on debug logging
115    openstack.enable_logging(debug=True)
116
117    # Initialize connection
118    conn = openstack.connect(cloud='mordred')
119
120    # List the servers
121    for server in openstack.compute.v2.server.Server.list(session=conn.compute):
122        print(server.to_dict())
123
124.. _openstack.config:
125
126Configuration
127-------------
128
129openstacksdk uses the ``openstack.config`` module to parse configuration.
130``openstack.config`` will find cloud configuration for as few as one cloud and
131as many as you want to put in a config file. It will read environment variables
132and config files, and it also contains some vendor specific default values so
133that you don't have to know extra info to use OpenStack
134
135* If you have a config file, you will get the clouds listed in it
136* If you have environment variables, you will get a cloud named `envvars`
137* If you have neither, you will get a cloud named `defaults` with base defaults
138
139You can view the configuration identified by openstacksdk in your current
140environment by running ``openstack.config.loader``. For example:
141
142.. code-block:: bash
143
144   $ python -m openstack.config.loader
145
146More information at https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html
147
148Links
149-----
150
151* `Issue Tracker <https://storyboard.openstack.org/#!/project/openstack/openstacksdk>`_
152* `Code Review <https://review.opendev.org/#/q/status:open+project:openstack/openstacksdk,n,z>`_
153* `Documentation <https://docs.openstack.org/openstacksdk/latest/>`_
154* `PyPI <https://pypi.org/project/openstacksdk/>`_
155* `Mailing list <http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-discuss>`_
156* `Release Notes <https://docs.openstack.org/releasenotes/openstacksdk>`_
157