OpenStack Heat服务介绍


http://zhenhua2000.blog.51cto.com/3167594/1324883

这篇博文开始介绍一下OpenStack中的Orchestration Service:Heat

Orchestration词对一部分人也许还很陌生。Wikipedia上的解theautomated arrangement, coordination, and management of complex computersystems, middleware, andservices.”。我个人的理解就是自动化部署应用,自动化管理应用的整个生命周期 。


对于云计算来说,自动化管理是一个必不可少的部分。AWS的EC2是通过提供CloudFormation格式的模版来实现Orchestration Heat是这部分功能的开源实现。Heat不仅100%兼容CloudFormation格式,同时支持自己的Hot (Heat Orchestration Template)格式。


如果Nova, Glance, Neutron解决的是IaaS层的需要,那从上面的图你就能感觉到Heat 是解决客户PaaS层的需要。OpenStack作为云平台是需要让应用程序能够部署和运行的。Heat提供了一个框架来解决这类问题,其中的核心就是App Template。


我想把介绍Heat 的文章分成以下几个部分:

1.Heat的安装,配置以及核心概念

2.Heat的模版介绍

3.Heat和Puppet部署应用的案例介绍

4.Heat和Ceilometer之间的关系

5.Heat的源码介绍

Heat的安装,配置以及核心概念


Heat独立的模建立在其他模之上。Havana版中主要与Heat交互的模NovaCeilometer。下一版本Ice House还会有Swift,Glance, Neutron


安装和配置篇

推荐的安装方式是用RedhatpackstackUbuntuJuju直接安装,因HeatHavana 版本已是正式的模了。我主要用的是Redhat RDO,所以一条命令就能搞定。

packstack--install-hosts=x.x.x.x,x.x.x.x--os-heat-install=y


如果你是在Grizzly版上装就只能手安装了。

  1. gitclone git://github.com/openstack/heat.git

  2. cd heat; gitcheckout remotes/origin/stable/grizzly

  3. git checkout–b grizzly

  4. yum install -y libxslt-develpython-devel gcc python-pip

  5. pythonsetup.py install

  6. ./install.sh


配置Heat

  1. yum install -ypython-paste-deploy.noarch python-routes.noarch

  2. source/root/keystonerc_admin

  3. 打开heat/bin/heat-keystone-setup,修改201:
    SERVICE_TENANT=$(get_data 2 service 1keystone tenant-list)
    to:
    SERVICE_TENANT=$(get_data 2 services 1keystone tenant-list)

  4. heat/bin/heat-keystone-setupheat

  5. 'catpackstack-answers-20130912-124830.txt |grep MYSQL'. 拿到mysql的密个用来创建heat的数据.

    CONFIG_MYSQL_PW=4ad9837a8e5e473a

  6. heat/bin/heat-db-setup rpm. 脚本会入密,在个例子里面密码就 '4ad9837a8e5e473a'.

1
2
3
4
5
6
7
8
Installing on an RPM system.
Please enter the password for the 'root' MySQL user:
Verified connectivity to MySQL.
Creating 'heat' database.
/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()) isdeprecated.  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)


7.

1
`cat keystonerc_admin |grep OS_PASSWORD`, 修改/etc/heat/heat-api-paste.ini:

admin_tenant_name= services <-- orignial it is 'service'
admin_password =7d1642ae2c1c4aff

8. 修改/etc/heat/heat-api-cfn-paste.ini/etc/heat/heat-api-cloudwatch-paste.ini里的admin_tenant_name and admin_password.

9. heat-engine.conf中的heat_metadata_server_url,heat_waitcondition_server_url, heat_watch_server_url127.0.0.1改成你机器的外网ip

10. yum install -y python-heatclient

11. Heat:

heat-api &

heat-engine &

heat-api-cfn &

heat-cloud-watch &


启动第一个stack

Stack这个概念来源于AWS,Stack管理的是resource。而resource是个抽象的概念,它可以是虚拟机,可以是网络等等。Stack就是Heat管理应用程序的逻辑单元。

1. 从http://fedorapeople.org/groups/heat/prebuilt-jeos-images/中下载F17-x86_64-cfntools.qcow2, 然后用glance把它导入:

glanceimage-create --name=F17-x86_64-cfntools --disk-format=qcow2--container-format=bare < /var/lib/libvirt/images/F17-x86_64-cfntools.qcow2

2. 通过Horizon或者命令行注册一个SSH key-pair,下面的例子生成root_key

novakeypair-add --pub_key ~/.ssh/id_rsa.pub root_key

3. git clone https://github.com/openstack/heat-templates.git', 从这里可以下载很多heat的参考模版

4. 创建名为demo的Stack

1
heatstack-create demo --template- file = /root/heat-templates/cfn/F17/getting_started .template --parameters= "KeyName=root_key"

5. 观察stack启动的状态

1
2
3
4
5
6
# heat list
+--------------------------------------+------------+-----------------+----------------------+
| id                                   | stack_name | stack_status    | creation_time        |
+--------------------------------------+------------+-----------------+----------------------+
| 543b64c7-3165-4939-a249-ba68d8cb54b0 | demo       | CREATE_COMPLETE | 2013-10-21T10:03:06Z |
+--------------------------------------+------------+-----------------+----------------------+


1
2
3
4
5
6
7
8
9
10
11
12
13
heat resource-list 543b64c7-3165-4939-a249-ba68d8cb54b0
+---------------------+---------------------------------------+-----------------+----------------------+
| logical_resource_id | resource_type                         | resource_status | updated_time         |
+---------------------+---------------------------------------+-----------------+----------------------+
| JsmLaunchConfig     | AWS::AutoScaling::LaunchConfiguration | CREATE_COMPLETE | 2013-10-21T10:03:06Z |
| CfnUser             | AWS::IAM::User                        | CREATE_COMPLETE | 2013-10-21T10:03:07Z |
| VcsKeys             | AWS::IAM::AccessKey                   | CREATE_COMPLETE | 2013-10-21T10:03:17Z |
| CPUAlarmHigh        | AWS::CloudWatch::Alarm                | CREATE_COMPLETE | 2013-10-21T10:03:35Z |
| CPUAlarmLow         | AWS::CloudWatch::Alarm                | CREATE_COMPLETE | 2013-10-21T10:03:35Z |
| JsmScaleUpPolicy    | AWS::AutoScaling::ScalingPolicy       | CREATE_COMPLETE | 2013-10-21T11:13:20Z |
| VM                  | AWS::AutoScaling::AutoScalingGroup    | CREATE_COMPLETE | 2013-10-21T11:18:55Z |
| JsmScaleDownPolicy  | AWS::AutoScaling::ScalingPolicy       | CREATE_COMPLETE | 2013-10-28T12:52:40Z |
+---------------------+---------------------------------------+-----------------+----------------------+


本文出自 “专注Linux开发” 博客,请务必保留此出处http://zhenhua2000.blog.51cto.com/3167594/1324918

Heat是OpenStack中的Orchestration services,也就是应用程序的配置管理。

Heat用声明式的方法来管理公有云或者私有云中的应用程序。它和其他OpenStack的服务类似,对外提供ReSTful接口,但除此之外,它定义了一套配置管理的模版。Heat的模版才是Heat的核心所在。


因为OpenStack开发Heat一开始的目的是为了能支持AWS中的CloudFormation模版,所以很多术语和概念都来源于AWS的CloudFormation(http://awsdocs.s3.amazonaws.com/AWSCloudFormation/latest/cfn-ug.pdf)


让我们先从CloudFormation格式的getting_started.template 来介绍其中的几个关键概念。

https://github.com/openstack/heat-templates/blob/master/cfn/F17/getting_started.template


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
   "AWSTemplateFormatVersion" : "2010-09-09" ,
   "Parameters" : {
     "KeyName" : {
       "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance" ,
       "Type" : "String"
     }
   },
   "Resources" : {
     "MyInstance" : {
       "Type" : "AWS::EC2::Instance" ,
       "Properties" : {
         "KeyName" : { "Ref" : "KeyName" },
         "ImageId" : "F17-x86_64-cfntools" ,
         "InstanceType" : "m1.small" ,
         "UserData" : { "Fn::Base64" : "80" }
       }
     }
   },
   "Outputs" : {
     "InstanceIp" : {
       "Value" : { "Fn::Join" : [ "" , [ "ssh ec2-user@" ,
                                      { "Fn::GetAtt" : [ "MyInstance" ,
                                      "PublicIp" ]}]]},
       "Description" : "My ssh command"
     }
   }
}

AWSTemplateFormatVersion定义了Template的版本信息。

Parameters是用户在创建Stack时可以输入的参数类型。

Resources中,MyInstance是一个EC2的Instance,它的属性包括SSH的Key,Glance中的Image名称,Instance的Flavor类型,还有允许传给虚拟机的用户参数。

Outputs中定义了创建Stack后的输出。Instance的Ip值是从MyInstance中得到PublicIp值。


Heat中的基本术语

1. 栈。栈是CloudFormation中管理一组资源的基本单位。一个栈往往对应与一个应用程序。在Heat自己给出的例子中,WordPress就是一个web应用,用它的配置文件可以创建一个栈实例。

2. 资源。一个栈可以拥有很多资源, 资源是底层服务的抽象。CPU,memory,disk,网络等都可以看作是资源。资源和资源之间会存在依赖关系。Heat在创建栈的时候会自动解析依赖关系,按顺序创建资源。从Havana开始Heat能并行的创建没有依赖关系的资源。



理想情况下,Heat允许你象写代码那样来管理你的应用,你可以把Heattemplate保存在版本管理器中,当你修改了模版的内容,应用的配置也会自动做出调整。当然,这是理想情况。。。


Heat模版

Heat模版和CloudFormation模版的一个很大不同是格式。AWS的CloudFormation采用的是JSON格式,它的一个缺点是没办法插入注释。Heat采用Yaml格式来克服这一缺点。另一个好处是解析不同版本的Yaml文件更为方便。因为Yaml是JSON格式的超集,JSON格式的文件可以无损转成Yaml格式。下面,让我们先来看一个Heat模版的例子:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Parameters:
   ssh_key_name:
Type: String
     Description: ssh keypair name
   image_name:
     Type: String
     Description: The image to boot
Resources:
   my_server:
     Type: OS::Nova::Server
     Properties:
       flavor: m1.small
       key_name: { "Ref" : "ssh_key" }
       block_device_mapping:
         device_name: vda
         volume_id: { "Ref" : "my_vol" }
   my_vol:
     Type: OS::Cinder::Volume
     Properties:
       size: 20
       image: { "Ref" : "image_name" }
Outputs:
   server_ip:
     Description: The server IP
     Value: { "Fn::GetAtt" :
                 [ "my_server" ,
                  "first_address" ]}


模版中有四个关键段:

Parameters(可选):定义用户在创建stack需要输入的参数。

Mappings (可选):定义一组静态 Key/ValuePair。用Fn::FindInMap可以查找对应的值。

Resources (必填):定义你的应用所依赖的Resources,以及Resources之间的关系。比如你的应用依赖于哪些包,该如何配置网络,需要的CPU,Memory多少等等。

Outputs (可选): 描述给用户的返回值。


所有的Resources都用通用的接口。

一些可选或必填的属性:用来配置这些资源。

一些输出属性:通过内置函数,如Fn:GetAtt,来得到的属性。


资源之间可以建立起树状的依赖关系。下面是一个典型的Autoscaling例子,用Heat的模版表示会是这样


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Resources:
   MEMAlarmHigh:
     Type: AWS::CloudWatch::Alarm
     Properties:
       AlarmDescription: Scale-up if MEM > 50% for 1 minute
       MetricName: MemoryUtilization
       Namespace: system /linux
       Statistic: Average
       Period: '60'
       EvaluationPeriods: '1'
       Threshold: '50'
       AlarmActions:
       - {Ref: WebServerScaleUpPolicy}
       Dimensions:
       - Name: AutoScalingGroupName
         Value: {Ref: WebServerGroup}
       ComparisonOperator: GreaterThanThreshold
   WebServerScaleUpPolicy:
     Type: AWS::AutoScaling::ScalingPolicy
     Properties:
       AdjustmentType: ChangeInCapacity
       AutoScalingGroupName: {Ref: WebServerGroup}
       Cooldown: '60'
       ScalingAdjustment: '1'
   WebServerGroup:
     Type: AWS::AutoScaling::AutoScalingGroup
     Properties:
       AvailabilityZones: { 'Fn::GetAZs' : '' }
       LaunchConfigurationName: {Ref: LaunchConfig}
       MinSize: '1'
       MaxSize: '3'
       LoadBalancerNames:
       - {Ref: ElasticLoadBalancer}
   ElasticLoadBalancer:
     Type: AWS::ElasticLoadBalancing::LoadBalancer
     Properties:
       ...
   LaunchConfig:
     Type: AWS::AutoScaling::LaunchConfiguration
     Metadata:
       ...
     Properties:


大家可以看到Resource之间通过{Ref:}关键字相互联系了起来。


Heat通过AWS::AutoScaling::AutoScalingGroup来支持Autoscaling。当新的VM起来的时候,Scaling Group可以同时更新Load balancer的配置来加入新的VM信息。


Providers 和 Environments是Havana release中增加的两个features。Providers用来定义用户自定义的Resources,  Providers的语法和Heat内置支持的Resources语法格式完全一样。Environments用来覆盖template中的部分内容,比如基本环境的设置。理想的情况是用一组providertemplate来部署你的应用(每个provider template定义一个应用),用一个environmenttemplate来定义一个云的基础架构。这样通过选择provider模版和environment模版就能在不同的云环境下使用。


目前Heat还在开发自己的模版格式HOT (HeatOrchestration Template),在Heat的模版仓库中已经包含了HOT模版的例子,更多的例子可以看这里:

https://github.com/openstack/heat-templates/

本文出自 “专注Linux开发” 博客,请务必保留此出处http://zhenhua2000.blog.51cto.com/3167594/1335468

Openstack Heat试用

  • What's Heat ?
  • How to install Heat and make it ready to use?
  1. Installation
  2. Prepare JEOS(Just enough OS)
  • Use cases
  1. Deploy a single Wordpress blog server with a floating IP associated.
  2. Deploy wordpress blog server with 2 VM instances(front-end + back-end topology)
  3. Deploy a wordpress blog server with EBS volume as mysql DB storage
  4. Deploy a wordpress blog server with HA protection enabled


 


What's Heat ?


Heat is a service to orchestrate multiple composite cloud applications using the AWS CloudFormation template format, it's Openstack's implementation of CloudFormation and CloudWatch.


Heat integrates other core components of OpenStack into a one-file template system. The templates allow creation of most OpenStack resource types, the main functions of Heat cover:


-vAPP stack creation/update/deletion (suspend/resume will be added in Havana)
-High Availability
-Autoscaling
-Manual scale in/out(in Havana) 


How to install Heat and make it ready to use?


1.Installation


->Heat has been included in RDO repo, installation can be done by Yum:


yum install openstack-heat-api openstack-heat-api-cfn openstack-heat-api-cloudwatch openstack-heat-cli openstack-heat-common openstack-heat-engine python-heatclient python-heatclient-doc heat-cfntools heat-jeos


->Comment out following line since we use RabbitMQ instead of QPID as message queue. Do this for heat-api-cfn.conf, heat-api-cloudwatch.conf, heat-api.conf, heat-engine.conf under /etc/heat.


#rpc_backend=heat.openstack.common.rpc.impl_qpid


->Configure [filter:authtoken] section of heat-api-cfn-paste.ini  heat-api-cloudwatch-paste.ini  heat-api-paste.ini under /etc/heat


[filter:authtoken]
paste.filter_factory = heat.common.auth_token:filter_factory
service_protocol = http
service_host = api-vip
service_port = 5000
auth_host = api-vip
auth_port = 35357
auth_protocol = http
auth_uri = http://api-vip:35357/v2.0
admin_tenant_name = service
admin_user = heat
admin_password = password


->Configure [filter:ec2authtoken] section of  heat-api-cfn-paste.ini  heat-api-cloudwatch-paste.ini under /etc/heat


[filter:ec2authtoken]
paste.filter_factory = heat.api.aws.ec2token:EC2Token_filter_factory
auth_uri = http://api-vip:5000/v2.0
keystone_ec2_uri = http://api-vip:5000/v2.0/ec2tokens


>Update /etc/heat/heat-engine.conf as below:


heat_metadata_server_url = http://10.68.125.11:8000
heat_waitcondition_server_url = http://10.68.125.11:8000/v1/waitcondition
heat_watch_server_url = http://10.68.125.11:8003
sql_connection = mysql://heat:heat@db-vip/heat


#The IP for metadata, watchcondition and watch_server should be the host IP of heat services are running on, and should be reachable from VM instance.


->Setup database for heat:

 heat-db-setup rpm -y -r


->Setup keystone entries for heat:


 heat-keystone-setup


->Start heat services:


service openstack-heat-api start
service openstack-heat-api-cfn start
service openstack-heat-api-cloudwatch start
service openstack-heat-engine start


 


2.Prepare JEOS(Just enough OS)


JEOS image is basic OS image with cloud-init  and heat-cfn-tools pre-installed, they are the keys for Heat and VM exchanging information and doing post and regular jobs.


Pre-built JEOS of Fedora 17 and 18 can be downloaded from: http://fedorapeople.org/groups/heat/prebuilt-jeos-images/


To make our own JEOS on RHEL, following the steps:


a.Assume we have a RHEL 6.3 image registered in Glance already, launch a VM instance from it.
b.Log into the VM, install cloud-init and heat-cfn-tools


yum -y update
export http_proxy=   #This is needed if lab has no direct internet access
curl -O http://ftp.ps.pl/pub/Linux/fedora-epel/6/i386/epel-release-6-7.noarch.rpm
rpm -Uvh epel-release-6-7.noarch.rpm
yum -y install perl python python-setuptools cloud-init python-pip
pip-python install argparse 'boto==2.5.2' heat-cfntools
cfn-create-aws-symlinks --source /usr/bin
rm -rf /etc/udev/rules.d/70-persistent-net.rules


c.From Horizon GUI or CLI, make a snapshot for this VM, name it as "rhel63-x86_64-cfntools".  This snapshot actually becomes a valid JEOS image.


Use cases


1.Deploy a single Wordpress blog server with a floating IP associated.


This templates deploy a single VM instance with a associated floating IP, then install mysql-server, httpd and wordpress packages, initial database, integrate each other and finally start up wordpress web service.


->Download the template file:


wget  https://github.com/abckey/heat-templates/raw/master/WordPress_Single_Instance_With_EIP.template


->Source a tenant credential


source /root/nceprc


>Create a key-pair


nova   keypair-add ncepkey > ncepkey.pem


chmod 400 ncepkey.pem


->Deploy this template by heat


heat stack-create wordpress   -f WordPress_Single_Instance_With_EIP.template -P "InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3"


#Parameters followed after "-P" are needed for instance type selection, DB access setup, key-pair selection and image selection.


->Check stack creation process


Once the stack-create is issued, we should see the stack in "CREATE_IN_PROGRESS" status from output of "heat list"


Once creation is complete, we can see the status will change to "CREATE_COMPLETE".


[root@controller-1 heat(keystone_ncep)]# heat list
+--------------------------------------+--------------+-----------------+----------------------+
| ID | Name | Status | Created |
+--------------------------------------+--------------+-----------------+----------------------+
| a6740599-2c98-41b8-a55e-490f28f6f6f8 | wordpress | CREATE_COMPLETE | 2013-08-05T06:57:40Z |
+--------------------------------------+--------------+-----------------+----------------------+


We can also see detailed resource status in the stack by:


[root@controller-1 heat(keystone_ncep)]# heat resource-list wordpress
+------------------------+--------------------------+-----------------+----------------------+
| Name | Type | Status | Updated |
+------------------------+--------------------------+-----------------+----------------------+
| IPAddress | AWS::EC2::EIP | CREATE_COMPLETE | 2013-08-05T06:57:40Z |
| WebServerSecurityGroup | AWS::EC2::SecurityGroup | CREATE_COMPLETE | 2013-08-05T06:57:41Z |
| IPAssoc | AWS::EC2::EIPAssociation | CREATE_COMPLETE | 2013-08-05T06:57:52Z |
| WebServer | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T06:57:52Z |
+------------------------+--------------------------+-----------------+----------------------+

Also heat stack-show wordpress can be used to show detailed information of the stack

->Try to access the wordpress web UI

From nova list, we could see a VM named "wordpress.WebServer" is created with internal IP and floating IP:

[root@controller-1 heat(keystone_ncep)]# nova list
+--------------------------------------+--------------------------------------------+--------+-------------------------------------+
| ID | Name | Status | Networks |
+--------------------------------------+--------------------------------------------+--------+-------------------------------------+|
| 02da7185-a0a6-44cf-8076-875754163dac | wordpress.WebServer | ACTIVE | ncep-net=10.20.20.17, 10.68.124.102 |
+--------------------------------------+--------------------------------------------+--------+-------------------------------------+

Try to access the wordpress website by its floating IP

http://10.68.124.102/wordpress 

You should see the login page in the browser!!!

2.Deploy wordpress blog server with 2 VM instances(front-end + back-end topology)

This template deploy a 2 VM wordpress solution, one VM running web server, 2nd VM running Mysql DB.

->Download the template:

wget https://github.com/abckey/heat-templates/raw/master/WordPress_2_Instances.template

->Deploy the template by heat

 heat stack-create wp-2-vm  -f WordPress_2_Instances.template -P "InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3"

>From heat resource-list wp-2-vm, we can see 2 VM instances are created, also a floating IP and association with Webserver is there

[root@controller-1 heat(keystone_ncep)]# heat resource-list wp-2-vm 
+----------------+--------------------------+-----------------+----------------------+
| Name | Type | Status | Updated |
+----------------+--------------------------+-----------------+----------------------+
| DatabaseServer | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:14:04Z |
| IPAddress | AWS::EC2::EIP | CREATE_COMPLETE | 2013-08-05T07:14:13Z |
| WebServer | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:14:13Z |
| IPAssoc | AWS::EC2::EIPAssociation | CREATE_COMPLETE | 2013-08-05T07:14:14Z |
+----------------+--------------------------+-----------------+----------------------+

->Try wordpress website with floating IP of WebServer VM instance

[root@controller-1 heat(keystone_ncep)]# nova list
+--------------------------------------+--------------------------------------------+--------+-------------------------------------+
| ID | Name | Status | Networks |
+--------------------------------------+--------------------------------------------+--------+-------------------------------------+
| 4879bb03-bc20-4c33-91e2-d4a7e197d2e5 | wp-2-vm.DatabaseServer | ACTIVE | ncep-net=10.20.20.18 |
| 8e1dc2c7-bc34-4e5d-b833-b64dc8a12c9b | wp-2-vm.WebServer | ACTIVE | ncep-net=10.20.20.19, 10.68.124.103 |
+--------------------------------------+--------------------------------------------+--------+-------------------------------------+

http://10.68.124.103/wordpress


3.Deploy a wordpress blog server with EBS volume as mysql DB storage


This template deploy a VM instance with httpd, wordpress and mysql-server installed, a EBS volume is attached to instance as Mysql DB storage point.


->Download the template


wget  https://github.com/abckey/heat-templates/raw/master/WordPress_Single_Instance_With_EBS_EIP.template


->Deploy


heat stack-create wp-ebs -f WordPress_Single_Instance_With_EBS_EIP.template -P "VolumeSize=5;InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3"


#Here we need use parameter "VolumeSize" to specify the volume size we intend to use as DB storage.


->From resource list , we can see it has volume and volume attachment there

[root@controller-1 heat(keystone_ncep)]# heat resource-list wp-ebs
+-------------------------+----------------------------+-----------------+----------------------+
| Name | Type | Status | Updated |
+-------------------------+----------------------------+-----------------+----------------------+
| DataVolume | AWS::EC2::Volume | CREATE_COMPLETE | 2013-08-05T07:35:48Z |
| WikiServerSecurityGroup | AWS::EC2::SecurityGroup | CREATE_COMPLETE | 2013-08-05T07:35:48Z |
| IPAddress | AWS::EC2::EIP | CREATE_COMPLETE | 2013-08-05T07:35:59Z |
| WikiServer | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:35:59Z |
| IPAssoc | AWS::EC2::EIPAssociation | CREATE_COMPLETE | 2013-08-05T07:36:00Z |
| MountPoint | AWS::EC2::VolumeAttachment | CREATE_COMPLETE | 2013-08-05T07:36:02Z |
+-------------------------+----------------------------+-----------------+----------------------+


->Check volume and attachment


[root@controller-1 heat(keystone_ncep)]# cinder list
+--------------------------------------+--------+-------------------------+------+-------------+----------+--------------------------------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+--------+-------------------------+------+-------------+----------+--------------------------------------+
| 16c9c84f-9bf3-43c7-853d-453ec161b170 | in-use | wp-ebs.DataVolume | 5 | None | false | 0738154d-8d58-4a84-a5fc-71774228105d |
+--------------------------------------+--------+-------------------------+------+-------------+----------+--------------------------------------+

Inside vm, we can check mounts:

[root@wp-ebs ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 5.0G 1.6G 3.1G 34% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/vdb1 938M 39M 853M 5% /var/lib/mysql


->Try to access wordpress by floating IP.


4.Deploy a wordpress blog server with HA protection enabled


This template deploy a VM instance with wordpress server installed, and HA is enabled to monitor httpd/mysqld services to make sure they are already running.


->Download template:


wget  https://github.com/abckey/heat-templates/raw/master/WordPress_Single_Instance_With_HA.template


->Assign admin role to the tenant user by "  keystone user-role-add" command.


To use HA, waitcondition resource is needed, which  needs to create an ec2signed url and to do that it creates a restricted user in keystone. To create any user in keystone we need admin rights:( 


This issue has been addressed by a bug ticket:  https://bugs.launchpad.net/bugs/1089261


  keystone user-role-add  --user --role   --tenant-id


->Deploy


heat stack-create wp-ha -f WordPress_Single_Instance_With_HA.template -P "HupPollInterval=1;InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3" 


#Parameter "HupPollInterval" is needed to specify the cfn-hup process running interval in minutes, cfn-hup is to check services status, and restart them if return code of "service status" is not "0".


->Check resource


[root@controller-1 heat(keystone_ncep)]# heat resource-list wp-ha
+---------------+------------------------------------------+-----------------+----------------------+
| Name | Type | Status | Updated |
+---------------+------------------------------------------+-----------------+----------------------+
| CfnUser | AWS::IAM::User | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WaitHandle | AWS::CloudFormation::WaitConditionHandle | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WebServerKeys | AWS::IAM::AccessKey | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WaitCondition | AWS::CloudFormation::WaitCondition | IN_PROGRESS | 2013-08-05T07:53:41Z |
| WikiDatabase | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:53:41Z |
+---------------+------------------------------------------+-----------------+----------------------+

Here "WaitCondition" actually is waiting VM instance is properly started and configured, then goes to next step

Whole resource list after create_complete:

[root@controller-1 heat(keystone_ncep)]# heat resource-list wp-ha
+------------------------+------------------------------------------+-----------------+----------------------+
| Name | Type | Status | Updated |
+------------------------+------------------------------------------+-----------------+----------------------+
| CfnUser | AWS::IAM::User | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WebServerKeys | AWS::IAM::AccessKey | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WaitHandle | AWS::CloudFormation::WaitConditionHandle | CREATE_COMPLETE | 2013-08-05T07:54:41Z |
| WikiDatabase | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:54:41Z |
| HttpFailureAlarm | AWS::CloudWatch::Alarm | CREATE_COMPLETE | 2013-08-05T07:54:47Z |
| WaitCondition | AWS::CloudFormation::WaitCondition | CREATE_COMPLETE | 2013-08-05T07:54:47Z |
| WebServerRestartPolicy | OS::Heat::HARestarter | CREATE_COMPLETE | 2013-08-05T07:54:47Z |
+------------------------+------------------------------------------+-----------------+----------------------+

Resource "OS::Heat::HARestart" takes care of service HA.

->Try to access wordpress web by floating IP

Login page should show up.

->Try HA by stopping httpd service

In the VM, do service httpd stop.

Check cfn-hup.log

[root@wp-ha ~]# tail -f /var/log/cfn-hup.log

DEBUG [2013-08-05 16:28:02,552] Running command: /sbin/service httpd status
DEBUG [2013-08-05 16:28:02,609] Return code of 3 after executing: '['su', 'root', '-c', u'/sbin/service httpd status']'
WARNING [2013-08-05 16:28:02,610] Restarting service httpd
DEBUG [2013-08-05 16:28:02,610] Running command: /sbin/service httpd start
DEBUG [2013-08-05 16:28:02,732] Running command: /etc/cfn/notify-on-httpd-restarted
DEBUG [2013-08-05 16:28:03,634] Running command: /sbin/service mysqld status
DEBUG [2013-08-05 16:28:03,714] Running command: /sbin/service crond status

We can see once cfn-hup found httpd service has problem, it tried to start httpd service.

->Check wordpress web access again, it should work again.





OpenStack Heat Research


Heat is a template-based orchestration mechanism for use with OpenStack. With Heat, you can deploy collections of resources –networks,servers, storage, and more– all from a single, parameterized template.







Heat in Openstack

OpenStack Heat服务介绍_第1张图片







Basic Architecture

heat

The heat tool is a CLI which communicates with the heat-api to execute AWS CloudFormation APIs. End developers could also use the heat REST API directly.

heat-api

The 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

The 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

The heat engine’s main responsibility is to orchestrate the launching of templates and provide events back to the API consumer.



                  |- [REST API] -|
[CLI] --  --                                       --  -- [ENGINE]
                  |- [CFN API]   -|







Templates

Because Heat began life as an analog ofAWS CloudFormation,it supports the template formats used by the CloudFormation (CFN) tools.

It also supports its ownnative template format,called HOT (“Heat Orchestration Templates”).

Stack

A collection of resources defined by a template.



Heat Orchestration Template

Structure -YAML Style

heat_template_version: 2013-05-23

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



Parameter Groups Section

parameter_groups:
- label: 
  description: 
  parameters:
  - 
  - 



Parameters Section

parameters:
  :
    type: 
    label: 
    description: 
    default: 
    hidden: 
    constraints:
      



constraints:
  - : 
    description: 



length: { min: , max:  }
range: { min: , max:  }
allowed_values: [ , , ... ]
allowed_pattern: 



Resources Section

resources:
  :
    type: 
    properties:
      : 
    # more resource specific metadata



Output Section

outputs:
  :
    description: 
    value: 



Intrinsic Funciton

Referencing an input parameter of a template from anywhere within a template.

get_param:
  - 
  -  (optional)
  -  (optional)
  - ...

Referencing an attribute of a resource.

get_attr:
  - 
  - 
  -  (optional)
  -  (optional)
  - ...

Referencing another resource within the same template.

get_resource: 

String replace.

str_replace:
  template: