Skip to content

Instantly share code, notes, and snippets.

@psachin
Last active Oct 3, 2017
Embed
What would you like to do?
Tripleo autoscale instance
heat_template_version: 2016-10-14
description: Common Template
resources:
flavor-cirros:
type: OS::Nova::Flavor
properties:
name: flavor-cirros
ram: 100
vcpus: 1
disk: 1
mykey:
type: OS::Nova::KeyPair
properties:
name: psachin-key
save_private_key: true
ping-ssh:
type: OS::Neutron::SecurityGroup
properties:
name: ping-ssh-sec-group
rules:
- protocol: tcp
remote_ip_prefix: 0.0.0.0/0
port_range_min: 22
port_range_max: 22
- protocol: icmp
remote_ip_prefix: 0.0.0.0/0
public-net:
description: External network
type: OS::Neutron::ProviderNet
properties:
name: public-net
network_type: flat
physical_network: datacentre
router_external: true
public-net-subnet:
type: OS::Neutron::Subnet
properties:
name: public-subnet
network_id: { get_resource: public-net }
cidr: 192.168.24.0/24
allocation_pools: [{"start": "192.168.24.100", "end": "192.168.24.120"}]
enable_dhcp: false
gateway_ip: "192.168.24.1"
int-green:
description: internal network
type: OS::Neutron::Net
properties:
name: int-green
int-green-subnet:
type: OS::Neutron::Subnet
properties:
name: int-green-subnet
network_id: { get_resource: int-green }
cidr: 30.0.0.0/24
dns_nameservers: ["8.8.8.8"]
router-green:
type: OS::Neutron::Router
properties:
name: route-green
external_gateway_info: { network: { get_resource: public-net }}
router-green-interface:
type: OS::Neutron::RouterInterface
properties:
router: { get_resource: router-green }
subnet: { get_resource: int-green-subnet }
resource_registry:
"OS::Nova::Server::Cirros": ./simple-stack.yaml
heat_template_version: 2016-10-14
description: Simple template to deploy a single compute instance. Need to change image name
parameters:
metadata:
type: json
image:
type: string
description: Image name or id
default: cirros
key:
type: string
default: psachin-key
flavor-cirros:
type: string
default: flavor-cirros
sec-group:
type: string
default: ping-ssh-sec-group
internal-network:
type: string
default: int-green
external-network:
type: string
default: public-net
resources:
psachin_instance-1:
type: OS::Nova::Server
properties:
key_name: { get_param: key }
image: { get_param: image }
flavor: { get_param: flavor-cirros}
metadata: {get_param: metadata}
networks:
- port: { get_resource: instance_port }
instance_port:
type: OS::Neutron::Port
properties:
network: { get_param: internal-network }
security_groups: [ { get_param: sec-group } ]
floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network: { get_param: external-network }
port_id: { get_resource: instance_port }
floating_ip_assoc:
type: OS::Neutron::FloatingIPAssociation
properties:
floatingip_id: { get_resource: floating_ip }
port_id: { get_resource: instance_port }
heat_template_version: 2016-10-14
description: Example auto scale group, policy and alarm
resources:
scaleup_group:
type: OS::Heat::AutoScalingGroup
properties:
cooldown: 60
desired_capacity: 1
max_size: 3
min_size: 1
resource:
type: OS::Nova::Server::Cirros
properties:
metadata: {"metering.server_group": {get_param: "OS::stack_id"}}
scaleup_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: { get_resource: scaleup_group }
cooldown: 60
scaling_adjustment: 1
scaledown_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: { get_resource: scaleup_group }
cooldown: 60
scaling_adjustment: -1
cpu_alarm_high:
type: OS::Aodh::GnocchiAggregationByResourcesAlarm
properties:
description: Scale up if CPU > 80%
metric: cpu_util
aggregation_method: mean
granularity: 300
evaluation_periods: 1
threshold: 50
resource_type: instance
comparison_operator: gt
ok_actions: ['log://']
insufficient_data_actions: ['log://']
alarm_actions:
- str_replace:
template: trust+url
params:
url: {get_attr: [scaleup_policy, signal_url]}
query:
str_replace:
template: '{"=": {"server_group": "stack_id"}}'
params:
stack_id: {get_param: "OS::stack_id"}
cpu_alarm_low:
type: OS::Aodh::GnocchiAggregationByResourcesAlarm
properties:
metric: cpu_util
aggregation_method: mean
granularity: 300
evaluation_periods: 1
threshold: 5
resource_type: instance
comparison_operator: le
ok_actions: ['log://']
insufficient_data_actions: ['log://']
alarm_actions:
- str_replace:
template: trust+url
params:
url: {get_attr: [scaledown_policy, signal_url]}
query:
str_replace:
template: '{"=": {"server_group": "stack_id"}}'
params:
stack_id: {get_param: "OS::stack_id"}
outputs:
scaleup_policy_signal_url:
value: {get_attr: [scaleup_policy, signal_url]}
scaledown_policy_signal_url:
value: {get_attr: [scaledown_policy, signal_url]}
@psachin
Copy link
Author

psachin commented Sep 11, 2017

Stack events

[stack@undercloud ~]$ openstack stack event list autoscale-stack
2017-09-11 13:02:59Z [autoscale-stack]: CREATE_IN_PROGRESS  Stack CREATE started
2017-09-11 13:02:59Z [autoscale-stack.scaleup_group]: CREATE_IN_PROGRESS  state changed
2017-09-11 13:03:20Z [autoscale-stack.scaleup_group]: CREATE_COMPLETE  state changed
2017-09-11 13:03:20Z [autoscale-stack.scaledown_policy]: CREATE_IN_PROGRESS  state changed
2017-09-11 13:03:20Z [autoscale-stack.scaleup_policy]: CREATE_IN_PROGRESS  state changed
2017-09-11 13:03:21Z [autoscale-stack.scaledown_policy]: CREATE_COMPLETE  state changed
2017-09-11 13:03:21Z [autoscale-stack.cpu_alarm_low]: CREATE_IN_PROGRESS  state changed
2017-09-11 13:03:21Z [autoscale-stack.scaleup_policy]: CREATE_COMPLETE  state changed
2017-09-11 13:03:21Z [autoscale-stack.cpu_alarm_high]: CREATE_IN_PROGRESS  state changed
2017-09-11 13:03:29Z [autoscale-stack.cpu_alarm_high]: CREATE_COMPLETE  state changed
2017-09-11 13:03:30Z [autoscale-stack.cpu_alarm_low]: CREATE_COMPLETE  state changed
2017-09-11 13:03:30Z [autoscale-stack]: CREATE_COMPLETE  Stack CREATE completed successfully
2017-09-11 13:23:06Z [autoscale-stack.scaleup_policy]: SIGNAL_COMPLETE  alarm state changed from insufficient data to alarm (Transition to alarm due to 1 samples outside threshold, most recent: 99.3633665171)
2017-09-11 13:26:22Z [autoscale-stack.scaleup_policy]: SIGNAL_COMPLETE  alarm state changed from alarm to alarm (Remaining as alarm due to 1 samples outside threshold, most recent: 99.3633665171)
2017-09-11 13:44:08Z [autoscale-stack.scaledown_policy]: SIGNAL_COMPLETE  alarm state changed from ok to alarm (Transition to alarm due to 1 samples outside threshold, most recent: 2.57545880786)
2017-09-11 13:46:41Z [autoscale-stack.scaledown_policy]: SIGNAL_COMPLETE  alarm state changed from alarm to alarm (Remaining as alarm due to 1 samples outside threshold, most recent: 2.57545880786)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment