cURL : Utiliser le service d'orchestration

Afin d’illustrer tous les exemples de ce guide, nous allons utiliser un exemple de fichier HOT permettant de déployer 2 instances sur un réseau existant.

Créer une Stack

Dans notre exemple, nous allons devoir renseigner les éléments suivants :

  • La paire de clés à utiliser pour toutes les instances
  • Le type d’image : dans notre exemple Ubuntu 14.4 (id : 70d8f340-3628-474c-8910-df2ddf88997a)
  • Le type d’instance : nous utiliserons le type n1.cw.standard-2 (id : 22)
  • L’id du réseau à utiliser. Vous pouvez récupérer la liste en utilsant :
$ curl -i https://network.fr1.cloudwatt.com/v2.0/networks.json -X GET -H "X-Auth-Token:<token>" -H "Content-Type: application/json" -H "Accept: application/json"
  • L’id du sous-réseau à utiliser. Vous pouvez récupérer la liste des sous-résaux en utilisant :
curl -i https://network.fr1.cloudwatt.com/v2.0/subnets.json -X GET -H "X-Auth-Token:<token>" -H "Content-Type: application/json" -H "Accept: application/json"

Maintenant pour créer une stack vous pouvez utiliser :

$ curl -i -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" -d '{"stack_name":"<nom_de_la_stack>","parameters": {"subnet_id":"<id_du_sous_reseau>", "key_name":"<ma_cle>", "image":"<id_de_l_image>","flavor":"<type_d_instance>","net_id":"<id_du_reseau>"},"template_url":"<url_du_template_HOT>","timeout_mins": 60}'  https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks

Par exemple :

$ curl -i -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" -d '{"stack_name":"maStack","parameters": {"subnet_id":"55c72d79-1cf9-4786-a389-f34895b9d349", "key_name": "ma_cle", "image":"70d8f340-3628-474c-8910-df2ddf88997a", "flavor":"22", "net_id":"e6560afd-b71a-4918-82db-3ae4326bbecd"},"template_url":"https://raw.githubusercontent.com/cloudwatt/openstack-heat-templates/master/Exemples/servers_in_existing_neutron_network_no_floating_ips.hot","timeout_mins": 60}'  https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks

Résultat :

HTTP/1.1 201 Created
Location: https://orchestration.fr1.cloudwatt.com/v1/d0000000000000000000000000000000/stacks/maStack/618ac0ad-d208-4788-a284-73044c32e908
Content-Type: application/json
Content-Length: 206
Date: Mon, 22 Sep 2014 14:27:02 GMT

{
   "stack":{
      "id":"618ac0ad-d208-4788-a284-73044c32e908",
      "links":[
         {
            "href":"https://orchestration.fr1.cloudwatt.com/v1/d0000000000000000000000000000000/stacks/maStack/618ac0ad-d208-4788-a284-73044c32e908",
            "rel":"self"
         }
      ]
   }
}

Dans les exemples qui suivent, nous allons utiliser l’ID de cette stack : 618ac0ad-d208-4788-a284-73044c32e908.

Si vous souhaitez juste tester un fichier HOT sans pour autant créer une Stack, vous pouvez utiliser :

$ curl -i -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" -d '{"stack_name":"<nom_de_la_stack>","template_url":"<url_du_template_HOT>","timeout_mins": 60}'  https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/validate

Exemple :

$ curl -i -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" -d '{"stack_name":"maStack","template_url":"https://raw.githubusercontent.com/cloudwatt/openstack-heat-templates/master/Exemples/servers_in_existing_neutron_network_no_floating_ips.hot","timeout_mins": 60}'  https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/validate

Résultat :

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 747
Date: Mon, 22 Sep 2014 14:39:23 GMT

{
   "Description":"HOT template to deploy two servers to an existing Neutron network.",
   "Parameters":{
      "subnet_id":{
         "Type":"String",
         "NoEcho":"false",
         "Description":"ID of Neutron sub network into which servers get deployed",
         "Label":"subnet_id"
      },
      "key_name":{
         "Type":"String",
         "NoEcho":"false",
         "Description":"Name of keypair to assign to servers",
         "Label":"key_name"
      },
      "image":{
         "Type":"String",
         "NoEcho":"false",
         "Description":"Name of image to use for servers",
         "Label":"image"
      },
      "flavor":{
         "Type":"String",
         "NoEcho":"false",
         "Description":"Flavor to use for servers",
         "Label":"flavor"
      },
      "net_id":{
         "Type":"String",
         "NoEcho":"false",
         "Description":"ID of Neutron network into which servers get deployed",
         "Label":"net_id"
      }
   }
}

En cas de problème lors de la validation, un message d’erreur va s’afficher.


Mettre à jour une stack

Pour mettre à jour une stack existante en utilisant un fichier de HOT modifié vous pouvez utiliser :

$ curl -i -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" -d '{"stack_name":"<nom_de_la_stack>","parameters": {"subnet_id":"<id_du_sous_reseau>", "key_name":"<ma_cle>", "image":"<id_de_l_image>","flavor":"<type_d_instance>","net_id":"<id_du_reseau>"},"template_url":"<url_du_template_HOT>","timeout_mins": 60}'  https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/<nom_de_la_stack>/<id_de_la_stack>

Par exemple :

$ curl -i -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" -d '{"stack_name":"maStack","parameters": {"subnet_id":"55c72d79-1cf9-4786-a389-f34895b9d349", "key_name":"ma_cle", "image":"70d8f340-3628-474c-8910-df2ddf88997a","flavor":"22", "net_id":"e6560afd-b71a-4918-82db-3ae4326bbecd"},"template_url":"https://raw.githubusercontent.com/cloudwatt/openstack-heat-templates/master/Exemples/servers_in_existing_neutron_network_no_floating_ips.hot","timeout_mins": 60}'  https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/maStack/618ac0ad-d208-4788-a284-73044c32e908

Résultat :

HTTP/1.1 202 Accepted
Content-Length: 159
Content-Type: text/html; charset=UTF-8
Date: Tue, 23 Sep 2014 07:17:57 GMT

<html>
 <head>
  <title>202 Accepted</title>
 </head>
 <body>
  <h1>202 Accepted</h1>
  The request is accepted for processing.<br /><br />



 </body>
</html>

Certaines ressources vont se mettre à jour et d’autres seront remplacées par des nouvelles.


Obtenir des informations sur vos stacks

Pour obtenir la liste des stacks :

$ curl -i -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks

Réponse :

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 479
Date: Wed, 24 Sep 2014 09:47:04 GMT

{
    "stacks":[
        {
            "description":"HOT template to deploy two servers to an existing Neutron network.",
            "links":[
                {
                    "href":"https://orchestration.fr1.cloudwatt.com/v1/d0000000000000000000000000000000/stacks/maStack/618ac0ad-d208-4788-a284-73044c32e908",
                    "rel":"self"
                }
            ],
            "stack_status_reason":"Stack CREATE completed successfully",
            "stack_name":"maStack",
            "creation_time":"2014-09-24T09:46:04Z",
            "updated_time":null,
            "stack_status":"CREATE_COMPLETE",
            "id":"618ac0ad-d208-4788-a284-73044c32e908"
        }
    ]
}

Pour obtenir plus d’informations sur une stack en particulier :

$ curl -i -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/<nom_de_la_stack>/<id_de_la_stack>

Exemple :

$ curl -i -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/maStack/618ac0ad-d208-4788-a284-73044c32e908

Réponse :

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 1232
Date: Wed, 24 Sep 2014 10:01:50 GMT


{
    "stack":{
        "disable_rollback":true,
        "description":"HOT template to deploy two servers to an existing Neutron network.",
        "parameters":{
            "OS::stack_id":"618ac0ad-d208-4788-a284-73044c32e908",
            "OS::stack_name":"maStack",
            "subnet_id":"55c72d79-1cf9-4786-a389-f34895b9d349",
            "key_name":"fbureau",
            "image":"70d8f340-3628-474c-8910-df2ddf88997a",
            "flavor":"22",
            "net_id":"aadb35f3-2d04-4548-aad9-eeb6d33de603"
        },
        "stack_status_reason":"Stack CREATE completed successfully",
        "stack_name":"maStack",
        "outputs":[
            {
                "output_value":"192.168.0.253",
                "description":"IP address of server1 in provider network",
                "output_key":"server1_provider_ip"
            },
            {
                "output_value":"192.168.0.254",
                "description":"IP address of server2 in provider network",
                "output_key":"server2_provider_ip"
            }
        ],
        "creation_time":"2014-09-24T09:46:04Z",
        "links":[
            {
                "href":"https://orchestration.fr1.cloudwatt.com/v1/d0000000000000000000000000000000/stacks/maStack/618ac0ad-d208-4788-a284-73044c32e908",
                "rel":"self"
            }
        ],
        "capabilities":[

        ],
        "notification_topics":[

        ],
        "timeout_mins":60,
        "stack_status":"CREATE_COMPLETE",
        "updated_time":null,
        "id":"618ac0ad-d208-4788-a284-73044c32e908",
        "template_description":"HOT template to deploy two servers to an existing Neutron network."
    }
}

Durant le cycle de vie d’une Stack, plusieurs événements vont être générés. Pour en obtenir la liste, vous pouvez utiliser :

$ curl -i -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/<nom_de_la_stack>/<id_de_la_stack>/events

Exemple :

$ curl -i -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/maStack/70d8f340-3628-474c-8910-df2ddf88997a/events

Résultat :


Pour obtenir plus d’informations sur un événement :

$ curl -i -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/<nom_de_la_stack>/<id_de_la_stack>/resources/<type_de_ressource>/events/<id_de_l_evenement>

Exemple :

$ curl -i -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/maStack/70d8f340-3628-474c-8910-df2ddf88997a/resources/server_security_group/events/6f7e2d5f-f7be-4070-be15-3bad32f1d62d

Résultat :

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 1454
Date: Wed, 24 Sep 2014 12:53:02 GMT

{
    "event":{
        "resource_name":"server_security_group",
        "event_time":"2014-09-24T09:46:04Z",
        "links":[
            {
                "href":"https://orchestration.fr1.cloudwatt.com/v1/d0000000000000000000000000000000/stacks/maStack/70d8f340-3628-474c-8910-df2ddf88997a/resources/server_security_group/events/6f7e2d5f-f7be-4070-be15-3bad32f1d62d",
                "rel":"self"
            },
            {
                "href":"https://orchestration.fr1.cloudwatt.com/v1/d0000000000000000000000000000000/stacks/maStack/70d8f340-3628-474c-8910-df2ddf88997a/resources/server_security_group",
                "rel":"resource"
            },
            {
                "href":"https://orchestration.fr1.cloudwatt.com/v1/d0000000000000000000000000000000/stacks/maStack/70d8f340-3628-474c-8910-df2ddf88997a",
                "rel":"stack"
            }
        ],
        "logical_resource_id":"server_security_group",
        "resource_status_reason":"state changed",
        "resource_status":"CREATE_IN_PROGRESS",
        "physical_resource_id":null,
        "resource_properties":{
            "rules":[
                {
                    "remote_group_id":null,
                    "direction":"ingress",
                    "remote_ip_prefix":"0.0.0.0/0",
                    "protocol":"tcp",
                    "ethertype":"IPv4",
                    "port_range_max":22,
                    "port_range_min":22,
                    "remote_mode":"remote_ip_prefix"
                },
                {
                    "remote_group_id":null,
                    "direction":"ingress",
                    "remote_ip_prefix":"0.0.0.0/0",
                    "protocol":"icmp",
                    "ethertype":"IPv4",
                    "port_range_max":null,
                    "port_range_min":null,
                    "remote_mode":"remote_ip_prefix"
                }
            ],
            "name":"test-security-group",
            "description":"Test group to demonstrate Neutron security group functionality with Heat."
        },
        "id":"6f7e2d5f-f7be-4070-be15-3bad32f1d62d",
        "resource_type":"OS::Neutron::SecurityGroup"
    }
}


Supprimer ou abandonner une stack

Abandonner une stack

En abandonnant une stack, vous pouvez supprimer une stack tout en préservant les ressources déployées :

$ curl -i -X DELETE -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/<nom_de_la_stack>/<id_de_la_stack>/abandon

Exemple :

$ curl -i -X DELETE -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/maStack/70d8f340-3628-474c-8910-df2ddf88997a/abandon

Supprimer une stack

Si vous souhaitez supprimer une stack avec toutes les ressources qui y sont rattachées, utilisez la commande suivante :

$ curl -i -X DELETE -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/<nom_de_la_stack>/<id_de_la_stack>

Exemple :

$ curl -i -X DELETE -H 'Content-Type: application/json' -H 'Accept: application/json' -H "X-Auth-Token:<token>" https://orchestration.fr1.cloudwatt.com/v1/<Tenant_id>/stacks/maStack/70d8f340-3628-474c-8910-df2ddf88997a