Skip to main content

Openstack Orchestration - Heat




After having struggled through with various building blocks of OpenStack, Heat was a great relief. It's installation and integration was pretty smooth.
One of the most helpful documents was this one.

By definition

"The Orchestration service provides a template-based orchestration for describing a cloud application by running OpenStack API calls to generate running cloud applications."

The templates enable you to create most OpenStack resource types, such as instances, floating IPs, volumes, security groups, users, and so on. Also, provides some more advanced functionality, such as instance high availability, instance auto-scaling, and nested stacks. By providing very tight integration with other OpenStack core projects, all OpenStack core projects could receive a larger user base.

Components of the Orchestration service


  • heat command-line client. A CLI that communicates with the heat-api to run AWS CloudFormation APIs. End developers could also use the Orchestration REST API directly.
  • heat-api component. Provides an OpenStack-native REST API that processes API requests by sending them to the heat-engine over RPC.
  • heat-api-cfn component. Provides an AWS Query API that is compatible with AWS CloudFormation and processes API requests by sending them to the heat-engine over RPC.
  • heat-engine. Orchestrates the launching of templates and provides events back to the API consumer.

Installation


Installing in the controller node


  1. yum install openstack-heat-api openstack-heat-engine openstack-heat-api- cfn  

Edit the heat.conf file in /etc/heat/ directory. And the

sql_connection=mysql://heat:heat@controller/heat

Going into the database to create the heat database and give it the privileges.



  1. $ mysql -u root -p  
  2. mysql> CREATE DATABASE heat;  
  3. mysql> GRANT ALL PRIVILEGES ON heat.* TO 'heat'@'localhost' \  
  4. IDENTIFIED BY 'HEAT_DBPASS';  
  5. mysql> GRANT ALL PRIVILEGES ON heat.* TO 'heat'@'%' \  
  6. IDENTIFIED BY 'HEAT_DBPASS';  

The tables in the database get created using the below command

  1. heat-manage db_sync  

there are some DeprecationWarning errors, which can be ignored.

/usr/lib64/python2.6/site-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/pool.py:683: SADeprecationWarning: The 'listeners' argument to Pool (and create_engine()) is deprecated.  Use event.listen().
  Pool.__init__(self, creator, **kw)
/usr/lib64/python2.6/site-packages/SQLAlchemy-0.7.8-py2.6-linux-x86_64.egg/sqlalchemy/pool.py:159: SADeprecationWarning: Pool.add_listener is deprecated.  Use event.listen()
  self.add_listener(l)

creating the heat user and registering the service

  1. keystone user-create --name=heat --pass=HEAT_PASS --email=heat@example.com  
  2. $ keystone user-role-add --user=heat --tenant=service --role=admin  


And edit the heat.conf file to change the [keystone_authtoken] and [ec2_authtoken] section

[keystone_authtoken]
auth_host = controller
auth_port = 35357
auth_protocol = http
auth_uri = http://controller:5000/v2.0 admin_tenant_name = service admin_user = heat
admin_password = HEAT_PASS
[ec2_authtoken]



now registering the heat and cloudformations API with keystone so that other openstack services can locate these APIs.

  1. $ keystone service-create --name=heat --type=orchestration \  
  2.   --description="Orchestration"  
  3. $ keystone endpoint-create \  
  4.   --service-id= <service_id from above> \  
  5.   --publicurl=http://controller:8004/v1/%\(tenant_id\)s \  
  6.   --internalurl=http://controller:8004/v1/%\(tenant_id\)s \  
  7.   --adminurl=http://controller:8004/v1/%\(tenant_id\)s  



Now registering the service and creating the endpoints for heat-cfn

  1. $ keystone service-create --name=heat-cfn --type=cloudformation \  
  2.   --description="Orchestration CloudFormation"  
  3. $ keystone endpoint-create \  
  4.  --service-id=<service_id from above> \  
  5.   --publicurl=http://controller:8000/v1 \  
  6.   --internalurl=http://controller:8000/v1 \  
  7.   --adminurl=http://controller:8000/v1  



Now starting all these services and ensuring that they will start in case of a reboot.

  1. # service openstack-heat-api start  
  2. # service openstack-heat-api-cfn start   
  3. # service openstack-heat-engine start   
  4. # chkconfig openstack-heat-api on  
  5. # chkconfig openstack-heat-api-cfn on   
  6. # chkconfig openstack-heat-engine on  



Verifying the installation


After having sourced the credentials

We will be using this hello_world yaml template and place it in the home folder of controller and run the following controls

  1. # This is a hello world HOT template just defining a single compute instance  
  2. heat_template_version: 2013-05-23  
  3.   
  4.   
  5. description: >  
  6.   Hello world HOT template that just defines a single compute instance.  
  7.   Contains just base features to verify base HOT support.  
  8.   
  9.   
  10. parameters:  
  11.   KeyName:  
  12.     type: string  
  13.     description: Name of an existing key pair to use for the instance  
  14.   InstanceType:  
  15.     type: string  
  16.     description: Instance type for the instance to be created  
  17.     default: m1.small  
  18.     constraints:  
  19.       - allowed_values: [m1.tiny, m1.small, m1.large]  
  20.         description: Value must be one of 'm1.tiny', 'm1.small' or 'm1.large'  
  21.   ImageId:  
  22.     type: string  
  23.     description: ID of the image to use for the instance  
  24.   # parameters below are not used in template, but are for verifying parameter  
  25.   # validation support in HOT  
  26.   
  27.   
  28. resources:  
  29.   my_instance:  
  30.     # Use an AWS resource type since this exists; so why use other name here?  
  31.     type: AWS::EC2::Instance  
  32.     properties:  
  33.       KeyName: { get_param: KeyName }  
  34.       ImageId: { get_param: ImageId }  
  35.       InstanceType: { get_param: InstanceType }  
  36.   
  37.   
  38. outputs:  
  39.   instance_ip:  
  40.     description: The IP address of the deployed instance  
  41.     value: { get_attr: [my_instance, PublicIp] }  


And run the following command to check if all is well on the template file that is being fed.
  
  1. heat stack-create teststack --template-file=test1.yaml  

in case there is a problem with the template file, the following error shows up

ERROR: 'unicode' object has no attribute 'iteritems'

Now for the magic of openstack to work

  1. heat stack-update mystack --template-file=hello_world.yaml --parameters="KeyName=mykey;InstanceType=m1.large;ImageId=4e443a9c-40d7-4700-8fd4-6ef42e4e3792"  



Other helpful commands in heat


  1. heat stack-create mystack --template-file=hello_world.yaml --parameters="KeyName=mykey;InstanceType=m1.small;ImageId=4e443a9c-40d7-4700-8fd4-6ef42e4e3792"  

# This is a hello world HOT template just defining a single compute instance

+--------------------------------------+------------+--------------------+----------------------+
| id                                   | stack_name | stack_status       | creation_time        |
+--------------------------------------+------------+--------------------+----------------------+
| 022888cf-4bcd-4335-aaaa-6b0e8f712a55 | mystack    | CREATE_IN_PROGRESS | 2014-06-05T05:58:40Z |
+--------------------------------------+------------+--------------------+----------------------+

  1. heat stack-list  

+--------------------------------------+------------+-----------------+----------------------+
| id                                   | stack_name | stack_status    | creation_time        |
+--------------------------------------+------------+-----------------+----------------------+
| 022888cf-4bcd-4335-aaaa-6b0e8f712a55 | mystack    | CREATE_COMPLETE | 2014-06-05T05:58:40Z |
+--------------------------------------+------------+-----------------+----------------------+

  1. heat stack-show mystack  

+----------------------+--------------------------------------------------------------------------------------------------------------------------------+
| Property             | Value                                                                                                                          |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------+
| capabilities         | []                                                                                                                             |
| creation_time        | 2014-06-05T05:58:40Z                                                                                                           |
| description          | Hello world HOT template that just defines a single                                                                            |
|                      | compute instance. Contains just base features to verify                                                                        |
|                      | base HOT support.                                                                                                              |
| disable_rollback     | True                                                                                                                           |
| id                   | 022888cf-4bcd-4335-aaaa-6b0e8f712a55                                                                                           |
| links                | http://controller:8004/v1/02e0307cf9cd448f8039afd61498d48b/stacks/mystack/022888cf-4bcd-4335-aaaa-6b0e8f712a55                 |
| notification_topics  | []                                                                                                                             |
| outputs              | [                                                                                                                              |
|                      |   {                                                                                                                            |
|                      |     "output_value": "10.0.0.4",                                                                                                |
|                      |     "description": "The IP address of the deployed instance",                                                                  |
|                      |     "output_key": "instance_ip"                                                                                                |
|                      |   }                                                                                                                            |
|                      | ]                                                                                                                              |
| parameters           | {                                                                                                                              |
|                      |   "AWS::StackName": "mystack",                                                                                                 |
|                      |   "ImageId": "4e443a9c-40d7-4700-8fd4-6ef42e4e3792",                                                                           |
|                      |   "AWS::StackId": "arn:openstack:heat::02e0307cf9cd448f8039afd61498d48b:stacks/mystack/022888cf-4bcd-4335-aaaa-6b0e8f712a55",  |
|                      |   "KeyName": "mykey",                                                                                                          |
|                      |   "AWS::Region": "ap-southeast-1",                                                                                             |
|                      |   "InstanceType": "m1.small"                                                                                                   |
|                      | }                                                                                                                              |
| stack_name           | mystack                                                                                                                        |
| stack_status         | CREATE_COMPLETE                                                                                                                |
| stack_status_reason  | Stack create completed successfully                                                                                            |
| template_description | Hello world HOT template that just defines a single                                                                            |
|                      | compute instance. Contains just base features to verify                                                                        |
|                      | base HOT support.                                                                                                              |
| timeout_mins         | 60                                                                                                                             |
| updated_time         | 2014-06-05T05:59:40Z                                                                                                           |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------+

  1. heat resource-list mystack  
+---------------+--------------------+-----------------+----------------------+
| resource_name | resource_type      | resource_status | updated_time         |
+---------------+--------------------+-----------------+----------------------+
| my_instance   | AWS::EC2::Instance | CREATE_COMPLETE | 2014-06-05T05:59:40Z |
+---------------+--------------------+-----------------+----------------------+


  1. [root@controller ~]# heat resource-show mystack my_instance  

+------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Property               | Value                                                                                                                                |
# This is a hello world HOT template just defining a single compute instance
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| description            |                                                                                                                                      |
|                        | http://controller:8004/v1/02e0307cf9cd448f8039afd61498d48b/stacks/mystack/022888cf-4bcd-4335-aaaa-6b0e8f712a55                       |
| logical_resource_id    | my_instance                                                                                                                          |
| physical_resource_id   | 3eba3496-fb77-474f-9c04-1663fda8d958                                                                                                 |
| required_by            |                                                                                                                                      |
| resource_name          | my_instance                                                                                                                          |
| resource_status        | CREATE_COMPLETE                                                                                                                      |
| resource_status_reason | state changed                                                                                                                        |
| resource_type          | AWS::EC2::Instance                                                                                                                   |
| updated_time           | 2014-06-05T05:59:40Z                                                                                                                 |
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------+


  1. heat resource-metadata mystack my_instance  
{}

  1. heat event-list mystack  
+---------------+----+------------------------+--------------------+----------------------+
| resource_name | id | resource_status_reason | resource_status    | event_time           |
+---------------+----+------------------------+--------------------+----------------------+
| my_instance   | 1  | state changed          | CREATE_IN_PROGRESS | 2014-06-05T05:58:40Z |
| my_instance   | 2  | state changed          | CREATE_COMPLETE    | 2014-06-05T05:59:40Z |
+---------------+----+------------------------+--------------------+----------------------+


  1. heat stack-update mystack --template-file=hello_world.yaml --parameters="KeyName=mykey;InstanceType=m1.large;ImageId=4e443a9c-40d7-4700-8fd4-6ef42e4e3792"  
+--------------------------------------+------------+--------------------+----------------------+
| id                                   | stack_name | stack_status       | creation_time        |
+--------------------------------------+------------+--------------------+----------------------+
| 022888cf-4bcd-4335-aaaa-6b0e8f712a55 | mystack    | UPDATE_IN_PROGRESS | 2014-06-05T05:58:40Z |
+--------------------------------------+------------+--------------------+----------------------+

  1. heat event-list mystack  
+---------------+----+-------------------------------------------------------+--------------------+----------------------+
| resource_name | id | resource_status_reason                                | resource_status    | event_time           |
+---------------+----+-------------------------------------------------------+--------------------+----------------------+
| my_instance   | 1  | state changed                                         | CREATE_IN_PROGRESS | 2014-06-05T05:58:40Z |
| my_instance   | 2  | state changed                                         | CREATE_COMPLETE    | 2014-06-05T05:59:40Z |
| my_instance   | 3  | state changed                                         | UPDATE_IN_PROGRESS | 2014-06-05T06:14:19Z |
| my_instance   | 4  | Error: Resizing to 'm1.large' failed, status 'ACTIVE' | UPDATE_FAILED      | 2014-06-05T06:14:21Z |
+---------------+----+-------------------------------------------------------+--------------------+----------------------+

Popular posts from this blog

Ansible - Error - stderr: E: There are problems and -y was used without --force-yes

Error: SMTPIN_ADDED_BROKEN@mx.google.com