Heat是OpenStack的编排服务,通过使用编排的模板来进行自动化事务管理, 因为资料比较稀碎,文档结构比较乱。
本次案例我们将编写yml文件来使用Heat创建云主机。
description: create cirros server
heat_template_version: '2013-05-23'
resources:
cirros:
properties:
flavor: Fmin
image: cirros
networks:
- {network: intnet}
type: OS::Nova::Server
opensatack stack create --template create_server.yml create_server
heat_template_version: 2015-04-30 ### HOT版本
description: ### 说明
# a description of the template
parameter_groups: ### 指定参数顺序
- label: <human-readable label of parameter group>
description: <description of the parameter group>
parameters:
- <param name>
- <param name>
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: ### 已有的内置参数:OS::stack_name、OS::stack_id、OS::project_id
<parameter constraints>
immutable: <true | false>
resources: ### 资源对象
<resource ID>: ### 资源的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>
outputs: ### 返回值
<parameter name>: ### 参数名
description: <description> ### 说明
value: <parameter value> ### 输出值
heat_temp_version:2016-04-30 # HOT版本
Description: AWS::CloudWatch::Alarm using Ceilometer. # 描述信息
parameters: # 传递的参数
user_name: # 参数名
type: string # 参数类型
label: User Name # 标签
description: User name to be configured for the application
port_number: # 参数名
type: number # 参数类型
label: Port Number # 参数标签
description: Port number to be configured for the web server
resources: #资源对象
my_instance: # 资源ID
type: OS::Nova::Server # 资源类型
properties: # 资源属性
flavor: m1.small # 资源元数据
image: F18-x86_64-cfntools
outputs: # 返回值
instance_ip: # 参数名
description: IP address of the deployed compute instance
value: { get_attr: [my_instance, first_address] } # 输出值
heat_template_version: 2015-10-15
description: Sample Nova Host Aggregate template
parameters:
host_aggregate_name:
type: string
description: Nova host aggregate name
availability_zone_name:
type: string
description: Nova availability zone name
hosts:
type: comma_delimited_list
description: Nova host name list
metadata:
type: json
description: Arbitrary key/value metadata
resources:
sample_host_aggregate:
type: OS::Nova::HostAggregate
properties:
name: {get_param: host_aggregate_name}
availability_zone: {get_param: availability_zone_name}
hosts: {get_param: hosts}
metadata: {get_param: metadata}
outputs:
sample_host_aggregate_id:
value: {get_resource: sample_host_aggregate}
description: Sample nova host_aggregate
# 创建f1.flavor云主机类型,硬盘:20GB,ID:1234,内存:1024MB,CPU数量:2。
heat_template_version: 2015-04-30
description: create flavor by vcpu:2 name:m1.flavor id:1234 ram:1024mb disk:20gb
resources:
m1.flavor:
type: OS::Nova::Flavor
properties:
disk: 20
flavorid: 1234
name: f1.flavor
ram: 1024
vcpus: 2
######################################
description: create flavor by vcpu:2 name:m1.flavor id:1234 ram:1024mb disk:20gb
heat_template_version: '2015-04-30'
resources:
m1.flavor:
properties: {disk: 20, flavorid: 1234, name: f1.flavor, ram: 1024, vcpus: 2}
type: OS::Nova::Flavor
heat_template_version: 2015-04-30
description: create server "cirros" by image:cirros,flavor:Fmin,network:intnet,subnet:intsubnet,floating_ip:192.168.200.60,name:cirros.
resources:
server_cirros:
type: OS::Nova::Server
properties:
image: cirros
flavor: Fmin
networks:
- {network: intnet, subnet: intsubnet_2, floating_ip: 16a625e4-9552-48eb-95f1-daaa846b0f77}
name: cirros
使用Heat编写堆伐(stack)创建的内容,在堆伐被删除后也会被删除。
成功导入堆伐后会自动在后台生成更标准的模板文件。
绑定浮动IP地址要写浮动IP的ID
创建模板文件的时候可以指定传递参数进入 --parameters "参数名=参数值"
英文 | 含义 |
---|---|
parameters | 传递参数;顶级关键字 |
resources | 资源对象;顶级关键字 |
description | 注释 |
properties | 属性,配合resources使用 |
template | 模板 |