Skip to content

Commit

Permalink
Fix README example for cloud layer
Browse files Browse the repository at this point in the history
This was showing 'import openstack.cloud' but then using openstack
directly. Fix that.

Then, reorganize a little bit.

Change-Id: Iecb7cd02cc6648c6e78666da0d237fc28643d2ae
  • Loading branch information
emonty committed Aug 1, 2019
1 parent f162b71 commit e702b02
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,47 @@ List servers using objects configured with the ``clouds.yaml`` file:
for server in conn.compute.servers():
print(server.to_dict())
Cloud Layer
===========

``openstacksdk`` contains a higher-level layer based on logical operations.

.. code-block:: python
import openstack
# Initialize and turn on debug logging
openstack.enable_logging(debug=True)
for server in conn.list_servers():
print(server.to_dict())
The benefit is mostly seen in more complicated operations that take multiple
steps and where the steps vary across providers:

.. code-block:: python
import openstack
# Initialize and turn on debug logging
openstack.enable_logging(debug=True)
# Initialize connection
# Cloud configs are read with openstack.config
conn = openstack.connect(cloud='mordred')
# Upload an image to the cloud
image = conn.create_image(
'ubuntu-trusty', filename='ubuntu-trusty.qcow2', wait=True)
# Find a flavor with at least 512M of RAM
flavor = conn.get_flavor_by_ram(512)
# Boot a server, wait for it to boot, and then do whatever is needed
# to get a public ip for it.
conn.create_server(
'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)
openstack.config
================

Expand Down Expand Up @@ -124,34 +165,6 @@ in the following locations:

More information at https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html

openstack.cloud
===============

Create a server using objects configured with the ``clouds.yaml`` file:

.. code-block:: python
import openstack.cloud
# Initialize and turn on debug logging
openstack.enable_logging(debug=True)
# Initialize connection
# Cloud configs are read with openstack.config
conn = openstack.connect(cloud='mordred')
# Upload an image to the cloud
image = conn.create_image(
'ubuntu-trusty', filename='ubuntu-trusty.qcow2', wait=True)
# Find a flavor with at least 512M of RAM
flavor = conn.get_flavor_by_ram(512)
# Boot a server, wait for it to boot, and then do whatever is needed
# to get a public ip for it.
conn.create_server(
'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)
Links
=====

Expand Down

0 comments on commit e702b02

Please sign in to comment.