tass 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +7 -0
  2. data/bin/tass +97 -0
  3. data/lib/tapjoy/autoscaling_bootstrap/AWS/Autoscaling/group.rb +61 -0
  4. data/lib/tapjoy/autoscaling_bootstrap/AWS/Autoscaling/launch_config.rb +45 -0
  5. data/lib/tapjoy/autoscaling_bootstrap/AWS/autoscaling.rb +45 -0
  6. data/lib/tapjoy/autoscaling_bootstrap/AWS/cloudwatch.rb +41 -0
  7. data/lib/tapjoy/autoscaling_bootstrap/AWS/ec2.rb +23 -0
  8. data/lib/tapjoy/autoscaling_bootstrap/AWS/elb.rb +55 -0
  9. data/lib/tapjoy/autoscaling_bootstrap/alerts/monitoring.rb +38 -0
  10. data/lib/tapjoy/autoscaling_bootstrap/alerts/scaling.rb +75 -0
  11. data/lib/tapjoy/autoscaling_bootstrap/alerts.rb +7 -0
  12. data/lib/tapjoy/autoscaling_bootstrap/audit.rb +49 -0
  13. data/lib/tapjoy/autoscaling_bootstrap/autoscaling/config.rb +38 -0
  14. data/lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb +113 -0
  15. data/lib/tapjoy/autoscaling_bootstrap/autoscaling/policy.rb +37 -0
  16. data/lib/tapjoy/autoscaling_bootstrap/autoscaling.rb +6 -0
  17. data/lib/tapjoy/autoscaling_bootstrap/autoscaling_group.rb +59 -0
  18. data/lib/tapjoy/autoscaling_bootstrap/aws.rb +7 -0
  19. data/lib/tapjoy/autoscaling_bootstrap/cloudwatch.rb +29 -0
  20. data/lib/tapjoy/autoscaling_bootstrap/configure_autoscaler.rb +40 -0
  21. data/lib/tapjoy/autoscaling_bootstrap/elb.rb +56 -0
  22. data/lib/tapjoy/autoscaling_bootstrap/errors/elb.rb +48 -0
  23. data/lib/tapjoy/autoscaling_bootstrap/errors.rb +30 -0
  24. data/lib/tapjoy/autoscaling_bootstrap/launch_configuration.rb +42 -0
  25. data/lib/tapjoy/autoscaling_bootstrap/version.rb +11 -0
  26. data/lib/tapjoy/autoscaling_bootstrap.rb +165 -0
  27. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a59b4519fd31ade584e3b01e4e2e9e710398b0d7
4
+ data.tar.gz: bcaf7a3d8ea6ceb7aaf543cee80cb9c9d8f56e8b
5
+ SHA512:
6
+ metadata.gz: bb7a05c28477783135d2685371d8e8013f313b0d74907568ea90be27fc122b53c543a10e3c526f1ea1b7629393dccb9364b210d60fb6e7086d0b123d323f9135
7
+ data.tar.gz: f63a73d33066180446250213a0f6ccacf5a9e71ea6ce776edca5218871431361de810c4b150997dc6d01792e3c61334fb3a73bd0f18af3711664bb0087a9c9c5
data/bin/tass ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tapjoy/autoscaling_bootstrap'
4
+
5
+ def confirm_config(aws_env, misc_config, opts)
6
+ use_vpc = true if misc_config[:vpc_subnets]
7
+ unless Tapjoy::AutoscalingBootstrap::Base.new.confirm_config(**aws_env,
8
+ **misc_config, **opts, use_vpc: use_vpc)
9
+
10
+ abort('Cannot continue if configuration is not correct. Please fix.')
11
+ end
12
+ end
13
+
14
+ def supported_envs(listing)
15
+ envs = []
16
+ Dir.entries("#{listing}/config/common").each do |file|
17
+ next unless file.end_with?('yaml')
18
+ next if file.start_with?('defaults')
19
+ envs << file.chomp!('.yaml')
20
+ end
21
+ envs
22
+ end
23
+
24
+ SUB_COMMANDS = %w(create update audit)
25
+ Trollop::options do
26
+ usage '[SUB_COMMAND] [options]'
27
+ synopsis "\nConfigures autoscaling groups.\nAvailable subcommands are: #{SUB_COMMANDS}"
28
+ version "#{File.basename($0)} #{Tapjoy::AutoscalingBootstrap::VERSION} \u00A9 2015 Tapjoy, Inc."
29
+ stop_on SUB_COMMANDS
30
+ end
31
+
32
+ cmd = ARGV.shift
33
+ case cmd
34
+ when 'create'
35
+ opts = Trollop.options do
36
+ # Set help message
37
+ usage 'create [options]'
38
+ synopsis 'This command creates new autoscaling groups, and overwrites existing ones.'
39
+
40
+ opt :filename, 'Specify config file to load', type: :string, required: true
41
+ opt :config_dir, 'Specify the directory for configuration files', type: :string, short: :none, default: Tapjoy::AutoscalingBootstrap.config_dir
42
+ opt :env, 'Specify which environment config to load', required: true, type: :string
43
+ opt :clobber_elb, 'Force ELB creation', default: false, short: :none
44
+ opt :clobber_as, 'Force AS group creation', default: false, short: :none
45
+ opt :prompt, 'Enable/disable prompts', default: true
46
+ end
47
+
48
+ env_list = supported_envs(opts[:config_dir])
49
+ unless env_list.include?(opts[:env])
50
+ Trollop.die :env, "Currently supported enviroments are #{env_list.join(',')}"
51
+ end
52
+
53
+ config, aws_env, user_data = Tapjoy::AutoscalingBootstrap::Base.new.configure_environment(opts[:filename], opts[:env], opts[:config_dir])
54
+ Aws.config[:region] = config[:aws_region]
55
+ confirm_config(aws_env, config, opts)
56
+
57
+ Tapjoy::AutoscalingBootstrap::Base.new.check_clobber(opts, config)
58
+ Tapjoy::AutoscalingBootstrap::AutoscalingGroup.new.create(opts, config, aws_env, user_data)
59
+ when 'update'
60
+ opts = Trollop.options do
61
+ # Set help message
62
+ usage 'update [options]'
63
+ synopsis 'This command creates new launch configurations based on existing autoscaling groups using local instance configuration files as overrides.'
64
+ opt :filename, 'Specify config file to load', type: :string, required: true
65
+ opt :config_dir, 'Specify the directory for configuration files', type: :string, short: :none, default: Tapjoy::AutoscalingBootstrap.config_dir
66
+ opt :env, 'Specify which environment config to load', required: true, type: :string
67
+ opt :prompt, 'Enable/disable prompts', default: true
68
+ end
69
+
70
+ env_list = supported_envs(opts[:config_dir])
71
+ unless env_list.include?(opts[:env])
72
+ Trollop.die :env, "Currently supported enviroments are #{env_list.join(',')}"
73
+ end
74
+
75
+ config, aws_env, user_data = Tapjoy::AutoscalingBootstrap::Base.new.configure_environment(opts[:filename], opts[:env], opts[:config_dir])
76
+ Aws.config[:region] = config[:aws_region]
77
+ confirm_config(aws_env, config, opts)
78
+
79
+ Tapjoy::AutoscalingBootstrap::LaunchConfiguration.new(config, aws_env, user_data)
80
+ when 'audit'
81
+ opts = Trollop.options do
82
+ usage 'audit'
83
+ synopsis 'This command compares local configuration files for a given cluster to the existing launch configuration and autoscaling group running in AWS.'
84
+ opt :filename, 'Specify config file to load', type: :string, required: true
85
+ opt :config_dir, 'Specify the directory for configuration files', type: :string, short: :none, default: Tapjoy::AutoscalingBootstrap.config_dir
86
+ opt :env, 'Specify which environment config to load', required: true, type: :string
87
+ opt :prompt, 'Enable/disable prompts', default: true
88
+ end
89
+
90
+ config, aws_env, user_data = Tapjoy::AutoscalingBootstrap::Base.new.configure_environment(opts[:filename], opts[:env], opts[:config_dir])
91
+ Aws.config[:region] = config[:aws_region]
92
+
93
+ config.merge!(aws_env.merge({user_data: Base64.encode64("#{user_data}")}))
94
+ Tapjoy::AutoscalingBootstrap::Audit.new(config)
95
+ else
96
+ Trollop.educate
97
+ end
@@ -0,0 +1,61 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module AWS
4
+ module Autoscaling
5
+ # This module includes autoscaling group calls to AWS
6
+ module Group
7
+ class << self
8
+ def client
9
+ @client ||= Tapjoy::AutoscalingBootstrap::AWS::Autoscaling.client
10
+ end
11
+
12
+ def resize(min_size: 0, max_size: 0, desired_capacity:0)
13
+ self.client.update_auto_scaling_group(
14
+ auto_scaling_group_name: Tapjoy::AutoscalingBootstrap.scaler_name,
15
+ min_size: min_size, max_size: max_size,
16
+ desired_capacity: desired_capacity)
17
+ end
18
+
19
+ def delete(force_delete: true)
20
+ self.client.delete_auto_scaling_group(
21
+ auto_scaling_group_name: Tapjoy::AutoscalingBootstrap.scaler_name,
22
+ force_delete: force_delete)
23
+ end
24
+
25
+ def describe
26
+ self.client.describe_auto_scaling_groups(
27
+ auto_scaling_group_names: [
28
+ Tapjoy::AutoscalingBootstrap.scaler_name
29
+ ]
30
+ )[0][0]
31
+ end
32
+
33
+ def create(zones:, health_check_type: nil, tags:,
34
+ vpc_subnets: nil, create_elb:, **unused_values)
35
+
36
+ group_hash = {
37
+ auto_scaling_group_name: Tapjoy::AutoscalingBootstrap.scaler_name,
38
+ availability_zones: zones,
39
+ launch_configuration_name: Tapjoy::AutoscalingBootstrap.config_name,
40
+ min_size: 0, max_size: 0, desired_capacity: 0,
41
+ termination_policies: ['OldestInstance'],
42
+ vpc_zone_identifier: vpc_subnets,
43
+ tags: Tapjoy::AutoscalingBootstrap::Autoscaling::Group.new.generate_tags(tags)
44
+ }
45
+
46
+ if create_elb
47
+ group_hash.merge!({
48
+ load_balancer_names: [Tapjoy::AutoscalingBootstrap.elb_name],
49
+ health_check_type: health_check_type,
50
+ health_check_grace_period: 300,
51
+ })
52
+ end
53
+
54
+ self.client.create_auto_scaling_group(**group_hash)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,45 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module AWS
4
+ module Autoscaling
5
+ # This module includes autoscaling launch config calls to AWS
6
+ module LaunchConfig
7
+ class << self
8
+ def client
9
+ @client ||= Tapjoy::AutoscalingBootstrap::AWS::Autoscaling.client
10
+ end
11
+
12
+ def delete
13
+ self.client.delete_launch_configuration(
14
+ launch_configuration_name: Tapjoy::AutoscalingBootstrap.config_name)
15
+ end
16
+
17
+ def create(image_id:, instance_type:, security_groups:, user_data:,
18
+ keypair:, iam_instance_profile:, classic_link_vpc_id: nil,
19
+ classic_link_sg_ids: nil, **unused_values)
20
+
21
+ self.client.create_launch_configuration(
22
+ launch_configuration_name: Tapjoy::AutoscalingBootstrap.config_name,
23
+ image_id: image_id,
24
+ iam_instance_profile: iam_instance_profile,
25
+ instance_type: instance_type,
26
+ security_groups: security_groups,
27
+ user_data: "#{Tapjoy::AutoscalingBootstrap::Autoscaling::Group.new.encode_user_data(user_data)}",
28
+ key_name: keypair,
29
+ classic_link_vpc_id: classic_link_vpc_id,
30
+ classic_link_vpc_security_groups: classic_link_sg_ids,
31
+ )
32
+ end
33
+
34
+ def describe(config_name)
35
+ # config_name is scoped locally, since we can't always be sure
36
+ # that we are using the default launch_configuration name
37
+ self.client.describe_launch_configurations(
38
+ launch_configuration_names:[config_name])[0][0]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module AWS
4
+ # This class contains AWS methods for ELB
5
+ module Autoscaling
6
+ class << self
7
+ def client
8
+ @client ||= Aws::AutoScaling::Client.new
9
+ end
10
+
11
+ def put_notification_configuration(sns_base_arn:, **unused_values)
12
+ self.client.put_notification_configuration(
13
+ auto_scaling_group_name: Tapjoy::AutoscalingBootstrap.scaler_name,
14
+ topic_arn: "#{sns_base_arn}:InstanceTerminated",
15
+ notification_types: ['autoscaling:EC2_INSTANCE_TERMINATE']
16
+ )
17
+ end
18
+
19
+ def put_scaling_policy(policy_name: policy, scaling_adjustment:,
20
+ cooldown:, **unused_values)
21
+
22
+ self.client.put_scaling_policy(policy_name: policy_name,
23
+ auto_scaling_group_name: Tapjoy::AutoscalingBootstrap.scaler_name,
24
+ scaling_adjustment: scaling_adjustment,
25
+ cooldown: cooldown,
26
+ adjustment_type: 'ChangeInCapacity'
27
+ )[0]
28
+ end
29
+
30
+ def describe_policies(policy:)
31
+ self.client.describe_policies(
32
+ auto_scaling_group_name: Tapjoy::AutoscalingBootstrap.scaler_name,
33
+ policy_names: [policy])
34
+ end
35
+
36
+ def delete_policy(policy:)
37
+ self.client.delete_policy(
38
+ auto_scaling_group_name: Tapjoy::AutoscalingBootstrap.scaler_name,
39
+ policy_name: policy)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module AWS
4
+ # This class contains AWS methods for ELB
5
+ module Cloudwatch
6
+ class << self
7
+ def client
8
+ @client ||= Aws::CloudWatch::Client.new
9
+ end
10
+
11
+ def put_metric_alarm(alarm:, comparison_operator:,
12
+ evaluation_periods:, threshold:, actions:)
13
+ self.client.put_metric_alarm(alarm_name: alarm,
14
+ comparison_operator: comparison_operator,
15
+ evaluation_periods: evaluation_periods,
16
+ metric_name: 'CPUUtilization',
17
+ namespace: 'AWS/EC2',
18
+ period: 300,
19
+ statistic: 'Average',
20
+ threshold: threshold,
21
+ alarm_actions: actions,
22
+ dimensions: [
23
+ {
24
+ name:'AutoScalingGroupName',
25
+ value: Tapjoy::AutoscalingBootstrap.scaler_name
26
+ }
27
+ ])
28
+ end
29
+
30
+ def describe_alarm(alarm)
31
+ self.client.describe_alarms(alarm_names: [alarm])[0]
32
+ end
33
+
34
+ def delete_alarm(alarm)
35
+ self.client.delete_alarms(alarm_names: [alarm])
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module AWS
4
+ # This class contains AWS methods for ELB
5
+ module EC2
6
+ class << self
7
+ def client
8
+ @client ||= Aws::EC2::Client.new
9
+ end
10
+
11
+ def describe_security_groups(group)
12
+ self.client.describe_security_groups(group_names: [group])
13
+ end
14
+
15
+ def create_security_group(group)
16
+ self.client.create_security_group(group_name: group,
17
+ description: "Security group for #{Tapjoy::AutoscalingBootstrap.scaler_name}")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module AWS
4
+ # This class contains AWS methods for ELB
5
+ module ELB
6
+ class << self
7
+ def client
8
+ @client ||= Aws::ElasticLoadBalancing::Client.new
9
+ end
10
+
11
+ # Creates ELB
12
+ def create(elb_protocol:, elb_port:, instance_protocol:,
13
+ instance_port:, zones:, **unused_values)
14
+ self.client.create_load_balancer(
15
+ load_balancer_name: Tapjoy::AutoscalingBootstrap.elb_name,
16
+ listeners: [
17
+ { protocol: elb_protocol, load_balancer_port: elb_port,
18
+ instance_protocol: instance_protocol,
19
+ instance_port: instance_port
20
+ }
21
+ ],
22
+ availability_zones: zones)
23
+ end
24
+
25
+ # Configures health check in AWS
26
+ def health_check(elb_health_target:, elb_health_interval:,
27
+ elb_health_timeout:, elb_unhealthy_threshold:,
28
+ elb_healthy_threshold:, **unused_values)
29
+
30
+ self.client.configure_health_check(
31
+ load_balancer_name: Tapjoy::AutoscalingBootstrap.elb_name,
32
+ health_check: {
33
+ target: elb_health_target,
34
+ interval: elb_health_interval,
35
+ timeout: elb_health_timeout,
36
+ unhealthy_threshold: elb_unhealthy_threshold,
37
+ healthy_threshold: elb_healthy_threshold
38
+ })
39
+ end
40
+
41
+ # Deletes existing ELB
42
+ def delete
43
+ self.client.delete_load_balancer(
44
+ load_balancer_name: Tapjoy::AutoscalingBootstrap.elb_name)
45
+ end
46
+
47
+ def describe
48
+ self.client.describe_load_balancers(
49
+ load_balancer_names: [Tapjoy::AutoscalingBootstrap.elb_name])
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module Alerts
4
+ # Class to handle monitoring alerts
5
+ class Monitoring
6
+ # Create monitoring alerts
7
+ def create(alarm_high_alert:, alarm_low_alert:, notification:)
8
+
9
+ high_alert = {
10
+ alarm: alarm_high_alert,
11
+ comparison_operator: 'GreaterThanOrEqualToThreshold',
12
+ evaluation_periods: 1,
13
+ threshold: 90,
14
+ actions: [notification]
15
+ }
16
+
17
+ low_alert = {
18
+ alarm: alarm_low_alert,
19
+ comparison_operator: 'LessThanOrEqualToThreshold',
20
+ evaluation_periods: 1,
21
+ threshold: 35,
22
+ actions: [notification]
23
+ }
24
+ puts 'Clearing out original CloudWatch alarms'
25
+ Tapjoy::AutoscalingBootstrap::Cloudwatch.delete_alarm(alarm_high_alert)
26
+ Tapjoy::AutoscalingBootstrap::Cloudwatch.delete_alarm(alarm_low_alert)
27
+
28
+ puts 'Creating new CloudWatch Alarms'
29
+ Tapjoy::AutoscalingBootstrap::Cloudwatch.create_alarm(high_alert)
30
+ puts "\n"
31
+
32
+ Tapjoy::AutoscalingBootstrap::Cloudwatch.create_alarm(low_alert)
33
+ puts "\n"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,75 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module Alerts
4
+ # Class to handle scaling alerts
5
+ class Scaling
6
+ # Initialize the class
7
+ def initialize(config)
8
+ @policy = Tapjoy::AutoscalingBootstrap.policy
9
+
10
+ scale_up, scale_down = prepare(**config)
11
+
12
+ create(config[:policy_up], scale_up)
13
+ create(config[:policy_down], scale_down)
14
+ end
15
+
16
+ # Prepare scaling alerts
17
+ def prepare(alarm_high_scale:, alarm_low_scale:, policy_up:,
18
+ policy_down:, scale_up_scaling_adjustment:, scale_up_cooldown:,
19
+ scale_up_threshold:, scale_down_scaling_adjustment:,
20
+ scale_down_cooldown:, scale_down_threshold:, **unused_values)
21
+
22
+ puts 'Creating autoscale alerts and policies'
23
+
24
+ puts 'Clearing out original CloudWatch alarms'
25
+ Tapjoy::AutoscalingBootstrap::Cloudwatch.delete_alarm(alarm_high_scale)
26
+ Tapjoy::AutoscalingBootstrap::Cloudwatch.delete_alarm(alarm_low_scale)
27
+ puts "\n"
28
+
29
+ puts 'Clearing out original scaling policies'
30
+ @policy.delete(policy_up)
31
+ @policy.delete(policy_down)
32
+ puts "\n"
33
+
34
+ puts 'Configuring autoscaling...'
35
+ scale_up = {
36
+ scaling_adjustment: scale_up_scaling_adjustment,
37
+ cooldown: scale_up_cooldown,
38
+ threshold: scale_up_threshold,
39
+ alarm: alarm_high_scale,
40
+ comparison_operator: 'GreaterThanOrEqualToThreshold'
41
+ }
42
+
43
+ scale_down = {
44
+ scaling_adjustment: scale_down_scaling_adjustment,
45
+ cooldown: scale_down_cooldown,
46
+ threshold: scale_down_threshold,
47
+ alarm: alarm_low_scale,
48
+ comparison_operator: 'LessThanOrEqualToThreshold'
49
+ }
50
+
51
+ return scale_up, scale_down
52
+ end
53
+
54
+ # Create alerts for autoscaling
55
+ def create(policy, scale)
56
+
57
+ puts "Creating scale policy: #{policy}"
58
+ scale_policy = @policy.create(policy,
59
+ **scale)
60
+
61
+ scale_alert = {
62
+ alarm: scale[:alarm],
63
+ comparison_operator: scale[:comparison_operator],
64
+ evaluation_periods: 3,
65
+ threshold: scale[:threshold],
66
+ actions: [scale_policy]
67
+ }
68
+
69
+ puts "Creating alarms for scale policy: #{scale_policy}"
70
+ Tapjoy::AutoscalingBootstrap::Cloudwatch.create_alarm(scale_alert)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,7 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ # Module to handle alerts
4
+ module Alerts
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ # This class handles the comparison of local configs against upstream
4
+ class Audit
5
+ def initialize(config)
6
+ local_config = Hash(**clean_local_hash(config))
7
+
8
+ remote_launch_config = Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::LaunchConfig.describe(Tapjoy::AutoscalingBootstrap.config_name).to_h
9
+ remote_group_config = Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::Group.describe.to_h
10
+ # Combine launch config and group config into a single hash
11
+ remote_config = remote_launch_config.merge!(remote_group_config)
12
+ clean_remote_hash(remote_config)
13
+ puts "\n\n\n"
14
+ HashDiff.diff(local_config, remote_config).each do |op, key, value|
15
+ puts "%s %s %-60s" % [op, key, value]
16
+ end
17
+ end
18
+
19
+ private
20
+ # fix key names to match AWS standards
21
+ def clean_local_hash(config)
22
+ config[:key_name] = config.delete :keypair
23
+ config[:launch_configuration_name] = Tapjoy::AutoscalingBootstrap.config_name
24
+ keys = %w(bootstrap_script chef_server_url clobber clobber_elb
25
+ create_as_group config_dir)
26
+ delete_keys(config, keys)
27
+
28
+ config
29
+ end
30
+
31
+ # Remove keys that the local config does not support
32
+ def clean_remote_hash(config)
33
+ keys = %w(kernel_id instances desired_capacity min_size max_size
34
+ ramdisk_id)
35
+ delete_keys(config, keys)
36
+ config[:tags].each do |tag|
37
+ delete_keys(tag, %w(resource_id))
38
+ tag[tag[:key].to_sym] = tag.delete :value
39
+ delete_keys(tag, %w(resource_type propagate_at_launch key))
40
+ end
41
+ end
42
+
43
+ # Helper method to delete keys
44
+ def delete_keys(config, keys)
45
+ keys.each {|key| config.delete key.to_sym}
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ module Tapjoy
2
+ module AutoscalingBootstrap
3
+ module Autoscaling
4
+ # Code specific to Launch Configs
5
+ class Config
6
+
7
+ # Create launch configuration
8
+ def create(config, aws_env, user_data)
9
+
10
+ if exists
11
+ delete
12
+ else
13
+ puts "Launch config #{Tapjoy::AutoscalingBootstrap.config_name} does not exist, continuing..."
14
+ end
15
+
16
+ puts "Creating launch config: #{Tapjoy::AutoscalingBootstrap.config_name}"
17
+ begin
18
+ Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::LaunchConfig.create(
19
+ **config, **aws_env, user_data: user_data)
20
+ rescue Aws::AutoScaling::Errors::ValidationError => err
21
+ STDERR.puts "Cannot create launch configuration: #{err}"
22
+ end
23
+ end
24
+
25
+ # Check if launch configuration exists
26
+ def exists
27
+ !Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::LaunchConfig.describe(
28
+ Tapjoy::AutoscalingBootstrap.config_name).nil?
29
+ end
30
+
31
+ def delete
32
+ puts "Deleting launch config #{Tapjoy::AutoscalingBootstrap.config_name}"
33
+ Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::LaunchConfig.delete
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end