Skip to content

Instantly share code, notes, and snippets.

@StephenKing
Last active October 20, 2021 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save StephenKing/13987089075af2cb72d43fee4a0c1ef4 to your computer and use it in GitHub Desktop.
Save StephenKing/13987089075af2cb72d43fee4a0c1ef4 to your computer and use it in GitHub Desktop.
Assigning a Floating IP Address to Each Instance of an Autoscaling Group in OpenStack Heat
heat_template_version: 2013-05-23
description: >
This template creates an AutoScalingGroup based on the stack
defined in the file `server_with_floating.yaml`.
parameters:
key_name:
type: string
description: Name of an existing key pair to use for the instances
constraints:
- custom_constraint: nova.keypair
description: Must name a public key (pair) known to Nova
flavor:
type: string
description: Flavor for the instances to be created
default: m1.small
constraints:
- custom_constraint: nova.flavor
description: Must be a flavor known to Nova
image:
type: string
description: >
Name or ID of the image to use for the instances.
You can get the default from
constraints:
- custom_constraint: glance.image
description: Must identify an image known to Glance
network:
type: string
description: The network for the VM
constraints:
- {custom_constraint: neutron.network}
public_net:
type: string
description: >
ID of public network for which floating IP addresses will be allocated
constraints:
- {custom_constraint: neutron.network}
resources:
asg:
type: OS::Heat::AutoScalingGroup
properties:
resource:
type: server_with_floating.yaml
properties:
key_name: { get_param: key_name }
image: { get_param: image }
flavor: { get_param: flavor }
network: { get_param: network }
public_net: { get_param: public_net}
min_size: 1
desired_capacity: 3
max_size: 20
scale_up_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: asg}
cooldown: 1
scaling_adjustment: 3
scale_dn_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: asg}
cooldown: 1
scaling_adjustment: '-1'
outputs:
scale_up_url:
description: >
This URL is the webhook to scale up the group. You can invoke
the scale-up operation by doing an HTTP POST to this URL; no
body nor extra headers are needed.
value: {get_attr: [scale_up_policy, alarm_url]}
scale_dn_url:
description: >
This URL is the webhook to scale down the group. You can invoke
the scale-down operation by doing an HTTP POST to this URL; no
body nor extra headers are needed.
value: {get_attr: [scale_dn_policy, alarm_url]}
#!/bin/bash
openstack stack create my-test-stack --template asg_of_server_with_floating.yaml -e environment.yaml
parameters:
key_name: admin
flavor: m1.small
image: Ubuntu 14.04 (trusty)
network: 1234567-...................
public_net: 1234567-...................
heat_template_version: 2013-05-23
description: >
Creates a server and assigns a floating IP.
parameters:
key_name:
type: string
description: Name of an existing key pair to use for the instances
constraints:
- custom_constraint: nova.keypair
description: Must name a public key (pair) known to Nova
flavor:
type: string
description: Flavor for the instances to be created
default: m1.small
constraints:
- custom_constraint: nova.flavor
description: Must be a flavor known to Nova
image:
type: string
description: >
Name or ID of the image to use for the instances.
You can get the default from
constraints:
- custom_constraint: glance.image
description: Must identify an image known to Glance
network:
type: string
description: The network for the VM
constraints:
- {custom_constraint: neutron.network}
public_net:
type: string
description: >
ID of public network for which floating IP addresses will be allocated
constraints:
- {custom_constraint: neutron.network}
resources:
server1:
type: OS::Nova::Server
properties:
name: Server with Floating IP
image: { get_param: image }
flavor: { get_param: flavor }
key_name: { get_param: key_name }
networks:
- port: { get_resource: server1_port }
server1_port:
type: OS::Neutron::Port
properties:
network_id: { get_param: network }
security_groups: [{ get_resource: server_security_group }]
server1_floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net }
port_id: { get_resource: server1_port }
server_security_group:
type: OS::Neutron::SecurityGroup
properties:
description: Add security group rules for server
name: security-group
rules:
- remote_ip_prefix: 0.0.0.0/0
protocol: tcp
port_range_min: 22
port_range_max: 22
- remote_ip_prefix: 0.0.0.0/0
protocol: icmp
outputs:
server1_private_ip:
description: IP address of server1 in private network
value: { get_attr: [ server1, first_address ] }
server1_public_ip:
description: Floating IP address of server1 in public network
value: { get_attr: [ server1_floating_ip, floating_ip_address ] }
@StephenKing
Copy link
Author

screenshot

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