Heat Orchestration Template (HOT) specification
updated: 'Fri Sep 22 14:44:51 2017, commit 31175a5'
這片文章定義了HEAT模板的格式佳遂。HEAT是一個(gè)軟件,用于管理OpenStack的stack。這里的stack承疲,是將各種OpenStack的資源捆綁在一起筛谚,方便創(chuàng)建和刪除浸剩。如果希望對HEAT模板有個(gè)初步和形象的認(rèn)識年碘,可以讀這篇文章:http://www.reibang.com/writer#/notebooks/18275097/notes/19531272
1 HEAT模板格式
heat_template_version: 2016-10-14
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
1.1 heat_template_version
For example,
heat_template_version: 2013-05-23
heat_template_version: 2014-10-16
heat_template_version: 2015-04-30
heat_template_version: 2015-10-15
heat_template_version: 2016-04-08
heat_template_version: 2016-10-14 (or newton)
heat_template_version: 2017-02-24 (or ocata)
heat_template_version: 2017-09-01 (or pike)
1.2 description
For example,
description: Simple template to deploy a virtual machine.
1.3 parameter_groups (可省略)
通過把有共性的參數(shù)組合在一起嘶伟,增強(qiáng)邏輯性。
1.4 parameter (可省略)
在stack被創(chuàng)建之前写半,這些參數(shù)的值必須被提供岸蜗。參數(shù)的作用是,幫助模板變得靈活叠蝇,適應(yīng)不同的場合璃岳。
1.5 resources
被創(chuàng)建的各種資源,如虛擬機(jī)悔捶,網(wǎng)絡(luò)/子網(wǎng)铃慷,路由器,floating IP等蜕该,都定義在這里犁柜。
1.6 outputs (可省略)
Stack 創(chuàng)建完后,通過下面的命令顯示一些信息堂淡。好像沒太大用處馋缅。
$ heat output-list <stack-name>
$ heat output-show <stack-name>
1.7 conditions (Newton以后版本才支持)
我現(xiàn)在的試驗(yàn)環(huán)境,最新僅支持2016-04-8绢淀,暫時(shí)無法試驗(yàn)conditions相關(guān)的用法萤悴。
2 舉例
例2.1 一個(gè)虛擬機(jī)
在這個(gè)例子中,我們將練習(xí):
- description 采用多行格式
- network_name 作為命令行參數(shù)傳入
- resources 中只有一個(gè)虛擬機(jī)
heat_template_version: 2016-04-08
description: >
This template will deploy a single virtual machine, and
this virtual machine will connect to an existing network.
There are three networks can be selected.
parameters:
network_name:
type: string
constraints:
- allowed_values:
- extnet-vxlan-0
- extnet-vxlan-1
- extnet-vxlan-2
resources:
my_virtual_machine:
type: OS::Nova::Server
properties:
image: cirros
flavor: m1.small
networks:
- network: { get_param: network_name }
通過命令行皆的,啟動 stack:
$ heat stack-create -f example_2_1.yaml --parameters "network_name=extnet-vxlan-0" xxx
$ heat stack-list
+--------------------------------------+------------+-----------------+----------------------------+
| id | stack_name | stack_status | creation_time |
+--------------------------------------+------------+-----------------+----------------------------+
| 221c247c-0fd4-4283-b0a6-16ff2894f044 | xxx | CREATE_COMPLETE | 2017-11-13T08:02:13.088757 |
+--------------------------------------+------------+-----------------+----------------------------+
$ nova list
+--------------------------------------+-------------------------------------+--------+------------+-------------+-----------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+-------------------------------------+--------+------------+-------------+-----------------------------+
| db9135aa-8065-44dd-8b46-b825948f4a23 | xxx-my_virtual_machine-v27lqcztcq34 | ACTIVE | - | Running | extnet-vxlan-0=10.37.227.35 |
+--------------------------------------+-------------------------------------+--------+------------+-------------+-----------------------------+
Stack 也可以在 OpenStack 的 Dash-board 中被啟動覆履,這時(shí)候 network_name 這個(gè)參數(shù)被顯示在網(wǎng)頁中,很容易輸入祭务。
例2.2 兩個(gè)虛擬機(jī)+一個(gè)網(wǎng)絡(luò)
在這個(gè)例子中内狗,我們將練習(xí):parameter_groups 看它是如何工作的。
heat_template_version: 2016-04-08
description: ...
parameter_groups:
- label: network parameters
parameters:
- network_name
- subnet_name
- subnet_cidr
parameters:
network_name:
type: string
subnet_name:
type: string
subnet_cidr:
type: string
resources:
simple_net:
type: OS::Neutron::Net
properties:
name: { get_param: network_name }
simple_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: simple_net }
name: { get_param: subnet_name }
cidr: { get_param: subnet_cidr }
VM1:
type: OS::Nova::Server
properties:
name: VM1
image: cirros
flavor: m1.small
networks:
- network: { get_resource: simple_net }
VM2:
type: OS::Nova::Server
properties:
name: VM2
image: cirros
flavor: m1.small
networks:
- network: { get_resource: simple_net }
$ heat stack-create -f example_2_2.yaml --parameters "network_name=GREEN;subnet_name=10_10_10;subnet_cidr=10.10.10.0/24" xxx
$ heat stack-list
+--------------------------------------+------------+-----------------+----------------------------+
| id | stack_name | stack_status | creation_time |
+--------------------------------------+------------+-----------------+----------------------------+
| 5bbac33f-fc54-4dbc-a622-cc27acb13b88 | xxx | CREATE_COMPLETE | 2017-11-14T00:53:45.609428 |
+--------------------------------------+------------+-----------------+----------------------------+
$ neutron net-list --name GREEN
+-------------------------------+-------+-------------------------------+
| id | name | subnets |
+-------------------------------+-------+-------------------------------+
| 6f356b52-f2ab- | GREEN | e5903726-080f-4b3a-bc1f- |
| 4c73-8221-cf0f7d827d8d | | 77c1235cef20 10.10.10.0/24 |
+-------------------------------+-------+-------------------------------+
$ nova list
+--------------------------------------+------+--------+------------+-------------+------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+------------------+
| 0c07eb32-efab-4582-a77c-ce4c9689f9ae | VM1 | ACTIVE | - | Running | GREEN=10.10.10.4 |
| 35c9d4b7-b4b8-4267-aba8-df8fe7e62c54 | VM2 | ACTIVE | - | Running | GREEN=10.10.10.3 |
+--------------------------------------+------+--------+------------+-------------+------------------+
$ heat stack-delete xxx
通過dash-board啟動stack义锥,也沒有看到 parameter_groups柳沙。
結(jié)論: parameter_groups 好像沒有什么用?
例2.3 虛擬機(jī)的metadata
這個(gè)例子拌倍,我們練習(xí)一下赂鲤,每個(gè)虛擬機(jī)的metadata是如何工作的。
語法:
resources:
<resource ID>:
type: <resource type>
properties:
<property name>: <property value>
metadata:
<resource specific metadata>
heat_template_version: 2016-04-08
description: Simple template to deploy a network with two VMs.
resources:
simple_net:
type: OS::Neutron::Net
properties:
name: GREEN
simple_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: simple_net }
name: 10_10_10
cidr: 10.10.10.0/24
VM1:
type: OS::Nova::Server
properties:
name: VM1
image: cirros
flavor: m1.small
networks:
- network: { get_resource: simple_net }
metadata:
param_1: value_1
VM2:
type: OS::Nova::Server
properties:
name: VM2
image: cirros
flavor: m1.small
networks:
- network: { get_resource: simple_net }
metadata:
param_1: value_2
$ heat stack-create -f example_2_3.yaml xxx
$ openstack server show VM1 | grep properties
| properties | param_1='value_1'
$ openstack server set VM1 --property param_1=xxx
$ openstack server show VM1 | grep properties
| properties | param_1='xxx'
在虛擬機(jī)中得到這個(gè)參數(shù):
$ curl http://169.254.169.254/openstack/latest/meta_data.json
參考文獻(xiàn)
1 Heat Orchestration Template (HOT) specification
2 Heat Orchestration Template (HOT) Guide
3 OpenStack document - Environments