Class: Cucloud::AsgUtils
- Inherits:
-
Object
- Object
- Cucloud::AsgUtils
- Defined in:
- lib/cucloud/asg_utils.rb
Overview
AsgUtils - Utilities for AutoScaling groups
Instance Method Summary collapse
-
#create_launch_configuration(options) ⇒ Seahorse::Client::Response
Create new launch configuration in AWS.
-
#generate_lc_options_hash_with_ami(launch_config, new_ami_id, new_launch_config_name = "cucloud-lc-#{UUID.new.generate}") ⇒ Hash
Generate a hash that can be submitted when creating a new launch config - replace image with desired AMI.
-
#get_asg_by_name(name) ⇒ Aws::AutoScaling::Types::AutoScalingGroup
Get an autoscale instance by group name.
-
#get_launch_configuration_by_name(launch_config_name) ⇒ Aws::AutoScaling::Types::LaunchConfiguration
get an instance of the launch configuration for a given autoscaling group.
-
#initialize(asg_client = Aws::AutoScaling::Client.new) ⇒ AsgUtils
constructor
Constructor for AsgUtils class.
-
#update_asg_launch_configuration!(asg_name, launch_config_name) ⇒ Seahorse::Client::Response
Update autoscale group launch configuration.
Constructor Details
#initialize(asg_client = Aws::AutoScaling::Client.new) ⇒ AsgUtils
Constructor for AsgUtils class
8 9 10 11 |
# File 'lib/cucloud/asg_utils.rb', line 8 def initialize(asg_client = Aws::AutoScaling::Client.new) ## DI for testing purposes @asg = asg_client end |
Instance Method Details
#create_launch_configuration(options) ⇒ Seahorse::Client::Response
Create new launch configuration in AWS
52 53 54 55 |
# File 'lib/cucloud/asg_utils.rb', line 52 def create_launch_configuration() # https://docs.aws.amazon.com/sdkforruby/api/Aws/AutoScaling/Client.html#create_launch_configuration-instance_method @asg.create_launch_configuration() end |
#generate_lc_options_hash_with_ami(launch_config, new_ami_id, new_launch_config_name = "cucloud-lc-#{UUID.new.generate}") ⇒ Hash
Generate a hash that can be submitted when creating a new launch config - replace image with desired AMI
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cucloud/asg_utils.rb', line 34 def (launch_config, new_ami_id, new_launch_config_name = "cucloud-lc-#{UUID.new.generate}") # make sure we got a valid launch config raise 'Not a launch configuration struct' unless launch_config.is_a? Aws::AutoScaling::Types::LaunchConfiguration # convert to hash (required for aws sdk) and update necessary values config_hash = launch_config.to_h config_hash[:launch_configuration_name] = new_launch_config_name config_hash[:image_id] = new_ami_id # request cannot have arn, created_time or keys with empty values config_hash.delete_if { |key, value| key == :launch_configuration_arn || key == :created_time || value == '' } end |
#get_asg_by_name(name) ⇒ Aws::AutoScaling::Types::AutoScalingGroup
Get an autoscale instance by group name
16 17 18 19 |
# File 'lib/cucloud/asg_utils.rb', line 16 def get_asg_by_name(name) # https://docs.aws.amazon.com/sdkforruby/api/Aws/AutoScaling/Client.html#describe_auto_scaling_groups-instance_method @asg.describe_auto_scaling_groups(auto_scaling_group_names: [name]).auto_scaling_groups.first end |
#get_launch_configuration_by_name(launch_config_name) ⇒ Aws::AutoScaling::Types::LaunchConfiguration
get an instance of the launch configuration for a given autoscaling group
24 25 26 27 |
# File 'lib/cucloud/asg_utils.rb', line 24 def get_launch_configuration_by_name(launch_config_name) # https://docs.aws.amazon.com/sdkforruby/api/Aws/AutoScaling/Client.html#describe_launch_configurations-instance_method @asg.describe_launch_configurations(launch_configuration_names: [launch_config_name]).launch_configurations.first end |
#update_asg_launch_configuration!(asg_name, launch_config_name) ⇒ Seahorse::Client::Response
Update autoscale group launch configuration
61 62 63 64 65 |
# File 'lib/cucloud/asg_utils.rb', line 61 def update_asg_launch_configuration!(asg_name, launch_config_name) # https://docs.aws.amazon.com/sdkforruby/api/Aws/AutoScaling/Client.html#update_auto_scaling_group-instance_method @asg.update_auto_scaling_group(auto_scaling_group_name: asg_name, launch_configuration_name: launch_config_name) end |