Creating Resources Using a Template (Using the Heat Client)

After the Heat client is installed and configured, you can use this client to create an ECS.

The required operations are as follows:

  1. Compile a Template: A template is a collection of resources and a blueprint for resource orchestration. Before creating a resource, compile a template according to syntax requirements.
  2. Create Resources: To create an ECS, run commands on the Heat client to create an ECS stack.
  3. View Resources: To view resources, run commands on the Heat client to view all resource stacks and details of a specified resource stack.
  4. Delete Resources: To delete resources, run commands on the Heat client to delete the resource stack if the stack is no longer used.

Compile a Template

Create a template and name it server_instance.yaml. The template content is as follows:

heat_template_version: 2014-10-16
description: Create a simple ECS instance.
parameters:
  name:
    type: string
    description: Specifies the ECS name.
  image: 
    type: string 
    description: Specifies the image used for creating ECS. The value can be the name or ID of the image.
  flavor: 
    type: string 
    description: Specifies the flavor used for creating ECS.
  key: 
    type: string 
    description: Specifies the key pair used for creating ECS. The value can be the name of the key pair. 
  network_id: 
    type: string 
    description: Specifies the network used for creating ECS. The value can be the name or ID of the network.
  availability_zone:
    type: string
    description: Specifies the name of the AZ to which the ECS belong.

resources:
  nova_serer:
    type: OS::Nova::Server
    properties:
      name: { get_param: name }
      image: { get_param: image } 
      flavor: { get_param: flavor } 
      key_name: { get_param: key } 
      networks: 
        - network: { get_param: network_id }
      availability_zone: { get_param: availability_zone } 

This YAML file contains four first-level fields:

Create Resources

Run the following command on the Heat client to create a resource stack:

heat stack-create -f server_instance.yaml -P 'name=ecs_name;image=Redhat-6.9;flavor=m1.medium;key=keypair_name;network_id=external-network3;availability_zone=az_name' ecsStack

In this command,

View Resources

Perform the following operations to check whether the resource stack is created:
  • Run the following command to query all stacks and check whether the new stack is included:

    heat stack-list

  • (Optional) Run the following command to view details of the new stack:

    heat stack-show ecsStack

Delete Resources

If you do not need a resource stack any longer, run the following command to delete it:

heat stack-delete ecsStack