kokou Agbedanou
Les API
1. Workflow
OpenStack permet d’exposer ses fonctionnalités via les API de ses services ; chaque service dispose de
sa propre API.
Le workflow suivant décrit l’interaction utilisateur avec les API de Keystone puis de Glance.
2. Méthodologie d’utilisation
Il existe plusieurs méthodologies pour utiliser les API d’OpenStack :
© Editions ENI - Tous droits réservés - Copie personnelle de kokou Agbedanou -1-
kokou Agbedanou
ˇ
Utilisation de la commande curl :
ˇ
Récupération du token pour l’utilisateur $OS_USERNAME :
curl -s -X POST http://srv-openstack-controller:5000/v2.0 /tokens
-H "Content-Type: application/json" -d '{"auth": {"tenantName":
"'"$OS_TENANT_NAME"'", "passwordCredentials":{"username":
"'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"}}}' | python
-m json.tool
Le résultat (positif) de la commande se traduit par la réponse d’OpenStack :
{
"access": {
"metadata": {
"is_admin": 0 ,
"roles": [
"77706edc3f504afaac546625b58a278c",
"c4117762a5e34fd7b1e304af0ff01952"
]
},
"serviceCatalog": [
{
"endpoints": [
{
"adminURL": "http://srv-openstack-
controller:8774/v2/4864 d3fff7f445d696e52aa77f728734",
"id": "2a059568212e435c9eb8d38f0075cc94",
"internalURL": "http://srv-openstack-
controller:8774/v2/4 864d3fff7f445d696e52aa77f728734",
"publicURL": "http://srv-openstack-
controller:8774/v2/486 4d3fff7f445d696e52aa77f728734",
"region": "regionOne"
}
],
"endpoints_links": [],
© Editions ENI - Tous droits réservés - Copie personnelle de kokou Agbedanou -2-
kokou Agbedanou
"name": "nova",
"type": "compute"
},
{
"endpoints": [
<...>
"token": {
"audit_ids": [
"jsR4kW0uRIOcVINSCyoj3A"
],
"expires": "2015-06-27T10:02:39Z",
"id": "c2e730aff2674c609445dcc5aee46829",
"issued_at": "2015-06-27T09:02:39.636174",
"tenant": {
"description": "Admin Tenant",
"enabled": true,
"id": "4864d3fff7f445d696e52aa77f728734",
"name": "admin"
}
},
Il est important de récupérer le token_id et le tenant_id.
ˇ
Interrogation de l’API de Compute (liste des flavors) :
# curl -s -H "X-Auth-Token:c2e730aff2674c609445dcc5aee46829"
http://srv-openstack-
controller:8774/v2/4864d3fff7f445d696e52aa77f728734/flavors |
python -m json.tool
ˇ
Interrogation de l’API de Compute (liste des images) :
# curl -s -H "X-Auth-Token:c2e730aff2674c609445dcc5aee46829"
© Editions ENI - Tous droits réservés - Copie personnelle de kokou Agbedanou -3-
kokou Agbedanou
http://srv-openstack-
controller:8774/v2/4864d3fff7f445d696e52aa77f728734/images |
python -m json.tool
Le résultat de la commande s’affiche de la façon suivante :
{
"id": "2cddb75f-5d3f-4cfb-b09f-7e75a0033115",
"links": [
{
"href": "http://srv-openstack-
controller:8774/v2/4864d3fff7f445d696e52aa77f728734/images/2cddb75f-
5d3f-4cfb-b09f-7e75a0033115",
"rel": "self"
},
{
"href": "http://srv-openstack-
controller:8774/4864d3fff7f445d696e52aa77f728734/images/2cddb75f-
5d3f-4cfb-b09f-7e75a0033115",
"rel": "bookmark"
},
{
"href": "http://srv-openstack-
controller:9292/4864d3fff7f445d696e52aa77f728734/images/2cddb75f-
5d3f-4cfb-b09f-7e75a0033115",
"rel": "alternate",
"type": "application/vnd.openstack.image"
}
],
"name": "cirros-0.3.3-x86_64"
}
Le port 8774 est utilisé ici et il correspond au point d’entrée de l’API du service Nova.
© Editions ENI - Tous droits réservés - Copie personnelle de kokou Agbedanou -4-
kokou Agbedanou
ˇ
Utilisation de la CLI (Command-Line Interface).
La CLI sera largement utilisée tout au long des chapitres Installation OpenStack : services de
base et Installation OpenStack : services avancés.
ˇ
Utilisation d’appels REST : http://developer.openstack.org/api-ref-compute-v2-ext.html
ˇ
Utilisation du SDK OpenStack Python : http://python-openstacksdk.readthedocs.org/en/latest
/users/
La documentation complète sur les API OpenStack est sur le site officiel :
http://developer.openstack.org/
© Editions ENI - Tous droits réservés - Copie personnelle de kokou Agbedanou -5-