CLI : 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 : cc2e31fc-c24d-4905-bb45-1d57794a4f3c)
  • Le type d’instance : nous utiliserons le type n1.cw.standard-2 (id : 22)
  • L’id du réseau à utiliser (pour rappel vous pouvez récupérer la liste des réseaux avec la commande neutron net-list)
  • L’id du sous-réseau à utiliser (pour rappel vous pouvez récupérer la liste des sous-résaux avec la commande neutron subnet-list)

Maintenant pour créer une stack vous pouvez utiliser la commande suivante :

$ heat stack-create maStack --template-file=https://raw.githubusercontent.com/cloudwatt/openstack-heat-templates/master/Exemples/servers_in_existing_neutron_network_no_floating_ips.hot --parameters="key_name=macle;image=edffd57d-82bf-4ffe-b9e8-af22563741bf;flavor=22;net_id=aadb35f3-2d04-4548-aad9-eeb6d33de603;subnet_id=55c72d79-1cf9-4786-a389-f34895b9d349"

La valeur --parameters (ou -P) permet de spécifier les paramètres définis dans le fichier HOT.

Résultat :

+--------------------------------------+------------+--------------------+----------------------+
| id                                   | stack_name | stack_status       | creation_time        |
+--------------------------------------+------------+--------------------+----------------------+
| fda0a251-e0b7-492c-9cd9-3bdf6f715b69 | maStack    | CREATE_IN_PROGRESS | 2014-08-11T08:17:08Z |
+--------------------------------------+------------+--------------------+----------------------+

Retrouvez toutes les options en utilisant la commande :

$ heat help stack-create
usage: heat stack-create [-f <FILE>] [-e <FILE or URL>] [-u <URL>] [-o <URL>]
                         [-c <TIMEOUT>] [-r] [-P <KEY1=VALUE1;KEY2=VALUE2...>]
                         <STACK_NAME>

Create the stack.

Positional arguments:
  <STACK_NAME>          Name of the stack to create.

Optional arguments:
  -f <FILE>, --template-file <FILE>
                        Path to the template.
  -e <FILE or URL>, --environment-file <FILE or URL>
                        Path to the environment.
  -u <URL>, --template-url <URL>
                        URL of template.
  -o <URL>, --template-object <URL>
                        URL to retrieve template object (e.g. from swift).
  -c <TIMEOUT>, --create-timeout <TIMEOUT>
                        Stack creation timeout in minutes. Default: 60.
  -r, --enable-rollback
                        Enable rollback on create/update failure.
  -P <KEY1=VALUE1;KEY2=VALUE2...>, --parameters <KEY1=VALUE1;KEY2=VALUE2...>
                        Parameter values used to create the stack. This can be
                        specified multiple times, or once with parameters
                        separated by a semicolon.

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

$ heat template-validate --template-file=https://raw.githubusercontent.com/cloudwatt/openstack-heat-templates/master/Exemples/servers_in_existing_neutron_network_no_floating_ips.hot

Résultat :

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

$ heat stack-update maStack --template-file=https://raw.githubusercontent.com/cloudwatt/openstack-heat-templates/master/Exemples/servers_in_existing_neutron_network_no_floating_ips.hot --parameters="key_name=macle;image=edffd57d-82bf-4ffe-b9e8-af22563741bf;flavor=23;net_id=aadb35f3-2d04-4548-aad9-eeb6d33de603;subnet_id=55c72d79-1cf9-4786-a389-f34895b9d349"

Résultat :

+--------------------------------------+------------+--------------------+----------------------+
| id                                   | stack_name | stack_status       | creation_time        |
+--------------------------------------+------------+--------------------+----------------------+
| fda0a251-e0b7-492c-9cd9-3bdf6f715b69 | maStack    | UPDATE_COMPLETE    | 2014-08-11T08:17:08Z |
+--------------------------------------+------------+--------------------+----------------------+

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 :

$ heat stack-list

Réponse :

+--------------------------------------+------------+-----------------+----------------------+
| id                                   | stack_name | stack_status    | creation_time        |
+--------------------------------------+------------+-----------------+----------------------+
| fda0a251-e0b7-492c-9cd9-3bdf6f715b69 | maStack    | CREATE_COMPLETE | 2014-08-11T08:17:08Z |
+--------------------------------------+------------+-----------------+----------------------+

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

$ heat stack-show maStack

Réponse :

+----------------------+-----------------------------------------------------------------------------------------------------------------------+
| Property             | Value                                                                                                                 |
+----------------------+-----------------------------------------------------------------------------------------------------------------------+
| capabilities         | []                                                                                                                    |
| creation_time        | 2014-08-11T08:17:08Z                                                                                                  |
| description          | HOT template to deploy two servers to an existing                                                                     |
|                      | Neutron network.                                                                                                      |
| disable_rollback     | True                                                                                                                  |
| id                   | fda0a251-e0b7-492c-9cd9-3bdf6f715b69                                                                                  |
| links                | http://orchestration.fr1.cloudwatt.com/v1/dd000000000000000000000000000000/stacks/maStack/fda0a251-e0b7-492c-9cd9-3bdf6f715b69 |
| notification_topics  | []                                                                                                                    |
| 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.252",                                                                                  |
|                      |     "description": "IP address of server2 in provider network",                                                       |
|                      |     "output_key": "server2_provider_ip"                                                                               |
|                      |   }                                                                                                                   |
|                      | ]                                                                                                                     |
| parameters           | {                                                                                                                     |
|                      |   "OS::stack_id": "fda0a251-e0b7-492c-9cd9-3bdf6f715b69",                                                             |
|                      |   "OS::stack_name": "maStack",                                                                                        |
|                      |   "subnet_id": "55c72d79-1cf9-4786-a389-f34895b9d349",                                                                |
|                      |   "key_name": "macle",                                                                                                |
|                      |   "image": "edffd57d-82bf-4ffe-b9e8-af22563741bf",                                                                    |
|                      |   "flavor": "22",                                                                                                     |
|                      |   "net_id": "aadb35f3-2d04-4548-aad9-eeb6d33de603"                                                                    |
|                      | }                                                                                                                     | 
| stack_name           | maStack                                                                                                               |
| stack_status         | CREATE_COMPLETE                                                                                                       |
| stack_status_reason  | Stack CREATE completed successfully                                                                                   |
| template_description | HOT template to deploy two servers to an existing                                                                     |
|                      | Neutron network.                                                                                                      |
| timeout_mins         | 60                                                                                                                    |
| updated_time         | None                                                                                                                  |
+----------------------+-----------------------------------------------------------------------------------------------------------------------+

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 la commande :

$ heat event-list maStack

ou en utilisant l’ID de la stack :

$ heat event-list fda0a251-e0b7-492c-9cd9-3bdf6f715b69

Résultat :

+-----------------------+--------------------------------------+------------------------+--------------------+----------------------+
| resource_name         | id                                   | resource_status_reason | resource_status    | event_time           |
+-----------------------+--------------------------------------+------------------------+--------------------+----------------------+
| server_security_group | 24368edb-f6d7-4fe9-92bf-7c58280162f1 | state changed          | CREATE_IN_PROGRESS | 2014-08-11T12:34:08Z |
| server_security_group | 0cfecd1a-35e9-4fd3-8093-a9d6f208f6b3 | state changed          | CREATE_COMPLETE    | 2014-08-11T12:34:09Z |
| server2_port          | 3c9ebda8-52b2-4c88-8dc9-fb5f1eff90ac | state changed          | CREATE_IN_PROGRESS | 2014-08-11T12:34:09Z |
| server1_port          | 78147f5d-1f3d-4148-95b3-5fb1f920e664 | state changed          | CREATE_IN_PROGRESS | 2014-08-11T12:34:09Z |
| server2_port          | e1ff925d-df16-458c-b87b-f2717bd6f74d | state changed          | CREATE_COMPLETE    | 2014-08-11T12:34:11Z |
| server1_port          | cdef271f-5482-4852-9cff-9223950d5691 | state changed          | CREATE_COMPLETE    | 2014-08-11T12:34:11Z |
| server1               | 6951a277-f202-4e7c-9f01-6a4e88f933cf | state changed          | CREATE_IN_PROGRESS | 2014-08-11T12:34:11Z |
| server2               | 4f288aeb-2566-409d-8317-50d1bae632ac | state changed          | CREATE_IN_PROGRESS | 2014-08-11T12:34:15Z |
+-----------------------+--------------------------------------+------------------------+--------------------+----------------------+

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

$ heat event-show maStack server_security_group 24368edb-f6d7-4fe9-92bf-7c58280162f1

Résultat :

+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Property               | Value                                                                                                                                                                                             |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| event_time             | 2014-08-11T12:34:08Z                                                                                                                                                                              |
| id                     | 24368edb-f6d7-4fe9-92bf-7c58280162f1                                                                                                                                                              |
| links                  | http://orchestration.fr1.cloudwatt.com/v1/dd000000000000000000000000000000/stacks/maStack/bba9d389-1ee0-42f6-95d2-65bf738888d3/resources/server_security_group/events/24368edb-f6d7-4fe9-92bf-7c58280162f1 |
|                        | http://orchestration.fr1.cloudwatt.com/v1/dd000000000000000000000000000000/stacks/maStack/bba9d389-1ee0-42f6-95d2-65bf738888d3/resources/server_security_group                                             |
|                        | http://orchestration.fr1.cloudwatt.com/v1/dd000000000000000000000000000000/stacks/maStack/bba9d389-1ee0-42f6-95d2-65bf738888d3                                                                             |
| logical_resource_id    | server_security_group                                                                                                                                                                             |
| physical_resource_id   | None                                                                                                                                                                                              |
| resource_name          | server_security_group                                                                                                                                                                             |
| 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."                                                                                                      |
|                        | }                                                                                                                                                                                                 |
| resource_status        | CREATE_IN_PROGRESS                                                                                                                                                                                |
| resource_status_reason | state changed                                                                                                                                                                                     |
| 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 :

$ heat stack-abandon maStack

Supprimer une stack

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

$ heat stack-delete maStack

résultat :

+--------------------------------------+------------+--------------------+----------------------+
| id                                   | stack_name | stack_status       | creation_time        |
+--------------------------------------+------------+--------------------+----------------------+
| acb4b6ed-d260-49a4-95b8-0840724cff0f | maStack    | DELETE_IN_PROGRESS | 2014-08-11T12:09:27Z |
+--------------------------------------+------------+--------------------+----------------------+