1. Template structure
1.1 status
HOT是一个新的模板格式,取代了Heat CloudFormation-compatible format(CFN),自Juno版本后,Heat开始支持HOT的多个版本
1.2 Template格式
HOT模板样式由YAML定义,形式如下:
heat_template_version: 2015-04-30
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
- heat_template_version
- description
可选关键字,模板描述
- parameter_groups
可选关键字,给输入参数分组并提供参数次序
- parameters
可选关键字,指定初始化模板时的输入参数
- resources
定义模板中的资源,本模块至少要定义一个资源,否则初始化模板无效
- outputs
可选关键字,指定模板初始化结束后用户可得到的输出参数
1.2.1 Heat template version
参数说明了该YAML文件是HOT模板的一个特定版本,也指出了模板验证和支持的功能。目前Heat支持以下Heat template version关键字,他们分别支持的功能为:
2013-05-23
get_attr |
get_file |
get_param |
get_resource |
list_join |
resource_facade |
str_replace |
Fn::Base64 |
Fn::GetAZs |
Fn::Join |
Fn::MemberListToMap |
Fn::Replace |
Fn::ResourceFacade |
Fn::Select |
Fn::Split |
Ref |
2014-10-16
get_attr |
get_file |
get_param |
get_resource |
list_join |
resource_facade |
str_replace |
Fn::Select |
2015-04-30
get_attr |
get_file |
get_param |
get_resource |
list_join |
resource_facade |
str_replace |
repeat |
Fn::Select |
2015-10-15
get_attr |
get_file |
get_param |
get_resource |
list_join |
resource_facade |
str_replace |
repeat |
Fn::Select |
digest |
str_split |
1.2.2 Parameter groups section
模块格式为:
parameter_groups:
- label: <human-readable label of parameter group>
description: <description of the parameter group>
parameters:
- <param name>
- <param name>
label:参数组标签
description:参数组描述
parameters:参数列表
param name:参数名字,与parameters模块中定义的参数关联
1.2.3 Parameters section
模块格式为:
parameters:
<param name>:
type: <string | number | json | comma_delimited_list | boolean>
label: <human-readable name of the parameter>
description: <description of the parameter>
default: <default value for parameter>
hidden: <true | false>
constraints:
<parameter constraints>
param name:参数名字
type:参数类型
Type |
Description |
Examples |
string |
A literal string. |
“String param” |
number |
An integer or float. |
“2”; “0.2” |
comma_delimited_list |
An array of literal strings that are separated by commas. The total number of strings should be one more than the total number of commas. |
[“one”, “two”]; “one, two”; Note: “one, two” returns [“one”, ” two”] |
json |
A JSON-formatted map or list. |
{“key”: “value”} |
boolean |
Boolean type value, which can be equal “t”, “true”, “on”, “y”, “yes”, or “1” for true value and “f”, “false”, “off”, “n”, “no”, or “0” for false value. |
“on”; “n |
label:可选关键字,参数标签
description:可选关键字,参数描述
default:可选关键字,参数默认值
hidden:当用请求查看该模板创建的stack信息时,该参数是否需要隐藏,默认false
constraints:可选关键字,约束列表,用户部署stack时由Orchestration engine验证
约束模块格式为:
constraints:
- <constraint type>: <constraint definition>
description: <constraint description>
description:可选关键字,约束描述
constrains type:约束类型
constraint definition:约束内容,与类型对应关系如下
约束类型 |
约束对象 |
约束内容 |
length |
string |
length: { min: <lower limit>, max: <upper limit> } |
range |
number |
range: { min: <lower limit>, max: <upper limit> } |
allowed_values |
string or number |
allowed_values: [ <value>, <value>, ... ] |
allowed_pattern |
string |
allowed_pattern: <regular expression> |
custom_constraint |
检查特定资源是否存在 资源列表如下 |
custom_constraint: <name> |
Pseudo parameters |
stack |
OS::stack_name OS::stack_id OS::project_id |
The following section lists the custom constraints and the plug-ins that support them.
Name |
Plug-in |
cinder.backup |
heat.engine.clients.os.cinder:VolumeBackupConstraint |
cinder.snapshot |
heat.engine.clients.os.cinder:VolumeSnapshotConstraint |
cinder.volume |
heat.engine.clients.os.cinder:VolumeConstraint |
cinder.vtype |
heat.engine.clients.os.cinder:VolumeTypeConstraint |
cron_expression |
heat.engine.constraint.common_constraints:CRONExpressionConstraint |
designate.domain |
heat.engine.clients.os.designate:DesignateDomainConstraint |
glance.image |
heat.engine.clients.os.glance:ImageConstraint |
ip_addr |
heat.engine.constraint.common_constraints:IPConstraint |
iso_8601 |
heat.engine.constraint.common_constraints:ISO8601Constraint |
keystone.domain |
heat.engine.clients.os.keystone:KeystoneDomainConstraint |
keystone.group |
heat.engine.clients.os.keystone:KeystoneGroupConstraint |
keystone.project |
heat.engine.clients.os.keystone:KeystoneProjectConstraint |
keystone.role |
heat.engine.clients.os.keystone:KeystoneRoleConstraint |
keystone.service |
heat.engine.clients.os.keystone:KeystoneServiceConstraint |
keystone.user |
heat.engine.clients.os.keystone:KeystoneUserConstraint |
mac_addr |
heat.engine.constraint.common_constraints:MACConstraint |
manila.share_network |
heat.engine.clients.os.manila:ManilaShareNetworkConstraint |
manila.share_snapshot |
heat.engine.clients.os.manila:ManilaShareSnapshotConstraint |
manila.share_type |
heat.engine.clients.os.manila:ManilaShareTypeConstraint |
monasca.notification |
heat.engine.clients.os.monasca:MonascaNotificationConstraint |
net_cidr |
heat.engine.constraint.common_constraints:CIDRConstraint |
neutron.network |
heat.engine.clients.os.neutron:NetworkConstraint |
neutron.port |
heat.engine.clients.os.neutron:PortConstraint |
neutron.router |
heat.engine.clients.os.neutron:RouterConstraint |
neutron.subnet |
heat.engine.clients.os.neutron:SubnetConstraint |
nova.flavor |
heat.engine.clients.os.nova:FlavorConstraint |
nova.keypair |
heat.engine.clients.os.nova:KeypairConstraint |
nova.network |
heat.engine.clients.os.nova:NetworkConstraint |
nova.server |
heat.engine.clients.os.nova:ServerConstraint |
sahara.image |
heat.engine.clients.os.sahara:ImageConstraint |
sahara.plugin |
heat.engine.clients.os.sahara:PluginConstraint |
timezone |
heat.engine.constraint.common_constraints:TimezoneConstraint |
trove.flavor |
heat.engine.clients.os.trove:FlavorConstraint |
1.2.4 Resources section
模块格式:
resources:
<resource ID>:
type: <resource type>
properties:
<property name>: <property value>
metadata:
<resource specific metadata>
depends_on: <resource ID or list of ID>
update_policy: <update policy>
deletion_policy: <deletion policy>
resource ID:在该template内唯一
type:资源类型,例如OS::Nova::Server or OS::Neutron::Port
properties:可选关键字,资源特性列表,属性值可以直接提供,或通过一个函数(内部函数见后文)
metadata:可选关键字,元数据
depends_on:可选关键字,资源依赖关系
应用举例:一个资源依赖于一个或更多资源时,
resources:
server1:
type: OS::Nova::Server
depends_on: [ server2, server3 ]
server2:
type: OS::Nova::Server
server3:
type: OS::Nova::Server
update_policy:可选关键字,资源更新策略,是否支持更新策略以及确切的语义取决于资源类型
deletion_policy:可选关键字,可选关键字,资源删除策略,支持的删除策略类型取决于资源类型
1.2.5 Outputs section
模块格式:
outputs:
<parameter name>:
description: <description>
value: <parameter value>
parameter name:输出参数名字,template内唯一
description:可选参数,输出参数描述
parameter value:输出参数值,通常由函数得到(内部函数见后文)
2. 内部函数
Note:这些函数值能用于resource的properties模块,或output模块
2.1 get_attr:引用资源属性
基于关键字或索引的方法需要heat_template_version 2014-10-16或更高
2015-10-15以后,<attribute_name>为可选关键字,缺省为all attributes
get_attr:
- <resource name>
- <attribute name>
- <key/index 1> (optional)
- <key/index 2> (optional)
- ...
2.2 get_file:返回template中file的内容
实参必须是一个静态路径或URL,且不能依赖于内部函数
get_file: <content key>d
2.3 get_param:引用模板的输入参数
get_param:
- <parameter name>
- <key/index 1> (optional)
- <key/index 2> (optional)
- ...
2.4 get_resource:引用同一模板中的其他resource
get_resource: <resource ID>
2.5 list_join:把给定分隔符加入strings列表
list_join:
- <delimiter>
- <list to join>
2.6 str_split:list_join的相反操作
str_split:
- ‘,‘
- string,to,split
2.7 digest:对给定值进行digest操作
Kilo版本引进,2015-04-30之后版本可用
算法由hashlib提供(md5, sha1, sha224, sha256, sha384, and sha512),或OpenSSL
digest:
- <algorithm>
- <value>
2.8 repeat:动态改变模板资源列表中的内容,返回一个新的列表
list内容可以来自一个函数
repeat:
template:
<template>
for_each:
<var>: <list>
2.9 resource_facade:在父模板中提取数据
resource_facade: <data type>
2.10 str_replace:用给定值替换template中的相应内容
str_replace:
template: <template string>
params: <parameter mappings>