awsome 0.0.46 → 0.0.59
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/awsome +11 -11
- data/lib/awsome.rb +1 -1
- data/lib/awsome/debian.rb +12 -3
- data/lib/awsome/ec2/instance.rb +29 -8
- data/lib/awsome/executor.rb +4 -1
- data/lib/awsome/instance_requirement.rb +2 -2
- data/lib/awsome/matchmaker.rb +15 -19
- metadata +1 -1
data/bin/awsome
CHANGED
@@ -22,32 +22,32 @@ OptionParser.new do |opts|
|
|
22
22
|
end.parse!
|
23
23
|
|
24
24
|
def perform_task(task, &block)
|
25
|
-
puts
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
puts
|
26
|
+
puts task
|
27
|
+
puts '=' * task.length
|
28
|
+
yield task
|
29
29
|
end
|
30
30
|
|
31
31
|
requirements = nil
|
32
32
|
instances = nil
|
33
33
|
matches = nil
|
34
34
|
|
35
|
-
perform_task "Gathering Instance Requirements" do
|
35
|
+
perform_task "Step 1: Gathering Instance Requirements" do
|
36
36
|
requirements = Awsome::Requirements.from_yaml_file(requirements_file)
|
37
|
-
puts Awsome::Requirements.to_table(requirements.instances, '
|
37
|
+
puts Awsome::Requirements.to_table(requirements.instances, 'Instance Requirements')
|
38
38
|
end
|
39
39
|
|
40
|
-
perform_task "Analyzing Running Instances" do
|
40
|
+
perform_task "Step 2: Analyzing Running Instances" do
|
41
41
|
filters = {'instance-state-name' => 'running'}.merge(requirements.filters)
|
42
42
|
instances = Awsome::Ec2.describe_instances(filters)
|
43
43
|
puts Awsome::Ec2::Instance.to_table(instances, 'Running Instances')
|
44
44
|
end
|
45
45
|
|
46
|
-
perform_task "
|
46
|
+
perform_task "Step 3: Planning" do
|
47
47
|
matches = Awsome::Matchmaker.new(instances, requirements).matches
|
48
|
-
puts Awsome::Matchmaker.to_table(matches, '
|
48
|
+
puts Awsome::Matchmaker.to_table(matches, 'The Plan')
|
49
49
|
end
|
50
50
|
|
51
|
-
perform_task "
|
52
|
-
Awsome::Executor.new(matches).execute
|
51
|
+
perform_task "Step 4: Execution" do
|
52
|
+
Awsome::Executor.new(matches, requirements).execute
|
53
53
|
end
|
data/lib/awsome.rb
CHANGED
data/lib/awsome/debian.rb
CHANGED
@@ -16,7 +16,9 @@ module Awsome
|
|
16
16
|
|
17
17
|
Awsome::Ssh.ssh hostname, "sudo apt-get update"
|
18
18
|
|
19
|
-
packages.each
|
19
|
+
packages.each do |p|
|
20
|
+
Awsome::Ssh.ssh hostname, "sudo apt-get remove -y --force-yes #{p}"
|
21
|
+
end
|
20
22
|
|
21
23
|
Awsome::Ssh.ssh hostname, "echo #{remaining.to_a.join(',')} > ~/packages.csv"
|
22
24
|
end
|
@@ -25,11 +27,18 @@ module Awsome
|
|
25
27
|
installed = describe_debian_packages(hostname)
|
26
28
|
remaining = installed.to_set + packages.to_set
|
27
29
|
|
28
|
-
|
30
|
+
return if remaining.empty?
|
29
31
|
|
30
|
-
remaining.each
|
32
|
+
remaining.each do |p|
|
33
|
+
Awsome::Ssh.ssh hostname, "sudo apt-get update"
|
34
|
+
Awsome::Ssh.ssh hostname, "sudo apt-get install -y --force-yes #{p}"
|
35
|
+
end
|
31
36
|
|
32
37
|
Awsome::Ssh.ssh hostname, "echo #{remaining.to_a.join(',')} > ~/packages.csv"
|
33
38
|
end
|
39
|
+
|
40
|
+
def self.autoremove_debian_packages(hostname)
|
41
|
+
Awsome::Ssh.ssh hostname, "sudo apt-get autoremove -y --force-yes"
|
42
|
+
end
|
34
43
|
end
|
35
44
|
end
|
data/lib/awsome/ec2/instance.rb
CHANGED
@@ -10,14 +10,16 @@ module Awsome
|
|
10
10
|
@properties = property_hash.clone
|
11
11
|
end
|
12
12
|
|
13
|
-
def packages
|
14
|
-
|
13
|
+
def packages(options={})
|
14
|
+
return @cached_packages if @cached_packages && options[:cached_ok]
|
15
|
+
@cached_packages = Awsome::Debian.describe_debian_packages(@properties['public_dns_name']).to_set
|
15
16
|
end
|
16
17
|
|
17
|
-
def volumes
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def volumes(options={})
|
19
|
+
return @cached_volumes if @cached_volumes && options[:cached_ok]
|
20
|
+
@cached_volumes = Awsome::Ec2.describe_attachments(
|
21
|
+
'attachment.instance-id' => @properties['instance_id']
|
22
|
+
).collect{ |p| p['volume_id'] }.to_set
|
21
23
|
end
|
22
24
|
|
23
25
|
def wait_until_running!
|
@@ -38,9 +40,12 @@ module Awsome
|
|
38
40
|
def associate_cnames(*cnames)
|
39
41
|
cnames.each do |cname|
|
40
42
|
zone = cname['zone']
|
41
|
-
cname['
|
43
|
+
(cname['private'] || []).each do |name|
|
42
44
|
Awsome::R53.redefine_cname(zone, name, @properties['private_dns_name'])
|
43
45
|
end
|
46
|
+
(cname['public'] || []).each do |name|
|
47
|
+
Awsome::R53.redefine_cname(zone, name, @properties['public_dns_name'])
|
48
|
+
end
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
@@ -58,6 +63,12 @@ module Awsome
|
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
66
|
+
def detach_volumes(*volumes)
|
67
|
+
volumes.each do |info|
|
68
|
+
Awsome::Ec2.detach_volume(info['id'], info['dir'], info['preumount'])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
61
72
|
def deregister_from_elbs
|
62
73
|
elbs.each { |elb| elb.deregister(@properties['instance_id']) }
|
63
74
|
end
|
@@ -75,6 +86,10 @@ module Awsome
|
|
75
86
|
Awsome::Debian.install_debian_packages(@properties['public_dns_name'], *packages)
|
76
87
|
end
|
77
88
|
|
89
|
+
def autoremove_packages
|
90
|
+
Awsome::Debian.autoremove_debian_packages(@properties['public_dns_name'])
|
91
|
+
end
|
92
|
+
|
78
93
|
def terminate
|
79
94
|
Awsome::Ec2.terminate_instances(@properties['instance_id'])
|
80
95
|
end
|
@@ -89,6 +104,8 @@ module Awsome
|
|
89
104
|
# add instance rows
|
90
105
|
instances.each do |instance|
|
91
106
|
rows << [
|
107
|
+
instance.id,
|
108
|
+
instance.public_dns_name,
|
92
109
|
instance.packages.to_a.join("\n"),
|
93
110
|
instance.volumes.to_a.join("\n"),
|
94
111
|
instance.elbs.collect(&:name).join("\n"),
|
@@ -104,7 +121,7 @@ module Awsome
|
|
104
121
|
# remove last unnecessary separator
|
105
122
|
rows.pop if rows.any?
|
106
123
|
|
107
|
-
headings = %w(packages volumes elbs ami key type zone secgroup)
|
124
|
+
headings = %w(id dns packages volumes elbs ami key type zone secgroup)
|
108
125
|
Terminal::Table.new :headings => headings, :rows => rows, :title => title
|
109
126
|
end
|
110
127
|
|
@@ -116,6 +133,10 @@ module Awsome
|
|
116
133
|
@properties['instance_id']
|
117
134
|
end
|
118
135
|
|
136
|
+
def public_dns_name
|
137
|
+
@properties['public_dns_name']
|
138
|
+
end
|
139
|
+
|
119
140
|
def ami_id
|
120
141
|
@properties['ami_id']
|
121
142
|
end
|
data/lib/awsome/executor.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Awsome
|
2
2
|
class Executor
|
3
|
-
def initialize(matches)
|
3
|
+
def initialize(matches, requirements)
|
4
4
|
@matches = matches
|
5
|
+
@requirements = requirements
|
5
6
|
end
|
6
7
|
|
7
8
|
def execute
|
@@ -64,6 +65,7 @@ module Awsome
|
|
64
65
|
instance.deregister_from_elbs
|
65
66
|
instance.remove_packages(*requirement.packages_to_remove(instance))
|
66
67
|
instance.install_packages(*requirement.packages_to_install(instance))
|
68
|
+
instance.autoremove_packages
|
67
69
|
instance.associate_cnames(*requirement.cnames)
|
68
70
|
instance.associate_ips(*requirement.elastic_ips)
|
69
71
|
instance.register_with_elbs(*requirement.elbs)
|
@@ -73,6 +75,7 @@ module Awsome
|
|
73
75
|
def terminate
|
74
76
|
instances_to_terminate do |instance|
|
75
77
|
instance.deregister_from_elbs
|
78
|
+
instance.detach_volumes(*instance.volumes.collect{|id|@requirements.options.find_volume(id)})
|
76
79
|
instance.terminate
|
77
80
|
end
|
78
81
|
end
|
@@ -79,11 +79,11 @@ module Awsome
|
|
79
79
|
private
|
80
80
|
|
81
81
|
def packages_installed_on(instance)
|
82
|
-
instance ? instance.packages : Set[]
|
82
|
+
instance ? instance.packages(cached_ok: true) : Set[]
|
83
83
|
end
|
84
84
|
|
85
85
|
def volumes_attached_to(instance)
|
86
|
-
instance ? @options.filter_volume_ids(instance.volumes) : Set[]
|
86
|
+
instance ? @options.filter_volume_ids(instance.volumes(cached_ok: true)) : Set[]
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/lib/awsome/matchmaker.rb
CHANGED
@@ -72,13 +72,24 @@ module Awsome
|
|
72
72
|
best = nil
|
73
73
|
|
74
74
|
permute i_pool do |i_pool_perm|
|
75
|
-
best =
|
75
|
+
best = winner(best, build_match(i_pool_perm, r_pool))
|
76
76
|
end
|
77
77
|
|
78
78
|
best
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def winner(m1, m2)
|
82
|
+
return m1 if m2.nil?
|
83
|
+
return m2 if m1.nil?
|
84
|
+
raise 'cannot declare winner between 2 nil contestants' if m1.nil? && m2.nil?
|
85
|
+
return m1 if m1[:v_delta] < m2[:v_delta]
|
86
|
+
return m2 if m2[:v_delta] < m1[:v_delta]
|
87
|
+
return m1 if m1[:p_delta] < m2[:p_delta]
|
88
|
+
return m2 if m2[:p_delta] < m1[:p_delta]
|
89
|
+
return m1
|
90
|
+
end
|
91
|
+
|
92
|
+
def build_match(i_pool, r_pool)
|
82
93
|
v_delta = 0
|
83
94
|
p_delta = 0
|
84
95
|
|
@@ -90,27 +101,12 @@ module Awsome
|
|
90
101
|
end
|
91
102
|
end
|
92
103
|
|
93
|
-
|
104
|
+
return {
|
94
105
|
v_delta: v_delta,
|
95
106
|
p_delta: p_delta,
|
96
107
|
i_pool: i_pool,
|
97
108
|
r_pool: r_pool
|
98
|
-
}
|
99
|
-
end
|
100
|
-
|
101
|
-
def top_score(*scores)
|
102
|
-
scores.sort_by do |s1, s2|
|
103
|
-
case
|
104
|
-
when s1.nil? && s2.nil? then 0
|
105
|
-
when s2.nil? then -1
|
106
|
-
when s1.nil? then 1
|
107
|
-
when s1[:v_delta] < s2[:v_delta] then -1
|
108
|
-
when s1[:v_delta] > s2[:v_delta] then 1
|
109
|
-
when s1[:p_delta] < s2[:p_delta] then -1
|
110
|
-
when s1[:p_delta] > s2[:p_delta] then 1
|
111
|
-
else 0
|
112
|
-
end
|
113
|
-
end.first
|
109
|
+
}
|
114
110
|
end
|
115
111
|
|
116
112
|
def permute(array, permutation=[], &block)
|