################################################################################ # Copyright (c) 2013-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # ################################################################################ # # Objective: # Demonstrates creating: # An autoscaling stack of nova instances that use cinder volumes # The default meter used to trigger scaling is: cpu_util # This template uses another template to show nested scaling # # Pre-Reqs: # Normal lab setup. Capable of launching 3 VMs # A keypair called: controller-0. (nova keypair-list) # A flavor called: small (nova flavor-list) # A glance image called: tis-centos-guest (glance image-list) # A network called: internal0-net0 (neutron net-list) # A nested template file NestedStack.yaml in the same folder as this yaml. # # Optional Template Parameters: # KEYPAIR: A keypair setup for the current user (nova keypair-list) # KEYPAIR_ADMIN_USER: The user to specify for injecting ssh keys from the # keypair into the VM # FLAVOR: A nova flavor name or UUID for the VMs (nova flavor-list) # IMAGE: A glance image name or UUID for launching VMs (glance image-list) # NETWORK: Name or UUID of the network to use for the VMs (neutron net-list) # METER_NAME: Name of the gnocchi metric to use to trigger autoscaling # (gnocchi metric list) # HIGH_VALUE: Value for the meter to trigger a scale up. # LOW_VALUE: Value for the meter to trigger a scale down. # # Tenant Considerations: # The tenant must have access to the meter type selected. # # Sample CLI syntax: # heat stack-create -f NestedAutoScale.yaml STACK # # Expected Outcome: # VMs running the guest image (nova list) # New aodh alarm triggers (aodh alarm list) # New cinder volumes for each VM (cinder list) # This template produces an output which shows the CLI syntax to help # troubleshoot autoscaling # ################################################################################ heat_template_version: 2015-04-30 description: > Demonstrates autoscaling of a nested stack The nested stack creates volumes and VMs parameters: KEYPAIR: description: keypair to use. (nova keypair-list) type: string default: controller-0 constraints: - custom_constraint: nova.keypair KEYPAIR_ADMIN_USER: description: Name of user account to inject ssh keys from keypair type: string default: 'ec2-user' FLAVOR: description: Nova flavor to use. (nova flavor-list) type: string default: small constraints: - custom_constraint: nova.flavor IMAGE: description: Glance image to create a cinder volume(glance image-list) type: string default: tis-centos-guest constraints: - custom_constraint: glance.image NETWORK: description: Name of the network to use (neutron net-list) type: string default: internal0-net0 constraints: - custom_constraint: neutron.network METER_NAME: description: Gnocchi metric to query when determining autoscaling type: string default: cpu_util RESOURCE_TYPE: description: Gnocchi resource type to use to query type: string default: instance HIGH_VALUE: description: Metric value that will trigger a scale up if exceeded type: string default: '80' LOW_VALUE: description: Metric value that will trigger a scale down if below type: string default: '30' resources: ScalingGroup: type: OS::Heat::AutoScalingGroup properties: cooldown: 60 desired_capacity: 1 max_size: 3 min_size: 1 resource: type: NestedStack.yaml properties: NAMING: { get_param: "OS::stack_name"} FLAVOR: { get_param: FLAVOR } IMAGE: { get_param: IMAGE } KEYPAIR: { get_param: KEYPAIR } KEYPAIR_ADMIN_USER: { get_param: KEYPAIR_ADMIN_USER } NETWORK: { get_param: NETWORK } METADATA: {"metering.server_group": {get_param: "OS::stack_id"}} ScaleUpPolicy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: ScalingGroup } cooldown: 60 scaling_adjustment: 1 ScaleDownPolicy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: ScalingGroup } cooldown: 60 scaling_adjustment: -1 AlarmHigh: type: OS::Aodh::GnocchiAggregationByResourcesAlarm properties: description: Scale up if the meter above threshold for 5 minutes metric: { get_param: METER_NAME } aggregation_method: mean granularity: 300 evaluation_periods: 1 threshold: { get_param: HIGH_VALUE } resource_type: { get_param: RESOURCE_TYPE } comparison_operator: gt alarm_actions: - {get_attr: [ScaleUpPolicy, alarm_url]} # gnocchi alarm resource will automatically # prepend to the query based on the meter type # metadata.metering # or metadata.user_metadata query: str_replace: template: '{"=": {"server_group": "stack_id"}}' params: stack_id: {get_param: "OS::stack_id"} AlarmLow: type: OS::Aodh::GnocchiAggregationByResourcesAlarm properties: description: Scale down if the meter below threshold for 5 minutes metric: { get_param: METER_NAME } aggregation_method: mean granularity: 300 evaluation_periods: 1 threshold: { get_param: LOW_VALUE } resource_type: { get_param: RESOURCE_TYPE } comparison_operator: lt alarm_actions: - {get_attr: [ScaleDownPolicy, alarm_url]} # gnocchi alarm resource will automatically # prepend to the query based on the meter type # metadata.metering # or metadata.user_metadata query: str_replace: template: '{"=": {"server_group": "stack_id"}}' params: stack_id: {get_param: "OS::stack_id"} outputs: gnocchi_query: value: str_replace: template: > gnocchi measures aggregation --resource-type resourcetype --query '"server_group"="stackval"' --granularity 300 --aggregation mean -m metric params: resourcetype: { get_param: RESOURCE_TYPE } metric: { get_param: METER_NAME } stackval: { get_param: "OS::stack_id" } description: > This is a Gnocchi query for statistics on the cpu_util measurements about OS::Nova::Server instances in this stack. The --resource-type select the type of Gnocchi resource. The --query parameter filters resources according to its attributes. When a VM's metadata includes an item of the form metering.server_group=X, the corresponding Gnocchi resource has a attribute named server_group that can queried with 'server_group="X"' In this case the nested stacks give their VMs metadata that is passed as a nested stack parameter, and this stack passes a metadata of the form metering.server_group=X, where X is this stack's ID. manual_scale_up: value: str_replace: template: > curl -X POST "scale_up_url" params: scale_up_url: {get_attr: [ScaleUpPolicy, alarm_url]} manual_scale_down: value: str_replace: template: > curl -X POST "scale_down_url" params: scale_down_url: {get_attr: [ScaleDownPolicy, alarm_url]}