Openstack instance deployment using HOT {Heat Orchestration Template} Part-I

HOT is a new template format meant to orchestrate the Openstack platform as its reliable and templates are defined in YAML and follow the structure outlined below:

heat_template_version: 2015-10-15

description:
  # a description of the template

parameter_groups:
  # a declaration of input parameter groups and order

parameters:
  # declaration of input parameters

resources:
  # declaration of template resources

outputs:
  # declaration of output parameters

conditions:
  # declaration of conditions


Important keywords to write a HOT {Heat Orchestration Template} templates are as :

  •   heat_template_version
  •   description
  •   parameter_groups
  •   parameters
  •   resources
  •   outputs
  •   conditions


heat_template_version:
This key with value 2015-10-15 (or a later date) indicates that the YAML document is a HOT template of the specified version.

description:
This optional key allows for giving a description of the template, or the workload that can be deployed using the template.

parameter_groups:
This section allows for specifying how the input parameters should be grouped and the order to provide the parameters in. This section is optional and can be omitted when necessary.

parameters:
This section allows for specifying input parameters that have to be provided when instantiating the template. The section is optional and can be omitted when no input is required.

resources:
This section contains the declaration of the single resources of the template. This section with at least one resource should be defined in any HOT template, or the template would not really do anything when being instantiated.

outputs:
This section allows for specifying output parameters available to users once the template has been instantiated. This section is optional and can be omitted when no output values are required.

conditions:
This optional section includes statements which can be used to restrict when a resource is created or when a property is defined. They can be associated with resources and resource properties in the resources section, also can be associated with outputs in the outputs sections of a template.

NOTE: There is no need to use all the above in every template. by using few of them also its possible to create a hot template.

Lets write a hot template to deploy an instance:


heat_template_version: 2015-10-15

description: Deploy Ubuntu 16.04 LTS Cloud image through HOT

parameters:
  key_name:
    type: string
    label: Keypair Name
    description: Name of the key pair to be used for the compute instance
    default: loginkey
 
  image_ID1:
    type: string
    label: instance0
    description: Define an image ID
    default: Ubuntu 16.04 LTS Cloud Image
 
  fixed_net:
    type: string
    label: Private Network ID
    description: Network to be used for the compute instance
    default: e37521f5-4b86-4678-8f61-0cf8423469de
 
  fixed_subnet:
    type: string
    label: Subnet ID
    description: Subnet to be used for the compute instance
    default: 98b51ded-547d-48d4-8a21-c520d3ba36fd
 
  external_net:
    type: string
    label: Public Network ID
    description: Floating IP network to be used for compute instance
    default: 4fec620d-e61b-4c76-be22-a0de0a92bd41
 
  availability_zone:
    type: string
    description: The Availability Zone to launch the instance.
    default: nova

resources:
  secgrp_id:
    type: OS::Neutron::SecurityGroup
    properties:
      name: "Ubuntu16.04 SecGrp"
      rules:
        - remote_ip_prefix: 0.0.0.0/0
          protocol: icmp
        - remote_ip_prefix: 0.0.0.0/0
          protocol: tcp
          port_range_min: 1
          port_range_max: 65535
 
  public_port1:
    type: OS::Neutron::Port
    properties:
      network_id: { get_param: fixed_net }
      fixed_ips:
      - subnet_id: { get_param: fixed_subnet }
      security_groups:
      - {get_resource: secgrp_id}
  floating_ip1:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network_id: { get_param: external_net }
      port_id: { get_resource: public_port1 }
 
  Ubuntu1604_instance:
    type: OS::Nova::Server
    properties:
      availability_zone: { get_param: availability_zone }
      name: "Ubuntu 16.04 LTS Server"
      key_name: { get_param: key_name }
      block_device_mapping: [{ device_name: "vda", volume_id : {    get_resource : Ubuntu16.04_Disk }, delete_on_termination : "true" }]
      flavor: "m1.small"
      networks:
        - port: { get_resource: public_port1 }
  Ubuntu16.04_Disk:
    type: OS::Cinder::Volume
    properties:
      name: "U16.04 Disk"
      image: { get_param: image_ID1 }
      size: 20

NOTE: Make sure to replace the following parameters correctly as per your infrastructure:

  • flavour
  • keypair
  • image_ID
  • fixed_net ID
  • fixed_subnet ID
  • external_net ID

Mirantis openstack is having an option to load the stack from horizon and deploy the instance and in this example I am using Mirantis Openstack's dashboard. But the same can be done from command line as well:

1. Login to openstack horizon using your credentials and go to Orchestration -> Stack:


2. Click on "Launch Stack" and select "Direct Input" option in Template Source:

3. Add the heat template and click on "Next". Give a name to your stack and provide the password to the user from which you are trying to deploy the template. It should show you all the variable that you have added as per your environment.


4.  Wait for 2/3 mins and the instance creation should be completed. The deployment time depends on the size of the HDD.

5. Go to the instance tab to see the newly created instance. Now to access the instance:
  • get the floating IP from the console
  • use the available keypair and do ssh to the instance
6. Once utilization is over, you can "Suspend Stacks" the instance from "Orchestration -> Stacks" tab and for next requirement you can "Resume Stacks" it:



NOTE: This deployment is not fully automated. You need to add few parameters manually in the template based on your setup.

Comments

Popular posts from this blog

How to build Ubuntu Server 20.04 LTS OVA with vAPP Properties ?

VNC Configuration using Ansible in CentOS 7

[RHOSP] Red Hat Openstack 11 Deployment on Nested KVM Infrastructure