tass-lib 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41273b54c8111e368fa32958616c8735ff6728d4
4
+ data.tar.gz: e3629695577f4e46556b75f3cf90ea136aaa0167
5
+ SHA512:
6
+ metadata.gz: 5ef9978bc8ef02b1926d705ed1a60abc8d5757480c02cc078eb30fc570389f15eb147929c633bab3549652f59ff031dacb91b466104c571005ddaffd89d978ac
7
+ data.tar.gz: 33162f84a5ad1e00ca8ae7496c9b0098b23e7871305e1a063f240d927a5bac1f043ec1f35ed8c23ab42a1485a7e78a88e2f27f5d9c07213335f2db30d97f3284
@@ -0,0 +1,48 @@
1
+ require_relative 'tass-lib/autoscaling'
2
+ require_relative 'tass-lib/elb'
3
+ require_relative 'tass-lib/ec2'
4
+ require_relative 'tass-lib/cloudwatch'
5
+ require_relative 'tass-lib/autoscaling'
6
+ require_relative 'tass-lib/Autoscaling/group'
7
+ require_relative 'tass-lib/Autoscaling/launch_config'
8
+ require 'aws-sdk-core'
9
+ require 'yaml'
10
+
11
+ module Tapjoy
12
+ # Module for Autoscaling Bootstrap
13
+ module TassLib
14
+ # This class is meant for class and instances variables used throughout
15
+ # the application.
16
+ class << self
17
+ attr_accessor :scaler_name, :config_name, :create_elb
18
+ attr_reader :elb_name
19
+
20
+ def elb_name=(str)
21
+ @elb_name = str
22
+ end
23
+
24
+ def policy
25
+ @policy = Tapjoy::TassLib::Autoscaling::Policy.new
26
+ end
27
+
28
+ def group
29
+ @group = Tapjoy::TassLib::Autoscaling::Group.new
30
+ end
31
+
32
+ def config
33
+ @config = Tapjoy::TassLib::Autoscaling::Config.new
34
+ end
35
+
36
+ def cloudwatch
37
+ @cloudwatch = Tapjoy::TassLib::CloudWatch.new
38
+ end
39
+ end
40
+
41
+ class Base
42
+ def load_yaml(filename)
43
+ abort("ERROR: '#{filename}' is not readable") unless File.readable?(filename)
44
+ Hash[YAML.load_file(filename)]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,67 @@
1
+ module Tapjoy
2
+ module TassLib
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::TassLib::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::TassLib.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::TassLib.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::TassLib.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::TassLib.scaler_name,
38
+ availability_zones: zones,
39
+ launch_configuration_name: Tapjoy::TassLib.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::TassLib::Autoscaling::Group.new.generate_tags(tags)
44
+ }
45
+
46
+ if create_elb
47
+ group_hash.merge!({
48
+ load_balancer_names: [Tapjoy::TassLib.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
+
57
+ def update(**asg_options_hash)
58
+ update_hash = {auto_scaling_group_name: Tapjoy::TassLib.scaler_name}
59
+ update_hash.merge!(asg_options_hash)
60
+ self.client.update_auto_scaling_group(**update_hash)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,45 @@
1
+ module Tapjoy
2
+ module TassLib
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::TassLib::AWS::Autoscaling.client
10
+ end
11
+
12
+ def delete
13
+ self.client.delete_launch_configuration(
14
+ launch_configuration_name: Tapjoy::TassLib.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::TassLib.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::TassLib::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 TassLib
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::TassLib.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::TassLib.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::TassLib.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::TassLib.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 TassLib
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::TassLib.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 TassLib
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::TassLib.scaler_name}")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ module Tapjoy
2
+ module TassLib
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::TassLib.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::TassLib.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::TassLib.elb_name)
45
+ end
46
+
47
+ def describe
48
+ self.client.describe_load_balancers(
49
+ load_balancer_names: [Tapjoy::TassLib.elb_name])
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ module Tapjoy
2
+ module TassLib
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 0
6
+ PATCH = 5
7
+ end
8
+
9
+ VERSION = [Version::MAJOR, Version::MINOR, Version::PATCH].join('.')
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tass-lib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Ali Tayarani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Supports Tapjoy AWS tools, primarily Tass
28
+ email: ali.tayarani@tapjoy.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/tapjoy/tass-lib.rb
34
+ - lib/tapjoy/tass-lib/Autoscaling/group.rb
35
+ - lib/tapjoy/tass-lib/Autoscaling/launch_config.rb
36
+ - lib/tapjoy/tass-lib/autoscaling.rb
37
+ - lib/tapjoy/tass-lib/cloudwatch.rb
38
+ - lib/tapjoy/tass-lib/ec2.rb
39
+ - lib/tapjoy/tass-lib/elb.rb
40
+ - lib/tapjoy/tass-lib/version.rb
41
+ homepage: https://github.com/Tapjoy/tass-lib
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.2.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Library Gem for Tapjoy Autoscaling Suite
65
+ test_files: []