Commit 1f969912 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Update docs and Changelog for get_endpoint_url

Closes #2
parent 62d6e983
...@@ -23,4 +23,5 @@ Features: ...@@ -23,4 +23,5 @@ Features:
- Datetime support in DateArgument - Datetime support in DateArgument
- Resources can be reassigned to projects - Resources can be reassigned to projects
- Update account API commands to reflect changes in synnefo 0.16 - Update account API commands to reflect changes in synnefo 0.16
- Implement a get_endpoint_url method and use it
...@@ -2,8 +2,8 @@ Creating applications with kamaki API ...@@ -2,8 +2,8 @@ Creating applications with kamaki API
===================================== =====================================
Kamaki features a clients API for building third-party client applications that Kamaki features a clients API for building third-party client applications that
communicate with Synnefo and (in most cases) OpenStack cloud services. The package is communicate with Synnefo and (in most cases) OpenStack cloud services. The
called *kamaki.clients* and serves as a library. package is called *kamaki.clients* and serves as a library.
A showcase of an application built on *kamaki.clients* is *kamaki.cli*, the A showcase of an application built on *kamaki.clients* is *kamaki.cli*, the
command line interface of kamaki. command line interface of kamaki.
...@@ -46,32 +46,28 @@ respectively. ...@@ -46,32 +46,28 @@ respectively.
Using endpoints to get the authentication url Using endpoints to get the authentication url
--------------------------------------------- ---------------------------------------------
In OpenStack, each service (e.g., `compute`, `object-store`, etc.) has a number Each client is initialized with a URL called ``the endpoint URL``. To get one,
of `endpoints`. These `endpoints` are URIs which are used by kamaki as prefixes an AstakosClient should be initialized first. The AstakosClient is an Astakos
to form the corresponding API calls. Client applications need just one of these client class. Astakos implements the OpenStack Identity API and the Synnefo
`endpoints`, namely the `publicURL` (also referred to as `publicURL` in the Account API. The astakos library features a simple call (``get_endpoint_url``)
internals of kamaki client libraries). which returns the initialization URL for a given service type (e.g., 'compute',
'object-store', 'network', 'image')
Here are instructions for getting the publicURL for a service:: Kamaki features a library of clients. Each client abides to a service type,
stored in ``service_type`` attribute in the client class.
1. From the deployment UI get the AUTHENTICATION_URL and TOKEN The values of ``service_type`` for each client are shown bellow::
(Example 1.2)
2. Use them to instantiate an AstakosClient
(Example 1.2)
3. Use AstakosClient instance to get endpoints for the service of interest
(Example 1.3)
4. The 'publicURL' endpoint is the URL we are looking for
(Example 1.3)
The AstakosClient is a client for the Synnefo/Astakos server. Synnefo/Astakos storage.StorageClient, pithos.PithosClient --> object-store
is an identity server that implements the OpenStack identity API and it compute.ComputeClient, cyclades.CycladesClient --> compute
can be used to get the URLs needed for API calls URL construction. The astakos network.NetworkClient, cyclades.CycladesNetworkClient --> network
kamaki client library simplifies this process. image.ImageClient --> image
astakos.AstakosClient --> identity
Let's review with a few examples. Let's review with a few examples.
First, an astakos client must be initialized (Example 1.2). An First, an astakos client must be initialized (Example 1.2). An
AUTHENTICATION_URL and a TOKEN can be acquired from the Synnefo deployment UI. AUTHENTICATION_URL and a TOKEN can be acquired from the service web UI.
.. code-block:: python .. code-block:: python
:emphasize-lines: 1 :emphasize-lines: 1
...@@ -82,32 +78,19 @@ AUTHENTICATION_URL and a TOKEN can be acquired from the Synnefo deployment UI. ...@@ -82,32 +78,19 @@ AUTHENTICATION_URL and a TOKEN can be acquired from the Synnefo deployment UI.
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN) astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
Next, the astakos client can be used to retrieve the `publicURL` values for the Next, the astakos client can be used to retrieve the URL for each service. In
services of interest. In this case (Example 1.3) they are *cyclades* (compute) this case (Example 1.3) we need a *compute* and an *object-store* URL. They
and *pithos* (object-store). A number of endpoints is related to each service, will be used to initialize a *cyclades* and a *pithos* client respectively.
but kamaki clients only need the ones labeled ``publicURL``.
.. code-block:: python .. code-block:: python
:emphasize-lines: 1 :emphasize-lines: 1
Example 1.3: Retrieve cyclades and pithos publicURL values Example 1.3: Retrieve cyclades and pithos URLs
cyclades_endpoints = astakos.get_service_endpoints('compute')
cyclades_URL = cyclades_endpoints['publicURL']
pithos_endpoints = astakos.get_service_endpoints('object-store')
pithos_URL = pithos_endpoints['publicURL']
The ``get_service_endpoints`` method is called with the service name as an cyclades_URL = astakos.get_endpoint_url(CycladesClient.service_type)
argument. Here are the service names for the kamaki clients:: pithos_URL = astakos.get_endpoint_url(PithosClent.service_type)
storage.StorageClient, pithos.PithosClient --> object-store
compute.ComputeClient, cyclades.CycladesClient --> compute
network.NetworkClient, cyclades.CycladesNetworkClient --> network
image.ImageClient --> image
astakos.AstakosClient --> identity, account
For example It's time to initialize both clients.
.. code-block:: python .. code-block:: python
:emphasize-lines: 1 :emphasize-lines: 1
...@@ -199,8 +182,7 @@ The following example concatenates examples 1.1 to 1.4 plus error handling ...@@ -199,8 +182,7 @@ The following example concatenates examples 1.1 to 1.4 plus error handling
raise raise
try: try:
cyclades_endpoints = astakos.get_service_endpoints('compute') CYCLADES_URL = astakos.get_endpoint_url(CycladesClient.service_type)
CYCLADES_URL = cyclades_endpoints['publicURL']
except ClientError: except ClientError:
print('Failed to get endpoints for cyclades') print('Failed to get endpoints for cyclades')
...@@ -210,8 +192,7 @@ The following example concatenates examples 1.1 to 1.4 plus error handling ...@@ -210,8 +192,7 @@ The following example concatenates examples 1.1 to 1.4 plus error handling
print('Failed to initialize Cyclades client') print('Failed to initialize Cyclades client')
try: try:
pithos_endpoints = astakos.get_service_endpoints('object-store') PITHOS_URL = astakos.get_endpoint_url(PithosClient.service_type)
PITHOS_URL = pithos_endpoints['publicURL']
except ClientError: except ClientError:
print('Failed to get endpoints for pithos') print('Failed to get endpoints for pithos')
...@@ -257,7 +238,7 @@ Batch-create servers ...@@ -257,7 +238,7 @@ Batch-create servers
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN) astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
CYCLADES_URL = astakos.get_service_endpoints('compute')['publicURL'] CYCLADES_URL = astakos.get_endpoint_url(CycladesClient.service_type)
cyclades = CycladesClient(CYCLADES_URL, TOKEN) cyclades = CycladesClient(CYCLADES_URL, TOKEN)
# (name, flavor-id, image-id) # (name, flavor-id, image-id)
...@@ -300,11 +281,11 @@ Register a banch of pre-uploaded images ...@@ -300,11 +281,11 @@ Register a banch of pre-uploaded images
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN) astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
USER_UUID = astakos.user_info['id'] USER_UUID = astakos.user_info['id']
PITHOS_URL = astakos.get_service_endpoints('object-store')['publicURL'] PITHOS_URL = astakos.get_endpoint_url(PithosClient.service_type)
pithos = PithosClient( pithos = PithosClient(
PITHOS_URL, TOKEN, account=USER_UUID, container=IMAGE_CONTAINER) PITHOS_URL, TOKEN, account=USER_UUID, container=IMAGE_CONTAINER)
IMAGE_URL = astakos.get_service_endpoints('image')['publicURL'] IMAGE_URL = astakos.get_endpoint_url(ImageClient.service_type)
plankton = ImageClient(IMAGE_URL, TOKEN) plankton = ImageClient(IMAGE_URL, TOKEN)
for img in pithos.list_objects(): for img in pithos.list_objects():
...@@ -336,12 +317,12 @@ Two servers and a private network ...@@ -336,12 +317,12 @@ Two servers and a private network
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN) astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
NETWORK_URL = astakos.get_service_endpoints('network')['publicURL'] NETWORK_URL = astakos.get_endpoint_url(CycladesNetworkClient.service_type)
network = CycladesNetworkClient(NETWORK_URL, TOKEN) network = CycladesNetworkClient(NETWORK_URL, TOKEN)
net = network.create_network(type='MAC_FILTERED', name='My private network') net = network.create_network(type='MAC_FILTERED', name='My private network')
CYCLADES_URL = astakos.get_service_endpoints('compute')['publicURL'] CYCLADES_URL = astakos.get_endpoint_url(CycladesClient.service_type)
cyclades = CycladesClient(CYCLADES_URL, TOKEN) cyclades = CycladesClient(CYCLADES_URL, TOKEN)
FLAVOR_ID = 'put your flavor id here' FLAVOR_ID = 'put your flavor id here'
......
...@@ -82,18 +82,14 @@ This is the plan: ...@@ -82,18 +82,14 @@ This is the plan:
AUTH_URL, AUTH_TOKEN)) AUTH_URL, AUTH_TOKEN))
raise raise
# 3. Get the endpoints # 3. Get the endpoint URLs
# Identity, Account --> astakos
# Compute, Network --> cyclades
# Object-store --> pithos
# Image --> plankton
try: try:
endpoints = dict( endpoints = dict(
astakos=AUTH_URL, astakos=AUTH_URL,
cyclades=auth.get_service_endpoints('compute')['publicURL'], cyclades=auth.get_endpoint_url(CycladesClient.service_type),
network=auth.get_service_endpoints('network')['publicURL'], network=auth.get_endpoint_url(CycladesNetworkClient.service_type),
pithos=auth.get_service_endpoints('object-store')['publicURL'], pithos=auth.get_endpoint_url(PithosClient.service_type),
plankton=auth.get_service_endpoints('image')['publicURL'] plankton=auth.get_endpoint_url(ImageClient.service_type)
) )
user_id = auth.user_info['id'] user_id = auth.user_info['id']
except ClientError: except ClientError:
...@@ -641,11 +637,13 @@ logging more. We also added some command line interaction candy. ...@@ -641,11 +637,13 @@ logging more. We also added some command line interaction candy.
print(' Get the endpoints') print(' Get the endpoints')
try: try:
endpoints = dict( endpoints = dict(
astakos=auth.get_service_endpoints('identity')['publicURL'], # Astakos implements identity and account APIs - The endpoint
cyclades=auth.get_service_endpoints('compute')['publicURL'], # URL is the same for both services
network=auth.get_service_endpoints('network')['publicURL'], astakos=auth.get_endpoint_url('identity'),
pithos=auth.get_service_endpoints('object-store')['publicURL'], cyclades=auth.get_endpoint_url(CycladesClient.service_type),
plankton=auth.get_service_endpoints('image')['publicURL'] network=auth.get_endpoint_url(CycladesNetworkClient.service_type),
pithos=auth.get_endpoint_url(PithosClient.service_type),
plankton=auth.get_endpoint_url(ImageClient.service_type)
) )
user_id = auth.user_info['id'] user_id = auth.user_info['id']
except ClientError: except ClientError:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment