awsome 0.0.59 → 0.0.60
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.
- data/lib/awsome.rb +11 -6
- data/lib/awsome/ec2.rb +47 -8
- data/lib/awsome/ec2/instance.rb +5 -3
- data/lib/awsome/elb.rb +18 -3
- data/lib/awsome/ssh.rb +2 -2
- metadata +1 -1
data/lib/awsome.rb
CHANGED
@@ -5,10 +5,11 @@ module Awsome
|
|
5
5
|
|
6
6
|
def self.execute(command, options={})
|
7
7
|
command = command.join(' ') if command.is_a?(Array)
|
8
|
-
|
8
|
+
description = options[:task] ? "[#{options[:task]}] #{command}" : command
|
9
|
+
verbose = config.verbose && options[:verbose] != false
|
10
|
+
if verbose
|
9
11
|
puts
|
10
|
-
puts
|
11
|
-
puts '-' * [command.length, 100].min
|
12
|
+
puts description
|
12
13
|
end
|
13
14
|
if options[:system]
|
14
15
|
result = system(command)
|
@@ -18,10 +19,11 @@ module Awsome
|
|
18
19
|
result = map_table(result, options)
|
19
20
|
end
|
20
21
|
ensure
|
21
|
-
if
|
22
|
+
if verbose && options[:output] != false
|
23
|
+
puts '-' * description.length
|
22
24
|
case result
|
23
25
|
when String then puts result
|
24
|
-
else ap result
|
26
|
+
else ap result # print a table perhaps..
|
25
27
|
end
|
26
28
|
end
|
27
29
|
if config.stacks
|
@@ -48,7 +50,10 @@ module Awsome
|
|
48
50
|
retries = opts[:retries] || 5
|
49
51
|
interval = opts[:interval] || 5
|
50
52
|
while !yield && retries > 0
|
51
|
-
|
53
|
+
if config.verbose
|
54
|
+
task = opts[:task] || 'block returned false'
|
55
|
+
puts "[#{retries} more retries] #{task}"
|
56
|
+
end
|
52
57
|
sleep interval
|
53
58
|
retries -= 1
|
54
59
|
end
|
data/lib/awsome/ec2.rb
CHANGED
@@ -44,13 +44,23 @@ module Awsome
|
|
44
44
|
'instance-type'.to_sym => properties['instance_type'],
|
45
45
|
'availability-zone'.to_sym => properties['availability_zone']
|
46
46
|
)
|
47
|
-
Awsome
|
47
|
+
result = Awsome.execute(
|
48
|
+
cmd,
|
49
|
+
columns: @@run_instance_fields,
|
50
|
+
filter: /^INSTANCE/,
|
51
|
+
task: 'creating instance'
|
52
|
+
)
|
53
|
+
Awsome::Ec2::Instance.new(result.first)
|
48
54
|
end
|
49
55
|
|
50
56
|
def self.create_tags(resource_id, tags)
|
51
57
|
tags = tags.collect { |k, v| v ? "--tag #{k}=#{v}" : "--tag #{k}" }
|
52
58
|
cmd = command('ec2-create-tags', resource_id, *tags)
|
53
|
-
Awsome.execute(
|
59
|
+
Awsome.execute(
|
60
|
+
cmd,
|
61
|
+
task: "tagging #{resource_id}",
|
62
|
+
output: false
|
63
|
+
)
|
54
64
|
end
|
55
65
|
|
56
66
|
@@describe_instance_fields = %w(
|
@@ -76,7 +86,13 @@ module Awsome
|
|
76
86
|
cmd = [Awsome::Ec2.command('ec2-describe-instances')]
|
77
87
|
cmd += filters.collect { |k,v| "--filter \"#{k}=#{v}\"" }
|
78
88
|
preprocess = Proc.new { |text| text.gsub("\nINSTANCE", " INSTANCE") }
|
79
|
-
properties = Awsome.execute(
|
89
|
+
properties = Awsome.execute(
|
90
|
+
cmd,
|
91
|
+
columns: @@describe_instance_fields,
|
92
|
+
filter: /^RESERVATION/,
|
93
|
+
preprocess: preprocess,
|
94
|
+
verbose: false
|
95
|
+
)
|
80
96
|
properties.collect { |p| Awsome::Ec2::Instance.new(p) }
|
81
97
|
end
|
82
98
|
|
@@ -94,7 +110,12 @@ module Awsome
|
|
94
110
|
def self.describe_volumes(*volume_ids)
|
95
111
|
return [] if volume_ids.empty?
|
96
112
|
cmd = [Awsome::Ec2.command('ec2-describe-volumes')] + volume_ids
|
97
|
-
Awsome.execute(
|
113
|
+
Awsome.execute(
|
114
|
+
cmd,
|
115
|
+
columns: @@describe_volumes_fields,
|
116
|
+
filter: /^VOLUME/,
|
117
|
+
verbose: false
|
118
|
+
)
|
98
119
|
end
|
99
120
|
|
100
121
|
def self.volume_available?(volume_id)
|
@@ -127,7 +148,11 @@ module Awsome
|
|
127
148
|
instance.ssh "sudo umount #{dir}"
|
128
149
|
|
129
150
|
cmd = Awsome::Ec2.command('ec2-detach-volume', volume_id)
|
130
|
-
Awsome.execute(
|
151
|
+
Awsome.execute(
|
152
|
+
cmd,
|
153
|
+
task: 'detaching volume',
|
154
|
+
output: false
|
155
|
+
)
|
131
156
|
end
|
132
157
|
end
|
133
158
|
|
@@ -139,18 +164,32 @@ module Awsome
|
|
139
164
|
|
140
165
|
def self.associate_address(instance_id, ip_address)
|
141
166
|
cmd = Awsome::Ec2.command('ec2-associate-address', ip_address, instance: instance_id)
|
142
|
-
Awsome.execute(
|
167
|
+
Awsome.execute(
|
168
|
+
cmd,
|
169
|
+
columns: @@associate_address_columns,
|
170
|
+
filter: /^ADDRESS/,
|
171
|
+
task: 'associating ip',
|
172
|
+
output: false
|
173
|
+
)
|
143
174
|
end
|
144
175
|
|
145
176
|
def self.attach_volume(volume_id, instance_id, device)
|
146
177
|
cmd = Awsome::Ec2.command('ec2-attach-volume', volume_id, instance: instance_id, device: device)
|
147
|
-
Awsome.execute(
|
178
|
+
Awsome.execute(
|
179
|
+
cmd,
|
180
|
+
task: 'attaching volume',
|
181
|
+
output: false
|
182
|
+
)
|
148
183
|
end
|
149
184
|
|
150
185
|
def self.terminate_instances(*instance_ids)
|
151
186
|
return if instance_ids.empty?
|
152
187
|
cmd = Awsome::Ec2.command("ec2-terminate-instances #{instance_ids.join(' ')}")
|
153
|
-
Awsome.execute(
|
188
|
+
Awsome.execute(
|
189
|
+
cmd,
|
190
|
+
task: 'terminating instances',
|
191
|
+
output: false
|
192
|
+
)
|
154
193
|
end
|
155
194
|
end
|
156
195
|
end
|
data/lib/awsome/ec2/instance.rb
CHANGED
@@ -23,14 +23,14 @@ module Awsome
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def wait_until_running!
|
26
|
-
Awsome.wait_until(interval: 20) do
|
26
|
+
Awsome.wait_until(interval: 20, task: "waiting for instance #{id} 'running' status") do
|
27
27
|
reload!
|
28
28
|
@properties['state'] =~ /^running/
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def wait_for_ssh!
|
33
|
-
Awsome.wait_until(interval: 20) { has_ssh? }
|
33
|
+
Awsome.wait_until(interval: 20, task: "waiting for instance #{id} ssh access") { has_ssh? }
|
34
34
|
end
|
35
35
|
|
36
36
|
def ssh(*args)
|
@@ -58,7 +58,9 @@ module Awsome
|
|
58
58
|
def reattach_volumes(*volumes)
|
59
59
|
volumes.each do |info|
|
60
60
|
Awsome::Ec2.detach_volume(info['id'], info['dir'], info['preumount'])
|
61
|
-
Awsome.wait_until(interval: 10
|
61
|
+
Awsome.wait_until(interval: 10, task: "waiting for volume #{info['id']} to become available") do
|
62
|
+
Awsome::Ec2.volume_available?(info['id'])
|
63
|
+
end
|
62
64
|
Awsome::Ec2.attach_volume(info['id'], @properties['instance_id'], info['device'])
|
63
65
|
end
|
64
66
|
end
|
data/lib/awsome/elb.rb
CHANGED
@@ -47,18 +47,33 @@ module Awsome
|
|
47
47
|
|
48
48
|
def self.describe_lbs(*load_balancer_names)
|
49
49
|
cmd = Awsome::Elb.command("elb-describe-lbs #{load_balancer_names.join(' ')}")
|
50
|
-
properties = Awsome.execute(
|
50
|
+
properties = Awsome.execute(
|
51
|
+
cmd,
|
52
|
+
columns: @@describe_lbs_columns,
|
53
|
+
delimiter: @@delimiter,
|
54
|
+
verbose: false
|
55
|
+
)
|
51
56
|
properties.collect { |p| Awsome::Elb::LoadBalancer.new(p) }
|
52
57
|
end
|
53
58
|
|
54
59
|
def self.deregister_instance_from_lb(load_balancer_name, instance_id)
|
55
60
|
cmd = Awsome::Elb.command('elb-deregister-instances-from-lb', load_balancer_name, instances: instance_id)
|
56
|
-
Awsome.execute(
|
61
|
+
Awsome.execute(
|
62
|
+
cmd,
|
63
|
+
delimiter: @@delimiter,
|
64
|
+
task: 'deregistering from elb',
|
65
|
+
output: false
|
66
|
+
)
|
57
67
|
end
|
58
68
|
|
59
69
|
def self.register_instance_with_lb(load_balancer_name, instance_id)
|
60
70
|
cmd = Awsome::Elb.command('elb-register-instances-with-lb', load_balancer_name, instances: instance_id)
|
61
|
-
Awsome.execute(
|
71
|
+
Awsome.execute(
|
72
|
+
cmd,
|
73
|
+
delimiter: @@delimiter,
|
74
|
+
task: 'registering with elb',
|
75
|
+
output: false
|
76
|
+
)
|
62
77
|
end
|
63
78
|
end
|
64
79
|
end
|
data/lib/awsome/ssh.rb
CHANGED
@@ -17,11 +17,11 @@ module Awsome
|
|
17
17
|
else
|
18
18
|
from = "#{ENV['SSH_USER']}@#{from}"
|
19
19
|
end
|
20
|
-
Awsome.execute("scp -i #{ENV['SSH_KEY']} #{from} #{to}", system: true)
|
20
|
+
Awsome.execute("scp -i #{ENV['SSH_KEY']} #{from} #{to}", system: true, verbose: false)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.has_ssh?(host)
|
24
|
-
Awsome.execute("nc -zw 2 #{host} 22 < /dev/null", system: true)
|
24
|
+
Awsome.execute("nc -zw 2 #{host} 22 < /dev/null", system: true, verbose: false)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|