Building a basic stack

OpenStack Heat can be used to deploy and configure resources within the OpenStack environment. Heat stacks are deployed using configuration files - in YAML format.

The following section will demonstrate how to deploy a basic stack using the OpenStack modules previously used in this guide. The stack will deploy:

  • A single virtual machine
  • Assigned to existing network
  • Floating IP assigned for external access
  • Cinder volume created, attached and formatted ready for use

Creating a configuration file

To begin creating the configuration file, open your text edit of choice on your workstation - name the file approrpriately e.g. myfirststack.yaml

Stage 1 - Define a stack template

The beginning of a Heat stack template requires the heat_template_version parameter to be set. A description of the stack should also be defined. In your .yaml file, enter the following:

heat_template_version: 2013-05-23
description: >
  Launch a basic Heat stack complete comprised of
  a single VM, with floating IP and Cinder volume.

Stage 2 - Parameters

The next step is to define user-configurable settings to be entered during the stack creation process - in this example we will ask the user to set the size of the created block storage volume, as well as the name of their OpenStack keypair used for access.

Add the following to your .yaml file:

parameters:
  cinder_size:
    type: string
    label: Cinder size
    description: >
      Enter the size in GB of the block
      storage volume you wish to create
  key_name:
    type: string
    label: OpenStack keypair
    description: >
      Enter the name of your OpenStack keypair
      used for access to the virtual machine

Stage 3 - Resources

The next step is to create the resources to be created - we will create:

  • A single virtual machine
  • Attach it to an existing network: primary
  • Create and assign a floating IP
  • Create, attach and format a Cinder volume

Instance creation resource

To begin the resources section - define the instance creation resource, add the following to your .yaml file - the defaults included will work with an Alces OpenStack v1.3.0 environment - networks and image names should be modified for non Alces OpenStack environments.

The following section will -

  • Create the virtual machine, using the centos6.7-cloud image
  • Create using the m1.tiny flavour
  • Add the OpenStack keypair defined in the Parameters section
  • Add the network configuration defined in node01_port
resources:
  node01:
    type: OS::Nova::Server
    properties:
      name: node01
      image: centos.6.7-cloud
      flavor: m1.tiny
      key_name: { get_param: key_name }
      networks:
        - port: { get_resource: node01_port }
      user_data_format: RAW
      user_data: |
        #!bin/bash
        mkfs.ext4 /dev/vdb
        mkdir /mnt/cinder
        mount /dev/vdb /mnt/cinder

  node01_port:
    type: OS::Neutron::Port
    properties:
      network_id: internal
      fixed_ips:
      - subnet_id: internal

Floating IP creation and allocation

To create a temporary floating IP (thus not relying on any existing) and attach it to the node01 instance, add the following to your .yaml template:

  node01_access:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network: public
      port_id: { get_resource: node01_port }

Cinder volume creation/attach

To create and attach the volume to the instance - add the following to your .yaml template:

  volume_create:
    type: OS::Cinder::Volume
    properties:
      size: { get_param: cinder_size }

  volume_attach:
    type: OS::Cinder::VolumeAttachment
    properties:
      volume_id: { get_resource: volume_create }
      instance_uuid: { get_resource: node01 }
      mountpoint: /dev/vdb

Stage 4 - Outputs

The next step is to display the floating IP address of the created instance once stack creation has completed.

Add the following section to your .yaml template to display the floating IP address of your virtual machine:

outputs:
  access_ip:
    description: Access IP for the node01 virtual machine
    value: { get_attr: [ node01, floating_ip_address ] }

Final output

Once complete - your Heat .yaml template should look like the following:

heat_template_version: 2013-05-23
description: >
  Launch a basic Heat stack complete comprised of
  a single VM, with floating IP and Cinder volume.

parameters:
  cinder_size:
    type: string
    label: Cinder size
    description: >
      Enter the size in GB of the block
      storage volume you wish to create
  key_name:
    type: string
    label: OpenStack keypair
    description: >
      Enter the name of your OpenStack keypair
      used for access to the virtual machine

resources:
  node01:
    type: OS::Nova::Server
    properties:
      name: node01
      image: centos.6.7-cloud
      flavor: m1.tiny
      key_name: { get_param: key_name }
      networks:
        - port: { get_resource: node01_port }
      user_data_format: RAW
      user_data: |
        #!bin/bash
        mkfs.ext4 /dev/vdb
        mkdir /mnt/cinder
        mount /dev/vdb /mnt/cinder

  node01_port:
    type: OS::Neutron::Port
    properties:
      network_id: 29946bd3-8e2a-4806-96bc-68cdbf1ef238
      fixed_ips:
      - subnet_id: 0bf4bdaa-09d3-47de-a0e2-590aadcc4728

  node01_access:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network: public
      port_id: { get_resource: node01_port }

  volume_create:
    type: OS::Cinder::Volume
    properties:
      size: { get_param: cinder_size }

  volume_attach:
    type: OS::Cinder::VolumeAttachment
    properties:
      volume_id: { get_resource: volume_create }
      instance_uuid: { get_resource: node01 }
      mountpoint: /dev/vdb

outputs:
  access_ip:
    description: Access IP for the node01 virtual machine
    value: { get_attr: [ node01_access, floating_ip_address ] }