aws-asg-fleet 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -12
- data/asg-fleet.gemspec +1 -1
- data/lib/aws/auto_scaling/fleet.rb +23 -4
- data/lib/aws/auto_scaling/fleet_collection.rb +0 -11
- data/lib/aws/auto_scaling/fleet_group_collection.rb +0 -135
- metadata +2 -2
data/README.md
CHANGED
@@ -121,20 +121,11 @@ fleet.update_launch_configuration('new-launch-config',
|
|
121
121
|
That will create a new launch configuration, and add it to all the
|
122
122
|
groups, replacing the old one.
|
123
123
|
|
124
|
-
Above, we showed how to add a group you've already created to the fleet.
|
125
|
-
You can also create a group *based on the existing template group*. This
|
126
|
-
method will create a new group using options you pass in, but any
|
127
|
-
options you don't specify will be pulled from the template group. Policies
|
128
|
-
and alarms also get duplicated for the new group:
|
129
|
-
|
130
|
-
```ruby
|
131
|
-
fleet.groups.create('yet-another-group',
|
132
|
-
:load_balancers => [ 'my-other-elb' ])
|
133
|
-
```
|
134
|
-
|
135
124
|
## How It Works
|
136
125
|
|
137
126
|
Fleets are identified using tags on Auto Scaling groups. When you create
|
138
127
|
a new fleet 'my-fleet', it adds the tag key "asgfleet:my-fleet" with
|
139
128
|
value "template". Other groups added to the fleet get tagged with key
|
140
|
-
"asgfleet:my-fleet" and value "member".
|
129
|
+
"asgfleet:my-fleet" and value "member". If you don't have a group tagged
|
130
|
+
with "template" and attempt to perform a `update_launch_configuration`, it
|
131
|
+
will use the first group tagged as a member instead.
|
data/asg-fleet.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "aws-asg-fleet"
|
8
|
-
spec.version = "0.0.
|
8
|
+
spec.version = "0.0.4"
|
9
9
|
spec.authors = ["Zach Wily"]
|
10
10
|
spec.email = ["zach@zwily.com"]
|
11
11
|
spec.description = %q{AWS Auto Scaling Fleets}
|
@@ -10,24 +10,43 @@ module AWS
|
|
10
10
|
# @return [String]
|
11
11
|
attr_reader :name
|
12
12
|
|
13
|
+
def tag_name
|
14
|
+
"asgfleet:#{name}"
|
15
|
+
end
|
16
|
+
|
13
17
|
# @return [Group]
|
14
18
|
def template_group
|
15
19
|
tag = TagCollection.new(:config => config)
|
16
|
-
.filter(:key,
|
20
|
+
.filter(:key, tag_name)
|
17
21
|
.filter(:value, "template")
|
18
22
|
.first
|
23
|
+
|
24
|
+
return nil unless tag
|
25
|
+
tag.resource
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Group]
|
29
|
+
def any_group
|
30
|
+
tag = TagCollection.new(:config => config)
|
31
|
+
.filter(:key, tag_name)
|
32
|
+
.first
|
33
|
+
|
19
34
|
return nil unless tag
|
20
35
|
tag.resource
|
21
36
|
end
|
22
37
|
|
38
|
+
def template_or_any_group
|
39
|
+
template_group || any_group
|
40
|
+
end
|
41
|
+
|
23
42
|
def exists?
|
24
|
-
!
|
43
|
+
!any_group.nil?
|
25
44
|
end
|
26
45
|
|
27
46
|
def groups
|
28
47
|
FleetGroupCollection.new(self)
|
29
48
|
end
|
30
|
-
|
49
|
+
|
31
50
|
# Suspends all scaling processes in all Auto Scaling groups in the
|
32
51
|
# fleet.
|
33
52
|
def suspend_all_processes
|
@@ -56,7 +75,7 @@ module AWS
|
|
56
75
|
# existing launch configuration on the template scaling group.
|
57
76
|
#
|
58
77
|
def update_launch_configuration name, options = {}
|
59
|
-
old_lc =
|
78
|
+
old_lc = template_or_any_group.launch_configuration
|
60
79
|
image_id = options[:image_id] || old_lc.image_id
|
61
80
|
instance_type = options[:instance_type] || old_lc.instance_type
|
62
81
|
|
@@ -34,17 +34,6 @@ module AWS
|
|
34
34
|
def [] name
|
35
35
|
Fleet.new(name, :config => config)
|
36
36
|
end
|
37
|
-
|
38
|
-
protected
|
39
|
-
|
40
|
-
def _each_item options
|
41
|
-
TagCollection.new(:config => config).filter(:value, "template").each do |tag|
|
42
|
-
if tag[:key] =~ /^asgfleet:/
|
43
|
-
name = tag[:key].split(':', 2)[1]
|
44
|
-
yield Fleet.new(name, :config => config)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
37
|
end
|
49
38
|
end
|
50
39
|
end
|
@@ -18,141 +18,6 @@ module AWS
|
|
18
18
|
def << group
|
19
19
|
group.set_fleet @fleet.name
|
20
20
|
end
|
21
|
-
|
22
|
-
# Create a group within a Fleet.
|
23
|
-
#
|
24
|
-
# To create a group you supply a name, and any desired Auto
|
25
|
-
# Scaling group options. Any options not specified will be pulled
|
26
|
-
# from the template group for the fleet. Scaling policies and
|
27
|
-
# alarms will also be created for the new Group, based on those
|
28
|
-
# associated with the template.
|
29
|
-
#
|
30
|
-
# @param [String] name The name of the new group to create in the
|
31
|
-
# fleet. Must be unique in your account.
|
32
|
-
#
|
33
|
-
# @param [Hash] options
|
34
|
-
#
|
35
|
-
# @option (see GroupOptions#group_options)
|
36
|
-
#
|
37
|
-
# @return [Group]
|
38
|
-
def create name, options = {}
|
39
|
-
## Clone the group
|
40
|
-
template_group = @fleet.template_group
|
41
|
-
|
42
|
-
options = Fleet.options_from(template_group,
|
43
|
-
:load_balancers, :min_size, :max_size, :launch_configuration,
|
44
|
-
:availability_zones, :default_cooldown, :desired_capacity,
|
45
|
-
:health_check_grace_period, :health_check_type, :placement_group,
|
46
|
-
:termination_policies, :subnets).merge(options)
|
47
|
-
|
48
|
-
# merge together tags from options and the template
|
49
|
-
new_tags = template_group.tags.to_a.map do |t|
|
50
|
-
{
|
51
|
-
:key => t[:key],
|
52
|
-
:value => t[:value],
|
53
|
-
:propagate_at_launch => t[:propagate_at_launch]
|
54
|
-
}
|
55
|
-
end
|
56
|
-
if options[:tags]
|
57
|
-
options[:tags].each do |tag|
|
58
|
-
existing_tag = new_tags.find {|t| t[:key] == tag[:key] }
|
59
|
-
if existing_tag
|
60
|
-
existing_tag.merge! tag
|
61
|
-
else
|
62
|
-
new_tags << tag
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
# change the fleet tag value from "template" to "member"
|
67
|
-
fleet_tag = new_tags.find {|t| t[:key] == "asgfleet:#{@fleet.name}" }
|
68
|
-
fleet_tag[:value] = "member"
|
69
|
-
options[:tags] = new_tags
|
70
|
-
|
71
|
-
group = GroupCollection.new(:config => config).create name, options
|
72
|
-
|
73
|
-
# Match metric collection with the template
|
74
|
-
# (If this call ever supports specifying a granularity of other than
|
75
|
-
# '1Minute', this will need to change.)
|
76
|
-
group.enable_metrics_collection(template_group.enabled_metrics.keys)
|
77
|
-
|
78
|
-
# Copy notification configurations
|
79
|
-
template_group.notification_configurations.each do |template_nc|
|
80
|
-
group.notification_configurations.create(
|
81
|
-
:topic => template_nc.topic_arn,
|
82
|
-
:types => template_nc.notification_types,
|
83
|
-
)
|
84
|
-
end
|
85
|
-
|
86
|
-
## Clone the scaling policies and alarms from the group
|
87
|
-
cloudwatch = AWS::CloudWatch.new(:config => config)
|
88
|
-
template_group.scaling_policies.each do |template_policy|
|
89
|
-
policy_options = Fleet.options_from(template_policy,
|
90
|
-
:adjustment_type, :scaling_adjustment, :cooldown, :min_adjustment_step)
|
91
|
-
|
92
|
-
policy = group.scaling_policies.create template_policy.name, policy_options
|
93
|
-
|
94
|
-
template_policy.alarms.keys.each do |template_alarm_name|
|
95
|
-
template_alarm = cloudwatch.alarms[template_alarm_name]
|
96
|
-
|
97
|
-
# try to generate a unique alarm name first by replacing the name
|
98
|
-
# of the template group with the new group. if that doesn't work, then
|
99
|
-
# just append the new group's name
|
100
|
-
alarm_name = template_alarm.name.gsub(template_group.name, group.name)
|
101
|
-
if alarm_name == template_group.name
|
102
|
-
alarm_name = "#{alarm_name}-#{group.name}"
|
103
|
-
end
|
104
|
-
|
105
|
-
alarm_options = Fleet.options_from(template_alarm,
|
106
|
-
:namespace, :metric_name, :comparison_operator, :evaluation_periods,
|
107
|
-
:period, :statistic, :threshold, :actions_enabled, :alarm_description,
|
108
|
-
:unit)
|
109
|
-
|
110
|
-
# For dimensions, copy them all except for the one
|
111
|
-
# referencing the ASG - replace that with the right group.
|
112
|
-
alarm_options[:dimensions] = template_alarm.dimensions.map do |dimension|
|
113
|
-
if dimension[:name] == "AutoScalingGroupName"
|
114
|
-
{ :name => "AutoScalingGroupName", :value => group.name }
|
115
|
-
else
|
116
|
-
dimension
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# For actions, we want to go through them all, replacing any
|
121
|
-
# ARNs referencing the template_policy with ones pointing to
|
122
|
-
# our new policy. For ARNs we don't recognize, we just copy
|
123
|
-
# them, assuming the user wants those ARNs to continue to
|
124
|
-
# fire.
|
125
|
-
[ :insufficient_data_actions, :ok_actions, :alarm_actions ].each do |key|
|
126
|
-
new_actions = template_alarm.send(key).map do |arn|
|
127
|
-
if arn == template_policy.arn
|
128
|
-
policy.arn
|
129
|
-
else
|
130
|
-
arn
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
unless new_actions.empty?
|
135
|
-
alarm_options[key] = new_actions
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
alarm = cloudwatch.alarms.create alarm_name, alarm_options
|
140
|
-
if !template_alarm.enabled?
|
141
|
-
alarm.disable
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
group
|
147
|
-
end
|
148
|
-
|
149
|
-
protected
|
150
|
-
|
151
|
-
def _each_item options
|
152
|
-
TagCollection.new(:config => config).filter(:key, "asgfleet:#{@fleet.name}").each do |tag|
|
153
|
-
yield tag.resource
|
154
|
-
end
|
155
|
-
end
|
156
21
|
end
|
157
22
|
end
|
158
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-asg-fleet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|