aws-asg-fleet 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/asg-fleet.gemspec +3 -3
- data/lib/aws-sdk-autoscaling/fleet.rb +144 -0
- data/lib/aws-sdk-autoscaling/fleet_collection.rb +50 -0
- data/lib/aws-sdk-autoscaling/fleet_group_collection.rb +25 -0
- data/lib/aws-sdk-autoscaling/fleets.rb +48 -0
- metadata +23 -33
- data/lib/aws/auto_scaling/fleet.rb +0 -122
- data/lib/aws/auto_scaling/fleet_collection.rb +0 -56
- data/lib/aws/auto_scaling/fleet_group_collection.rb +0 -31
- data/lib/aws/auto_scaling/fleets.rb +0 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff793ee569c79401db2eaae824a888e0383a7d3705f02d423e6288945fd817a7
|
4
|
+
data.tar.gz: f68bd89d722264acf81f10f8025e2ee843b22c0b5c42629e0eb73251f0bc7fc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 179dee8303a123490a611a48272f01c67397453db5fe8472d79fc2c9ccd429158cacf5c02104f9dd26617117f325a75aebbeefad77a5e752c622edd62f4e08cc
|
7
|
+
data.tar.gz: fd2d5749a01ff46d55013b79b8d850bf68d830a60d3be97033eb84f0e978fca219f1508e4b5c257e45ee5141c6cde5fef2adb450ad631d07acb83d1bfb39e0b2
|
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.7"
|
9
9
|
spec.authors = ["Zach Wily"]
|
10
10
|
spec.email = ["zach@zwily.com"]
|
11
11
|
spec.description = %q{AWS Auto Scaling Fleets}
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "aws-sdk", "~> 1.
|
21
|
+
spec.add_dependency "aws-sdk-autoscaling", "~> 1.3"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~>
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module Aws::AutoScaling
|
2
|
+
class Fleet
|
3
|
+
|
4
|
+
def initialize name, options
|
5
|
+
@name = name
|
6
|
+
@client = options.delete(:client)
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
attr_reader :name
|
11
|
+
|
12
|
+
def tags(filters=[])
|
13
|
+
# mostly copied from Resource#tags
|
14
|
+
options = {:filters => [{:name => "key", :values => [tag_name]}] + filters}
|
15
|
+
batches = Enumerator.new do |y|
|
16
|
+
resp = @client.describe_tags(options)
|
17
|
+
resp.each_page do |page|
|
18
|
+
batch = []
|
19
|
+
page.data.tags.each do |t|
|
20
|
+
batch << Tag.new(
|
21
|
+
key: t.key,
|
22
|
+
resource_id: t.resource_id,
|
23
|
+
resource_type: t.resource_type,
|
24
|
+
data: t,
|
25
|
+
client: @client
|
26
|
+
)
|
27
|
+
end
|
28
|
+
y.yield(batch)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
Tag::Collection.new(batches)
|
32
|
+
end
|
33
|
+
|
34
|
+
def group_for_tag(tag)
|
35
|
+
return nil unless tag
|
36
|
+
case tag.resource_type
|
37
|
+
when 'auto-scaling-group'
|
38
|
+
AutoScalingGroup.new(name: tag.resource_id, client: @client)
|
39
|
+
else
|
40
|
+
msg = "unhandled resource type: #{tag.resource_type}" # shamelessly copied from old aws-sdk
|
41
|
+
raise ArgumentError, msg
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def tag_name
|
46
|
+
"asgfleet:#{name}"
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Group]
|
50
|
+
def template_group
|
51
|
+
tag = tags([{:name => 'value', :values => ["template"]}]).first
|
52
|
+
group_for_tag(tag)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Group]
|
56
|
+
def any_group
|
57
|
+
group_for_tag(tags.first)
|
58
|
+
end
|
59
|
+
|
60
|
+
def template_or_any_group
|
61
|
+
template_group || any_group
|
62
|
+
end
|
63
|
+
|
64
|
+
def exists?
|
65
|
+
!any_group.nil?
|
66
|
+
end
|
67
|
+
|
68
|
+
def groups
|
69
|
+
FleetGroupCollection.new(self)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Suspends all scaling processes in all Auto Scaling groups in the
|
73
|
+
# fleet.
|
74
|
+
def suspend_all_processes
|
75
|
+
groups.each do |group|
|
76
|
+
group.suspend_processes
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Resumes all scaling processes in all Auto Scaling groups in the
|
81
|
+
# fleet.
|
82
|
+
def resume_all_processes
|
83
|
+
groups.each do |group|
|
84
|
+
group.resume_processes
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Creates a new launch configuration and applies it to all the
|
89
|
+
# Auto Scaling groups in the fleet. Any options not specified will
|
90
|
+
# be pulled from the Launch Configuration currently attached to
|
91
|
+
# the template Auto Scaling group.
|
92
|
+
#
|
93
|
+
# @param [String] name The name of the new launch configuration
|
94
|
+
#
|
95
|
+
# @param [Hash] options Options for the new launch configuration.
|
96
|
+
# Any options not specified in this hash will be pulled from the
|
97
|
+
# existing launch configuration on the template scaling group.
|
98
|
+
#
|
99
|
+
def update_launch_configuration name, options = {}
|
100
|
+
old_lc = template_or_any_group.launch_configuration
|
101
|
+
options = Fleet.options_from(old_lc,
|
102
|
+
:image_id, :instance_type,
|
103
|
+
:block_device_mappings, :instance_monitoring, :kernel_id,
|
104
|
+
:key_name, :ramdisk_id, :security_groups, :user_data,
|
105
|
+
:iam_instance_profile, :spot_price).merge(options)
|
106
|
+
|
107
|
+
options[:launch_configuration_name] = name
|
108
|
+
@client.create_launch_configuration(options)
|
109
|
+
|
110
|
+
groups.each do |group|
|
111
|
+
next unless group.launch_template.nil?
|
112
|
+
next unless group.mixed_instances_policy.nil?
|
113
|
+
|
114
|
+
group.update(:launch_configuration_name => name)
|
115
|
+
end
|
116
|
+
|
117
|
+
LaunchConfiguration.new(name: name, client: @client)
|
118
|
+
end
|
119
|
+
|
120
|
+
# @private
|
121
|
+
# Collects non-nil, non-empty-array attributes from the supplied object
|
122
|
+
# into a Hash. Also converts any Array-like objects into real
|
123
|
+
# Arrays.
|
124
|
+
def self.options_from(obj, *attributes)
|
125
|
+
opts = {}
|
126
|
+
attributes.each do |key|
|
127
|
+
value = obj.send(key)
|
128
|
+
next if value.blank?
|
129
|
+
if value.is_a? Array
|
130
|
+
value = value.to_a
|
131
|
+
next if value.empty?
|
132
|
+
end
|
133
|
+
opts[key] ||= value
|
134
|
+
end
|
135
|
+
opts
|
136
|
+
end
|
137
|
+
|
138
|
+
protected
|
139
|
+
|
140
|
+
def resource_identifiers
|
141
|
+
[[:name, name]]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Aws::AutoScaling
|
2
|
+
class FleetCollection
|
3
|
+
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(opts)
|
7
|
+
@resource = opts.delete(:resource)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Create an ASG Fleet.
|
11
|
+
#
|
12
|
+
# To create a Fleet, you must supply an already-constructed
|
13
|
+
# Auto Scaling group to be used as the template for new groups
|
14
|
+
# added to the fleet.
|
15
|
+
#
|
16
|
+
# fleet = auto_scaling.fleets.create('fleet-name',
|
17
|
+
# auto_scaling.groups['my-asg-group'])
|
18
|
+
#
|
19
|
+
# @param [String] name The name of the new fleet to create.
|
20
|
+
# Must be unique in your account.
|
21
|
+
#
|
22
|
+
# @param [Group] group The group to be used as a template
|
23
|
+
# for future groups and fleet changes.
|
24
|
+
#
|
25
|
+
# @return [Fleet]
|
26
|
+
#
|
27
|
+
def create name, template_group
|
28
|
+
raise ArgumentError, "Fleet #{name} already exists" if @resource.fleet(name).exists?
|
29
|
+
raise ArgumentError, "Group is already in a fleet" if template_group.fleet
|
30
|
+
|
31
|
+
template_group.set_fleet(name, "template")
|
32
|
+
@resource.fleet(name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def each
|
36
|
+
yielded_fleets = []
|
37
|
+
|
38
|
+
@resource.tags.each do |tag|
|
39
|
+
if tag.key =~ /^asgfleet:/
|
40
|
+
name = tag.key.split(':', 2)[1]
|
41
|
+
|
42
|
+
next if yielded_fleets.include? name
|
43
|
+
yielded_fleets << name
|
44
|
+
|
45
|
+
yield @resource.fleet(name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Aws::AutoScaling
|
2
|
+
class FleetGroupCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize fleet
|
6
|
+
@fleet = fleet
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Fleet]
|
10
|
+
attr_reader :fleet
|
11
|
+
|
12
|
+
# Add an existing group to a Fleet.
|
13
|
+
#
|
14
|
+
# @param [Group] The group to add.
|
15
|
+
def << group
|
16
|
+
group.set_fleet @fleet.name
|
17
|
+
end
|
18
|
+
|
19
|
+
def each
|
20
|
+
@fleet.tags.each do |t|
|
21
|
+
yield @fleet.group_for_tag(t)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'aws-sdk-autoscaling'
|
2
|
+
|
3
|
+
module Aws::AutoScaling
|
4
|
+
autoload :Fleet, 'aws-sdk-autoscaling/fleet'
|
5
|
+
autoload :FleetCollection, 'aws-sdk-autoscaling/fleet_collection'
|
6
|
+
autoload :FleetGroupCollection, 'aws-sdk-autoscaling/fleet_group_collection'
|
7
|
+
|
8
|
+
module ResourceFleetsExtension
|
9
|
+
# @return [FleetCollection]
|
10
|
+
def fleet(name)
|
11
|
+
Fleet.new(name, client: @client)
|
12
|
+
end
|
13
|
+
|
14
|
+
def fleets
|
15
|
+
FleetCollection.new(resource: self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
Resource.include(ResourceFleetsExtension)
|
19
|
+
|
20
|
+
module AutoScalingGroupFletsExtension
|
21
|
+
def fleet
|
22
|
+
fleet_tag = tags.find {|t| t.key =~ /^asgfleet:/ }
|
23
|
+
return nil unless fleet_tag
|
24
|
+
|
25
|
+
fleet_name = fleet_tag.key.split(':', 2)[1]
|
26
|
+
Fleet.new(fleet_name, client: @client)
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_fleet fleet, role = "member"
|
30
|
+
if fleet && self.fleet
|
31
|
+
raise ArgumentError, "Group already belongs to a fleet"
|
32
|
+
end
|
33
|
+
|
34
|
+
if fleet.nil?
|
35
|
+
tags.find {|t| t.key =~ /^asgfleet:/ }.delete
|
36
|
+
else
|
37
|
+
@client.create_or_update_tags(:tags => [{
|
38
|
+
:resource_type => "auto-scaling-group",
|
39
|
+
:resource_id => name,
|
40
|
+
:key => "asgfleet:#{fleet.is_a?(Fleet) ? fleet.name : fleet}",
|
41
|
+
:value => role,
|
42
|
+
:propagate_at_launch => false
|
43
|
+
}])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
AutoScalingGroup.include(AutoScalingGroupFletsExtension)
|
48
|
+
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-asg-fleet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Zach Wily
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2019-08-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: aws-sdk
|
14
|
+
name: aws-sdk-autoscaling
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '1.
|
19
|
+
version: '1.3'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
26
|
+
version: '1.3'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '2.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '2.0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: AWS Auto Scaling Fleets
|
@@ -66,41 +59,38 @@ executables: []
|
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
61
|
files:
|
69
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
70
63
|
- Gemfile
|
71
64
|
- LICENSE.txt
|
72
65
|
- README.md
|
73
66
|
- Rakefile
|
74
67
|
- asg-fleet.gemspec
|
75
|
-
- lib/aws/
|
76
|
-
- lib/aws/
|
77
|
-
- lib/aws/
|
78
|
-
- lib/aws/
|
68
|
+
- lib/aws-sdk-autoscaling/fleet.rb
|
69
|
+
- lib/aws-sdk-autoscaling/fleet_collection.rb
|
70
|
+
- lib/aws-sdk-autoscaling/fleet_group_collection.rb
|
71
|
+
- lib/aws-sdk-autoscaling/fleets.rb
|
79
72
|
homepage: ''
|
80
73
|
licenses:
|
81
74
|
- MIT
|
75
|
+
metadata: {}
|
82
76
|
post_install_message:
|
83
77
|
rdoc_options: []
|
84
78
|
require_paths:
|
85
79
|
- lib
|
86
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
81
|
requirements:
|
89
|
-
- -
|
82
|
+
- - ">="
|
90
83
|
- !ruby/object:Gem::Version
|
91
84
|
version: '0'
|
92
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
86
|
requirements:
|
95
|
-
- -
|
87
|
+
- - ">="
|
96
88
|
- !ruby/object:Gem::Version
|
97
89
|
version: '0'
|
98
90
|
requirements: []
|
99
|
-
|
100
|
-
rubygems_version: 1.8.23
|
91
|
+
rubygems_version: 3.0.3
|
101
92
|
signing_key:
|
102
|
-
specification_version:
|
93
|
+
specification_version: 4
|
103
94
|
summary: Provides a mechanism to group together Auto Scaling groups and perform actions
|
104
95
|
on them in bulk.
|
105
96
|
test_files: []
|
106
|
-
has_rdoc:
|
@@ -1,122 +0,0 @@
|
|
1
|
-
module AWS
|
2
|
-
class AutoScaling
|
3
|
-
class Fleet < Core::Resource
|
4
|
-
|
5
|
-
def initialize name, options = {}
|
6
|
-
@name = name
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
# @return [String]
|
11
|
-
attr_reader :name
|
12
|
-
|
13
|
-
def tag_name
|
14
|
-
"asgfleet:#{name}"
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [Group]
|
18
|
-
def template_group
|
19
|
-
tag = TagCollection.new(:config => config)
|
20
|
-
.filter(:key, tag_name)
|
21
|
-
.filter(:value, "template")
|
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
|
-
|
34
|
-
return nil unless tag
|
35
|
-
tag.resource
|
36
|
-
end
|
37
|
-
|
38
|
-
def template_or_any_group
|
39
|
-
template_group || any_group
|
40
|
-
end
|
41
|
-
|
42
|
-
def exists?
|
43
|
-
!any_group.nil?
|
44
|
-
end
|
45
|
-
|
46
|
-
def groups
|
47
|
-
FleetGroupCollection.new(self)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Suspends all scaling processes in all Auto Scaling groups in the
|
51
|
-
# fleet.
|
52
|
-
def suspend_all_processes
|
53
|
-
groups.each do |group|
|
54
|
-
group.suspend_all_processes
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Resumes all scaling processes in all Auto Scaling groups in the
|
59
|
-
# fleet.
|
60
|
-
def resume_all_processes
|
61
|
-
groups.each do |group|
|
62
|
-
group.resume_all_processes
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Creates a new launch configuration and applies it to all the
|
67
|
-
# Auto Scaling groups in the fleet. Any options not specified will
|
68
|
-
# be pulled from the Launch Configuration currently attached to
|
69
|
-
# the template Auto Scaling group.
|
70
|
-
#
|
71
|
-
# @param [String] name The name of the new launch configuration
|
72
|
-
#
|
73
|
-
# @param [Hash] options Options for the new launch configuration.
|
74
|
-
# Any options not specified in this hash will be pulled from the
|
75
|
-
# existing launch configuration on the template scaling group.
|
76
|
-
#
|
77
|
-
def update_launch_configuration name, options = {}
|
78
|
-
old_lc = template_or_any_group.launch_configuration
|
79
|
-
image_id = options[:image_id] || old_lc.image_id
|
80
|
-
instance_type = options[:instance_type] || old_lc.instance_type
|
81
|
-
|
82
|
-
options = Fleet.options_from(old_lc,
|
83
|
-
:block_device_mappings, :detailed_instance_monitoring, :kernel_id,
|
84
|
-
:key_pair, :ramdisk_id, :security_groups, :user_data,
|
85
|
-
:iam_instance_profile, :spot_price).merge(options)
|
86
|
-
|
87
|
-
launch_configurations = LaunchConfigurationCollection.new(:config => config)
|
88
|
-
new_lc = launch_configurations.create(name, image_id, instance_type, options)
|
89
|
-
|
90
|
-
groups.each do |group|
|
91
|
-
group.update(:launch_configuration => new_lc)
|
92
|
-
end
|
93
|
-
|
94
|
-
new_lc
|
95
|
-
end
|
96
|
-
|
97
|
-
# @private
|
98
|
-
# Collects non-nil, non-empty-array attributes from the supplied object
|
99
|
-
# into a Hash. Also converts any Array-like objects into real
|
100
|
-
# Arrays.
|
101
|
-
def self.options_from(obj, *attributes)
|
102
|
-
opts = {}
|
103
|
-
attributes.each do |key|
|
104
|
-
value = obj.send(key)
|
105
|
-
next if value.nil?
|
106
|
-
if value.is_a? Array
|
107
|
-
value = value.to_a
|
108
|
-
next if value.empty?
|
109
|
-
end
|
110
|
-
opts[key] ||= value
|
111
|
-
end
|
112
|
-
opts
|
113
|
-
end
|
114
|
-
|
115
|
-
protected
|
116
|
-
|
117
|
-
def resource_identifiers
|
118
|
-
[[:name, name]]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module AWS
|
2
|
-
class AutoScaling
|
3
|
-
class FleetCollection
|
4
|
-
|
5
|
-
include Core::Collection::Simple
|
6
|
-
|
7
|
-
# Create an ASG Fleet.
|
8
|
-
#
|
9
|
-
# To create a Fleet, you must supply an already-constructed
|
10
|
-
# Auto Scaling group to be used as the template for new groups
|
11
|
-
# added to the fleet.
|
12
|
-
#
|
13
|
-
# fleet = auto_scaling.fleets.create('fleet-name',
|
14
|
-
# auto_scaling.groups['my-asg-group'])
|
15
|
-
#
|
16
|
-
# @param [String] name The name of the new fleet to create.
|
17
|
-
# Must be unique in your account.
|
18
|
-
#
|
19
|
-
# @param [Group] group The group to be used as a template
|
20
|
-
# for future groups and fleet changes.
|
21
|
-
#
|
22
|
-
# @return [Fleet]
|
23
|
-
#
|
24
|
-
def create name, template_group
|
25
|
-
raise ArgumentError, "Fleet #{name} already exists" if self[name].exists?
|
26
|
-
raise ArgumentError, "Group is already in a fleet" if template_group.fleet
|
27
|
-
|
28
|
-
template_group.set_fleet(name, "template")
|
29
|
-
self[name]
|
30
|
-
end
|
31
|
-
|
32
|
-
# @param [String] name The name of the ASG fleet.
|
33
|
-
# @return [Fleet]
|
34
|
-
def [] name
|
35
|
-
Fleet.new(name, :config => config)
|
36
|
-
end
|
37
|
-
|
38
|
-
protected
|
39
|
-
|
40
|
-
def _each_item options
|
41
|
-
yielded_fleets = []
|
42
|
-
|
43
|
-
TagCollection.new(:config => config).each do |tag|
|
44
|
-
if tag[:key] =~ /^asgfleet:/
|
45
|
-
name = tag[:key].split(':', 2)[1]
|
46
|
-
|
47
|
-
next if yielded_fleets.include? name
|
48
|
-
yielded_fleets << name
|
49
|
-
|
50
|
-
yield Fleet.new(name, :config => config)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module AWS
|
2
|
-
class AutoScaling
|
3
|
-
class FleetGroupCollection
|
4
|
-
|
5
|
-
include Core::Collection::Simple
|
6
|
-
|
7
|
-
def initialize fleet, options = {}
|
8
|
-
@fleet = fleet
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
12
|
-
# @return [Fleet]
|
13
|
-
attr_reader :fleet
|
14
|
-
|
15
|
-
# Add an existing group to a Fleet.
|
16
|
-
#
|
17
|
-
# @param [Group] The group to add.
|
18
|
-
def << group
|
19
|
-
group.set_fleet @fleet.name
|
20
|
-
end
|
21
|
-
|
22
|
-
protected
|
23
|
-
|
24
|
-
def _each_item options
|
25
|
-
TagCollection.new(:config => config).filter(:key, "asgfleet:#{@fleet.name}").each do |tag|
|
26
|
-
yield tag.resource
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'aws/auto_scaling'
|
2
|
-
require 'aws/version'
|
3
|
-
|
4
|
-
module AWS
|
5
|
-
class AutoScaling
|
6
|
-
|
7
|
-
autoload :Fleet, 'aws/auto_scaling/fleet'
|
8
|
-
autoload :FleetCollection, 'aws/auto_scaling/fleet_collection'
|
9
|
-
autoload :FleetGroupCollection, 'aws/auto_scaling/fleet_group_collection'
|
10
|
-
|
11
|
-
# @return [FleetCollection]
|
12
|
-
def fleets
|
13
|
-
FleetCollection.new(:config => config)
|
14
|
-
end
|
15
|
-
|
16
|
-
class Group
|
17
|
-
def fleet
|
18
|
-
fleet_tag = tags.find {|t| t[:key] =~ /^asgfleet:/ }
|
19
|
-
return nil unless fleet_tag
|
20
|
-
|
21
|
-
fleet_name = fleet_tag[:key].split(':', 2)[1]
|
22
|
-
Fleet.new(fleet_name, :config => config)
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_fleet fleet, role = "member"
|
26
|
-
if fleet && self.fleet
|
27
|
-
raise ArgumentError, "Group already belongs to a fleet"
|
28
|
-
end
|
29
|
-
|
30
|
-
if fleet.nil?
|
31
|
-
tags.find {|t| t[:key] =~ /^asgfleet:/ }.delete
|
32
|
-
else
|
33
|
-
self.update(:tags => [{
|
34
|
-
:key => "asgfleet:#{fleet.is_a?(Fleet) ? fleet.name : fleet}",
|
35
|
-
:value => role,
|
36
|
-
:propagate_at_launch => false
|
37
|
-
}])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|