Heat提供了一个OpenStack的原生REST API和CloudFormation兼容的查询API。
编辑完模板文件后,可以使用该模板文件创建Stack,创建的过程中Heat引擎会根据模板文件中定义的资源,调用对应的资源插件创建资源。创建完Stack之后,Heat可以管理Stack中所有资源的生命周期,例如可以删除资源,也可以通过更新模板的方式来更新Stack中资源的定义。
1、安装软件包
sudo apt-get install heat-api heat-api-cfn heat-engine
2、修改heat配置文件
sudo vi /etc/heat/heat.conf
[database] # The SQLAlchemy connection string used to connect to the database connection = mysql://heat:[email protected]/heat
sm@controller:~$ sudo heat-manage db_sync No handlers could be found for logger "heat.common.config" 2015-05-17 01:53:41.853 24843 WARNING heat.openstack.common.db.sqlalchemy.session [-] This application has not enabled MySQL traditional mode, which means silent data corruption may occur. Please encourage the application developers to enable this mode./usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py:324: Warning: Specified key was too long; max key length is 767 bytes cursor.execute(statement, parameters)
mysql> use heat Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +---------------------+ | Tables_in_heat | +---------------------+ | event | | migrate_version | | raw_template | | resource | | resource_data | | software_config | | software_deployment | | stack | | stack_lock | | user_creds | | watch_data | | watch_rule | +---------------------+ 12 rows in set (0.00 sec)
[DEFAULT] verbose = True log_dir=/var/log/heat rabbit_host = 192.168.3.180 rabbit_password = mq4smtest # URL of the Heat metadata server. (string value) heat_metadata_server_url = http://192.168.3.180:8000 # URL of the Heat waitcondition server. (string value) heat_waitcondition_server_url = http://192.168.3.180:8000/v1/waitcondition [keystone_authtoken] auth_host = 192.168.3.180 auth_port = 35357 auth_protocol = http auth_uri = http://192.168.3.180:5000/v2.0 admin_tenant_name = service admin_user = heat admin_password = heat4smtest [ec2authtoken] auth_uri = http://192.168.3.180:5000/v2.0
sm@controller:~$ keystone user-create --name=heat --pass=heat4smtest [email protected] +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | email | [email protected] | | enabled | True | | id | 356986370fa0486d972b0ff84f068a02 | | name | heat | | username | heat | +----------+----------------------------------+
sm@controller:~$ keystone service-create --name=heat --type=orchestration --description="Orchestration" +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | Orchestration | | enabled | True | | id | 1ae32b5423a5430692c771de198eca84 | | name | heat | | type | orchestration | +-------------+----------------------------------+
sm@controller:~$ keystone endpoint-create --service-id=$(keystone service-list | awk '/ orchestration / {print$2}') --publicurl=http://192.168.3.180:8004/v1/%\(tenant_id\)s --internalurl=http://192.168.3.180:8004/v1/%\(tenant_id\)s --adminurl=http://192.168.3.180:8004/v1/%\(tenant_id\)s +-------------+--------------------------------------------+ | Property | Value | +-------------+--------------------------------------------+ | adminurl | http://192.168.3.180:8004/v1/%(tenant_id)s | | id | fbe1486bd14d4ef4852b40ac3c0ce6a5 | | internalurl | http://192.168.3.180:8004/v1/%(tenant_id)s | | publicurl | http://192.168.3.180:8004/v1/%(tenant_id)s | | region | regionOne | | service_id | 1ae32b5423a5430692c771de198eca84 | +-------------+--------------------------------------------+
sm@controller:~$ keystone service-create --name=heat-cfn --type=cloudformation --description="Orchestration CloudFormation" +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | Orchestration CloudFormation | | enabled | True | | id | 5764a2c064f5435c8f43f38c3ddb455d | | name | heat-cfn | | type | cloudformation | +-------------+----------------------------------+
sm@controller:~$ keystone endpoint-create --service-id=$(keystone service-list | awk '/ cloudformation / {print$2}') --publicurl=http://192.168.3.180:8000/v1 --internalurl=http://192.168.3.180:8000/v1 --adminurl=http://192.168.3.180:8000/v1 +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | adminurl | http://192.168.3.180:8000/v1 | | id | 6805a36f6cc740c298b8571b0bb367c7 | | internalurl | http://192.168.3.180:8000/v1 | | publicurl | http://192.168.3.180:8000/v1 | | region | regionOne | | service_id | 5764a2c064f5435c8f43f38c3ddb455d | +-------------+----------------------------------+
sm@controller:~$ keystone role-create --name heat_stack_user +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | id | 5ae818372ea24d2589e5c19b299c2e6a | | name | heat_stack_user | +----------+----------------------------------+
sudo service heat-engine restart
1、模板文件
这是帮助给的一个模板文件,创建test-stack.yml
heat_template_version: 2013-05-23 description: Test Template parameters: ImageID: type: string description: Image use to boot a server NetID: type: string description: Network ID for the server resources: server1: type: OS::Nova::Server properties: name: "Test server" image: { get_param: ImageID } flavor: "m1.tiny" networks: - network: { get_param: NetID } outputs: server1_private_ip: description: IP address of the server in the private network value: { get_attr: [ server1, first_address ] }
2、该模板文件目的就是创建一个VM实例,需要获得镜像信息和网络信息
sm@controller:~$ neutron net-list +--------------------------------------+------------+-----------------------------------------------------+ | id | name | subnets | +--------------------------------------+------------+-----------------------------------------------------+ | 1dfa9da1-43fd-4128-b9a0-2ca76a664933 | sharednet1 | db1aad02-3890-44d4-93c4-c933c2c818a5 192.168.3.0/24 | +--------------------------------------+------------+-----------------------------------------------------+
执行该模板,输入条件信息
sm@controller:~$ heat stack-create -f /home/sm/test-stack.yml -P "ImageID=cirros-0.3.2-x86_64;NetID=1dfa9da1-43fd-4128-b9a0-2ca76a664933" testStack +--------------------------------------+------------+--------------------+----------------------+ | id | stack_name | stack_status | creation_time | +--------------------------------------+------------+--------------------+----------------------+ | 52be000d-4046-40e9-9bab-d11375162080 | testStack | CREATE_IN_PROGRESS | 2015-05-16T19:17:21Z | +--------------------------------------+------------+--------------------+----------------------+
查看heat栈信息
sm@controller:~$ heat stack-list +--------------------------------------+------------+-----------------+----------------------+ | id | stack_name | stack_status | creation_time | +--------------------------------------+------------+-----------------+----------------------+ | 52be000d-4046-40e9-9bab-d11375162080 | testStack | CREATE_COMPLETE | 2015-05-16T19:17:21Z | +--------------------------------------+------------+-----------------+----------------------+
我们进入horzion查看信息
我们看到项目,增加了一个编配栏,里面包含一个栈,就是我们刚才创建的testStack。
点击该信息
我们可以看到,创建的明细,新生成了一个192.168.3.125的VM实例
我们再查看实例