heat_template_version: 2013-05-23
parameters:#定义一些变量
flavor:
type: string
default: m1.small
image:
type: string
default: 1a2b3c4f-1a2b-3c4f-5d6e-4130ff5203de
availability_zone:
type: string
default: nova
alarm_scaleout_threshold:#阈值
type: number
default: 80
alarm_scalein_threshold:#阈值
type: number
default: 20
resources:
neutron_network:
type: OS::Neutron::Net
properties:
name: {get_param: “OS::stack_name”}
neutron_subnet:
type: OS::Neutron::Subnet
properties:
name: {get_param: “OS::stack_name”}
network_id: { get_resource: neutron_network }
cidr: 192.168.111.0/24
gateway_ip: 192.168.111.1
allocation_pools:
– start: 192.168.111.2
end: 192.168.111.254
neutron_router:
type: OS::Neutron::Router
properties:
name: {get_param: “OS::stack_name”}
add_router_interface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: neutron_router }
subnet_id: { get_resource: neutron_subnet }
nova_server_security_group:
type: OS::Neutron::SecurityGroup
properties:
description: security group for VM
name: {get_param: “OS::stack_name”}
rules: [
{direction: ingress,
remote_ip_prefix: 0.0.0.0/0,
port_range_min: 0,
port_range_max: 30000,
ethertype: IPv4,
protocol: tcp},
{direction: egress,
remote_ip_prefix: 0.0.0.0/0,
port_range_min: 0,
port_range_max: 65535,
ethertype: IPv4,
protocol: tcp},
{direction: egress,
remote_ip_prefix: 0.0.0.0/0,
port_range_min: 0,
port_range_max: 65535,
ethertype: IPv4,
protocol: udp},
{direction: ingress,
remote_ip_prefix: 0.0.0.0/0,
port_range_min: null,
port_range_max: null,
ethertype: IPv4,
protocol: icmp},
{direction: egress,
remote_ip_prefix: 0.0.0.0/0,
port_range_min: null,
port_range_max: null,
ethertype: IPv4,
protocol: icmp}
]
launch_config:#Scale group中的实例的配置
type: AWS::AutoScaling::LaunchConfiguration
properties:
ImageId: { get_param: image }#实例使用的image
InstanceType: { get_param: flavor }#实例使用的flavor
SecurityGroups: [ get_resource: nova_server_security_group ]
UserData: |#实例启动时运行的脚本
#!/bin/bash
passwd root << EOD
123456
123456
EOD
server_group:#伸缩组
type: AWS::AutoScaling::AutoScalingGroup
properties:
AvailabilityZones: []
Cooldown: 60#冷却时间
LaunchConfigurationName: { get_resource: launch_config }#组中实例的配置
MinSize: 1#最小实例数
MaxSize: 4#最大实例数
VPCZoneIdentifier: [ get_resource: neutron_subnet ]
scaleout_policy:#向上扩展的策略
type: AWS::AutoScaling::ScalingPolicy
properties:
AdjustmentType: ChangeInCapacity
#heat 支持三种调整方式:change_in_capacity (new = current + adjustment), #exact_capacity (new = adjustment), percent_change_in_capacity (在current 的基#础上上按照 adjustment 的 百分比调整)
AutoScalingGroupName: { get_resource: server_group }
ScalingAdjustment: 1#每次的调整量,即增加一个实例
scalein_policy:#向下收缩的策略
type: AWS::AutoScaling::ScalingPolicy
properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName: { get_resource: server_group }
ScalingAdjustment: -1#每次的调整量,即减少一个实例
neutron_port:
type: OS::Neutron::Port
properties:
network_id: { get_resource: neutron_network }
fixed_ips:
– subnet_id: { get_resource: neutron_subnet }
security_groups: [ { get_resource: nova_server_security_group } ]
alarm_scaleout: #定义一个 ceilometer alarm
type: OS::Ceilometer::Alarm
properties:
description: Scale-up if the average CPU > 80% for 10 minute
meter_name: cpu_util #监控虚拟机的 cpu_util
statistic: avg #statistic 的计算方法为 avg 即平均值法
period: 600 #统计周期
evaluation_periods: 1 #连续几个周期才算有效
repeat_actions: true
threshold: { get_param: alarm_scaleout_threshold }# cpu_util 的阈值
alarm_actions: #该告警在alarm 状态时的 action。
– {get_attr: [scaleout_policy, AlarmUrl]}
matching_metadata: {metadata.user_metadata.groupname: {get_resource: server_group}}
comparison_operator: gt #检测值和阈值的比较方式为 gt 即大于
alarm_scalein:
type: OS::Ceilometer::Alarm
properties:
description: Scale-down if the average CPU < 20% for 10 minutes
meter_name: cpu_util
statistic: avg
period: 600
evaluation_periods: 1
repeat_actions: true
threshold: { get_param: alarm_scalein_threshold }
alarm_actions:
– {get_attr: [scalein_policy, AlarmUrl]}
matching_metadata: {metadata.user_metadata.groupname: {get_resource: server_group}}
comparison_operator: lt#检测值和阈值的比较方式为 lt 即小于
outputs:
scale_in_url:
value: { get_attr: [ scalein_policy, AlarmUrl ] }
scale_out_url:
value: { get_attr: [ scaleout_policy, AlarmUrl ] }