docs: make the first example easier to understand

The very first example of the usage of shade is easier to understand
if there is also an example of the needed `clouds.yml` file. Without
it, it is unclear what the meaning of the key `mordred` means.

Change-Id: Iad3aba66b0c6344157da30f374e191d01e938b2b
This commit is contained in:
Markus Zoeller 2017-06-16 11:21:41 +02:00
parent c16eef76a7
commit daabd8cb9c

View File

@ -21,25 +21,48 @@ Example
======= =======
Sometimes an example is nice. Sometimes an example is nice.
::
import shade #. Create a ``clouds.yml`` file::
# Initialize and turn on debug logging clouds:
shade.simple_logging(debug=True) mordred:
region_name: RegionOne
auth:
username: 'mordred'
password: XXXXXXX
project_name: 'shade'
auth_url: 'https://montytaylor-sjc.openstack.blueboxgrid.com:5001/v2.0'
# Initialize cloud Please note: *os-client-config* will look for a file called ``clouds.yaml``
# Cloud configs are read with os-client-config in the following locations:
cloud = shade.openstack_cloud(cloud='mordred')
# Upload an image to the cloud * Current Directory
image = cloud.create_image( * ``~/.config/openstack``
'ubuntu-trusty', filename='ubuntu-trusty.qcow2', wait=True) * ``/etc/openstack``
# Find a flavor with at least 512M of RAM More information at https://pypi.python.org/pypi/os-client-config
flavor = cloud.get_flavor_by_ram(512)
#. Create a server with *shade*, configured with the ``clouds.yml`` file::
import shade
# Initialize and turn on debug logging
shade.simple_logging(debug=True)
# Initialize cloud
# Cloud configs are read with os-client-config
cloud = shade.openstack_cloud(cloud='mordred')
# Upload an image to the cloud
image = cloud.create_image(
'ubuntu-trusty', filename='ubuntu-trusty.qcow2', wait=True)
# Find a flavor with at least 512M of RAM
flavor = cloud.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.
cloud.create_server(
'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)
# Boot a server, wait for it to boot, and then do whatever is needed
# to get a public ip for it.
cloud.create_server(
'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)