Edits to SDK sections in the End User Guide

Edited enumerated lists and directives to follow conventions for RST files

Change-Id: Ic78c971a9ef36babccf7f01a104fb1f979dd7012
This commit is contained in:
daz 2015-03-06 13:20:17 +11:00
parent 3c565ab973
commit 49ec1d522c
2 changed files with 299 additions and 306 deletions

View File

@ -44,28 +44,28 @@ List servers (API v2)
The following program lists servers by using the Compute API v2.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from credentials import get_nova_credentials_v2
from novaclient.client import Client
2. Get Nova credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
#. Get Nova credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
.. code:: python
nova_client = Client(**credentials)
nova_client = Client(**credentials)
4. List servers by calling ``servers.list`` on ``nova_client`` object:
#. List servers by calling ``servers.list`` on ``nova_client`` object:
.. code:: python
.. code:: python
print(nova_client.servers.list())
print(nova_client.servers.list())
List server code listing example
--------------------------------
@ -86,52 +86,51 @@ Create server (API v2)
The following program creates a server (VM) by using the Compute API v2.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
import time
from credentials import get_nova_credentials_v2
from novaclient.client import Client
import time
from credentials import get_nova_credentials_v2
from novaclient.client import Client
2. Get OpenStack credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
#. Get OpenStack credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
.. code:: python
nova_client = Client(**credentials)
nova_client = Client(**credentials)
4. Get the flavor and image to use to create a server. This code uses
the ``cirros`` image, the ``m1.tiny`` flavor, and the ``private``
network:
#. Get the flavor and image to use to create a server. This code uses
the ``cirros`` image, the ``m1.tiny`` flavor, and the ``private``
network:
.. code:: python
.. code:: python
image = nova_client.images.find(name="cirros")
flavor = nova_client.flavors.find(name="m1.tiny")
net = nova_client.networks.find(label="private")
image = nova_client.images.find(name="cirros")
flavor = nova_client.flavors.find(name="m1.tiny")
net = nova_client.networks.find(label="private")
5. To create the server, use the network, image, and flavor:
#. To create the server, use the network, image, and flavor:
.. code:: python
.. code:: python
nics = [{'net-id': net.id}]
instance = nova_client.servers.create(name="vm2", image=image,
flavor=flavor, key_name="keypair-1", nics=nics)
nics = [{'net-id': net.id}]
instance = nova_client.servers.create(name="vm2", image=image,
flavor=flavor, key_name="keypair-1", nics=nics)
6. Run the "Sleep for five seconds" command, and determine whether
the server/vm was
created by calling ``nova_client.servers.list()``:
#. Run the "Sleep for five seconds" command, and determine whether
the server/vm was created by calling ``nova_client.servers.list()``:
.. code:: python
.. code:: python
print("Sleeping for 5s after create command")
time.sleep(5)
print("List of VMs")
print(nova_client.servers.list())
print("Sleeping for 5s after create command")
time.sleep(5)
print("List of VMs")
print(nova_client.servers.list())
Create server code listing example
----------------------------------
@ -165,25 +164,25 @@ Delete server (API v2)
The following program deletes a server (VM) by using the Compute API v2.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
import time
from credentials import get_nova_credentials_v2
from novaclient.client import Client
import time
from credentials import get_nova_credentials_v2
from novaclient.client import Client
2. Get Nova credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
#. Get Nova credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
.. code:: python
nova_client = Client(**credentials)
nova_client = Client(**credentials)
4. Determine whether the ``vm1`` server exists:
#. Determine whether the ``vm1`` server exists:
a. List servers: ``servers_list``.
@ -192,25 +191,25 @@ The following program deletes a server (VM) by using the Compute API v2.
c. If true, set the variable name ``server_exists`` to ``True``
and break from the for loop:
.. code:: python
.. code:: python
servers_list = nova_client.servers.list()
server_del = "vm1"
server_exists = False
servers_list = nova_client.servers.list()
server_del = "vm1"
server_exists = False
for s in servers_list:
if s.name == server_del:
print("This server %s exists" % server_del)
server_exists = True
break
for s in servers_list:
if s.name == server_del:
print("This server %s exists" % server_del)
server_exists = True
break
5. If the server exists, run the ``delete`` method of the
``nova_client.servers`` object:
#. If the server exists, run the ``delete`` method of the
``nova_client.servers`` object:
.. code:: python
.. code:: python
nova_client.servers.delete(s)
nova_client.servers.delete(s)
Delete server code example
--------------------------
@ -246,70 +245,68 @@ Update server (API v2)
The following program updates the name of a server (VM) by using the
Compute API v2.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_server
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_server
``print_server`` is a method defined in ``utils.py`` and prints the
server details as shown in the code listing below:
``print_server`` is a method defined in ``utils.py`` and prints the
server details as shown in the code listing below:
.. code:: python
.. code:: python
def print_server(server):
print("-"*35)
print("server id: %s" % server.id)
print("server name: %s" % server.name)
print("server image: %s" % server.image)
print("server flavor: %s" % server.flavor)
print("server key name: %s" % server.key_name)
print("user_id: %s" % server.user_id)
print("-"*35)
def print_server(server):
print("-"*35)
print("server id: %s" % server.id)
print("server name: %s" % server.name)
print("server image: %s" % server.image)
print("server flavor: %s" % server.flavor)
print("server key name: %s" % server.key_name)
print("user_id: %s" % server.user_id)
print("-"*35)
2. Get OpenStack Credentials. See :ref:`Get OpenStack credentials
(API v2) <get-openstack-credentials>`.
#. Get OpenStack Credentials. See :ref:`Get OpenStack credentials
(API v2) <get-openstack-credentials>`.
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
nova_client = Client(**credentials)
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
nova_client = Client(**credentials)
4. Get the server instance using ``server_id`` and print the details by
#. Get the server instance using ``server_id`` and print the details by
calling ``print_server`` method:
.. code:: python
.. code:: python
server_id = '99889c8d-113f-4a7e-970c-77f1916bfe14'
server = nova_client.servers.get(server_id)
n = server.name
print_server(server)
server_id = '99889c8d-113f-4a7e-970c-77f1916bfe14'
server = nova_client.servers.get(server_id)
n = server.name
print_server(server)
#. Call ``server.update`` on the server object with the new value for
``name`` variable:
5. Call ``server.update`` on the server object with the new value for
``name`` variable:
.. code:: python
.. code:: python
server.update(name = n + '1')
server.update(name = n + '1')
#. Get the updated instance of the server:
6. Get the updated instance of the server:
.. code:: python
.. code:: python
server_updated = nova_client.servers.get(server_id)
server_updated = nova_client.servers.get(server_id)
#. Call ``print_server`` again to check the update server details:
7. Call ``print_server`` again to check the update server details:
.. code:: python
.. code:: python
print_server(server_updated)
print_server(server_updated)
Update server code listing example
----------------------------------
@ -342,48 +339,47 @@ List flavors (API v2)
The following program lists flavors and their details by using the
Compute API v2.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_flavors
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_flavors
The ``print_flavors`` method is defined in ``utils.py`` and prints the
flavor details:
The ``print_flavors`` method is defined in ``utils.py`` and prints the
flavor details:
.. code:: python
.. code:: python
def print_flavors(flavor_list):
for flavor in flavor_list:
print("-"*35)
print("flavor id : %s" % flavor.id)
print("flavor name : %s" % flavor.name)
print("-"*35)
def print_flavors(flavor_list):
for flavor in flavor_list:
print("-"*35)
print("flavor id : %s" % flavor.id)
print("flavor name : %s" % flavor.name)
print("-"*35)
2. Get OpenStack credentials. :ref:`Get OpenStack credentials
(API v2) <get-openstack-credentials>`.
#. Get OpenStack credentials. :ref:`Get OpenStack credentials
(API v2) <get-openstack-credentials>`.
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
.. code:: python
nova_client = Client(**credentials)
nova_client = Client(**credentials)
#. List flavors by calling ``list()`` on ``nova_client.flavors`` object:
4. List flavors by calling ``list()`` on ``nova_client.flavors`` object:
.. code:: python
.. code:: python
flavors_list = nova_client.flavors.list()
flavors_list = nova_client.flavors.list()
#. Print the flavor details, id and name by calling ``print_flavors``:
5. Print the flavor details, id and name by calling ``print_flavors``:
.. code:: python
.. code:: python
print_flavors(flavors_list)
print_flavors(flavors_list)
List flavors code listing example
---------------------------------
@ -408,53 +404,51 @@ List floating IPs (API v2)
The following program lists the floating IPs and their details by using
the Compute API v2.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_values_ip
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_values_ip
The ``print_values_ip`` method is defined in ``utils.py`` and prints the
floating\_ip object details:
The ``print_values_ip`` method is defined in ``utils.py`` and prints the
floating\_ip object details:
.. code:: python
.. code:: python
def print_values_ip(ip_list):
ip_dict_lisl = []
for ip in ip_list:
print("-"*35)
print("fixed_ip : %s" % ip.fixed_ip)
print("id : %s" % ip.id)
print("instance_id : %s" % ip.instance_id)
print("ip : %s" % ip.ip)
print("pool : %s" % ip.pool)
def print_values_ip(ip_list):
ip_dict_lisl = []
for ip in ip_list:
print("-"*35)
print("fixed_ip : %s" % ip.fixed_ip)
print("id : %s" % ip.id)
print("instance_id : %s" % ip.instance_id)
print("ip : %s" % ip.ip)
print("pool : %s" % ip.pool)
2. Get OpenStack credentials. See :ref:`Get OpenStack credentials
(API v2) <get-openstack-credentials>`.
#. Get OpenStack credentials. See :ref:`Get OpenStack credentials
(API v2) <get-openstack-credentials>`.
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
.. code:: python
nova_client = Client(**credentials)
nova_client = Client(**credentials)
4. List floating IPs by calling ``list()`` on ``nova_client.floating_ips``
#. List floating IPs by calling ``list()`` on ``nova_client.floating_ips``
object:
.. code:: python
.. code:: python
ip_list = nova_client.floating_ips.list()
ip_list = nova_client.floating_ips.list()
5. Print the floating IP object details by calling ``print_values_ip``:
#. Print the floating IP object details by calling ``print_values_ip``:
.. code:: python
.. code:: python
print_values_ip(ip_list)
print_values_ip(ip_list)
List floating IPs code listing example
--------------------------------------
@ -477,48 +471,48 @@ List hosts (API v2)
The following program lists the hosts by using the Compute API v2.
1. Import the following modules:
#. Import the following modules:
.. code:: python
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_hosts
from credentials import get_nova_credentials_v2
from novaclient.client import Client
from utils import print_hosts
The ``print_hosts`` method is defined in ``utils.py`` and prints the
host object details:
The ``print_hosts`` method is defined in ``utils.py`` and prints the
host object details:
.. code:: python
.. code:: python
def print_hosts(host_list):
for host in host_list:
print("-"*35)
print("host_name : %s" % host.host_name)
print("service : %s" % host.service)
print("zone : %s" % host.zone)
print("-"*35)
def print_hosts(host_list):
for host in host_list:
print("-"*35)
print("host_name : %s" % host.host_name)
print("service : %s" % host.service)
print("zone : %s" % host.zone)
print("-"*35)
2. Get OpenStack credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
#. Get OpenStack credentials. See :ref:`Get OpenStack credentials (API v2)
<get-openstack-credentials>`.
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
.. code:: python
nova_client = Client(**credentials)
nova_client = Client(**credentials)
4. List hosts by calling ``list()`` on ``nova_client.hosts`` object:
#. List hosts by calling ``list()`` on ``nova_client.hosts`` object:
.. code:: python
.. code:: python
host_list = nova_client.hosts.list()
host_list = nova_client.hosts.list()
5. Print the host object details by calling ``print_hosts(host_list)``:
#. Print the host object details by calling ``print_hosts(host_list)``:
.. code:: python
.. code:: python
print_hosts(host_list)
print_hosts(host_list)
List hosts code listing example
-------------------------------

View File

@ -292,55 +292,55 @@ This example queries OpenStack Networking to create a router and add a
port to a subnet.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from neutronclient.v2_0 import client
import novaclient.v1_1.client as nvclient
from credentials import get_credentials
from credentials import get_nova_credentials
from utils import print_values_server
from neutronclient.v2_0 import client
import novaclient.v1_1.client as nvclient
from credentials import get_credentials
from credentials import get_nova_credentials
from utils import print_values_server
2. Get Nova Credentials. See :ref:'Get Nova credentials
<get-nova-credentials>'.
#. Get Nova Credentials. See :ref:'Get Nova credentials
<get-nova-credentials>'.
3. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
#. Instantiate the ``nova_client`` client object by using the
``credentials`` dictionary object:
.. code:: python
.. code:: python
nova_client = nvclient.Client(**credentials)
nova_client = nvclient.Client(**credentials)
4. Create a router and add a port to the subnet:
#. Create a router and add a port to the subnet:
.. code:: python
.. code:: python
# Replace with network_id from your environment
# Replace with network_id from your environment
network_id = '81bf592a-9e3f-4f84-a839-ae87df188dc1'
network_id = '81bf592a-9e3f-4f84-a839-ae87df188dc1'
credentials = get_credentials()
neutron = client.Client(**credentials)
neutron.format = json
request = {'router': {'name': 'router name',
'admin_state_up': True}}
credentials = get_credentials()
neutron = client.Client(**credentials)
neutron.format = json
request = {'router': {'name': 'router name',
'admin_state_up': True}}
router = neutron.create_router(request)
router_id = router['router']['id']
# for example: '72cf1682-60a8-4890-b0ed-6bad7d9f5466'
router = neutron.show_router(router_id)
print(router)
body_value = {'port': {
'admin_state_up': True,
'device_id': router_id,
'name': 'port1',
'network_id': network_id,
}}
router = neutron.create_router(request)
router_id = router['router']['id']
# for example: '72cf1682-60a8-4890-b0ed-6bad7d9f5466'
router = neutron.show_router(router_id)
print(router)
body_value = {'port': {
'admin_state_up': True,
'device_id': router_id,
'name': 'port1',
'network_id': network_id,
}}
response = neutron.create_port(body=body_value)
print(response)
print("Execution Completed")
response = neutron.create_port(body=body_value)
print(response)
print("Execution Completed")
Create router: complete code listing example
--------------------------------------------
@ -390,46 +390,46 @@ Delete a network
This example queries OpenStack Networking to delete a network.
To delete a network
To delete a network:
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from neutronclient.v2_0 import client
from credentials import get_credentials
from neutronclient.v2_0 import client
from credentials import get_credentials
2. Get credentials. See :ref:`Get Nova credentials <get-nova-credentials>`.
#. Get credentials. See :ref:`Get Nova credentials <get-nova-credentials>`.
3. Instantiate the ``neutron`` client object by using the ``credentials``
dictionary object:
#. Instantiate the ``neutron`` client object by using the ``credentials``
dictionary object:
.. code:: python
.. code:: python
neutron = client.Client(**credentials)
neutron = client.Client(**credentials)
4. Delete the network:
#. Delete the network:
.. code:: python
.. code:: python
body_sample = {'network': {'name': network_name,
'admin_state_up': True}}
body_sample = {'network': {'name': network_name,
'admin_state_up': True}}
netw = neutron.create_network(body=body_sample)
net_dict = netw['network']
network_id = net_dict['id']
print('Network %s created' % network_id)
netw = neutron.create_network(body=body_sample)
net_dict = netw['network']
network_id = net_dict['id']
print('Network %s created' % network_id)
body_create_subnet = {'subnets': [{'cidr': '192.168.199.0/24',
'ip_version': 4, 'network_id': network_id}]}
body_create_subnet = {'subnets': [{'cidr': '192.168.199.0/24',
'ip_version': 4, 'network_id': network_id}]}
subnet = neutron.create_subnet(body=body_create_subnet)
print('Created subnet %s' % subnet)
subnet = neutron.create_subnet(body=body_create_subnet)
print('Created subnet %s' % subnet)
neutron.delete_network(network_id)
print('Deleted Network %s' % network_id)
neutron.delete_network(network_id)
print('Deleted Network %s' % network_id)
print("Execution completed")
print("Execution completed")
Delete network: complete code listing example
---------------------------------------------
@ -470,32 +470,32 @@ List routers
This example queries OpenStack Networking to list all routers.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from neutronclient.v2_0 import client
from credentials import get_credentials
from utils import print_values
from neutronclient.v2_0 import client
from credentials import get_credentials
from utils import print_values
2. Get credentials. See :ref:`Get Nova credentials <get-nova-credentials>`.
#. Get credentials. See :ref:`Get Nova credentials <get-nova-credentials>`.
3. Instantiate the ``neutron`` client object by using the ``credentials``
dictionary object:
#. Instantiate the ``neutron`` client object by using the ``credentials``
dictionary object:
.. code:: python
.. code:: python
neutron = client.Client(**credentials)
neutron = client.Client(**credentials)
4. List the routers:
#. List the routers:
.. code:: python
.. code:: python
routers_list = neutron.list_routers(retrieve_all=True)
print_values(routers_list, 'routers')
print("Execution completed")
routers_list = neutron.list_routers(retrieve_all=True)
print_values(routers_list, 'routers')
print("Execution completed")
For ``print_values``, see :ref:`Print values <print-values>`.
For ``print_values``, see :ref:`Print values <print-values>`.
List routers: complete code listing example
-------------------------------------------
@ -522,29 +522,29 @@ List security groups
This example queries OpenStack Networking to list security groups.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from neutronclient.v2_0 import client
from credentials import get_credentials
from utils import print_values
from neutronclient.v2_0 import client
from credentials import get_credentials
from utils import print_values
2. Get credentials. See :ref:`Get credentials <get-credentials>`.
#. Get credentials. See :ref:`Get credentials <get-credentials>`.
3. Instantiate the ``neutron`` client object by using the ``credentials``
dictionary object:
#. Instantiate the ``neutron`` client object by using the ``credentials``
dictionary object:
.. code:: python
.. code:: python
neutron = client.Client(**credentials)
neutron = client.Client(**credentials)
4. List Security groups
#. List Security groups
.. code:: python
.. code:: python
sg = neutron.list_security_groups()
print(sg)
sg = neutron.list_security_groups()
print(sg)
List security groups: complete code listing example
---------------------------------------------------
@ -561,44 +561,43 @@ List security groups: complete code listing example
sg = neutron.list_security_groups()
print(sg)
**Note**
.. note::
OpenStack Networking security groups are case-sensitive while the
nova-network security groups are case-insensitive.
.. _list-subnets:
OpenStack Networking security groups are case-sensitive while the
nova-network security groups are case-insensitive.
List subnets
~~~~~~~~~~~~
This example queries OpenStack Networking to list subnets.
1. Import the following modules:
#. Import the following modules:
.. code:: python
.. code:: python
from neutronclient.v2_0 import client
from credentials import get_credentials
from utils import print_values
from neutronclient.v2_0 import client
from credentials import get_credentials
from utils import print_values
2. Get credentials. See :ref:'Get credentials <get-credentials>'.
#. Get credentials. See :ref:'Get credentials <get-credentials>'.
3. Instantiate the ``neutron`` client object by using the ``credentials``
#. Instantiate the ``neutron`` client object by using the ``credentials``
dictionary object:
.. code:: python
.. code:: python
neutron = client.Client(**credentials)
neutron = client.Client(**credentials)
4. List subnets:
#. List subnets:
.. code:: python
.. code:: python
subnets = neutron.list_subnets()
print(subnets)
subnets = neutron.list_subnets()
print(subnets)
List subnets: complete code listing example
-------------------------------------------
.. code:: python
#!/usr/bin/env python