cardmagic-sumo 0.3.1 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/sumo +2 -2
- data/lib/sumo.rb +66 -19
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/bin/sumo
CHANGED
@@ -15,7 +15,7 @@ class CLI < Thor
|
|
15
15
|
if role
|
16
16
|
task("Bootstrap chef") { sumo.bootstrap_chef(host) }
|
17
17
|
role.split(',').each do |role|
|
18
|
-
task("Setup #{role}") { sumo.setup_role(
|
18
|
+
task("Setup #{role}") { sumo.setup_role(id, role) }
|
19
19
|
end
|
20
20
|
|
21
21
|
resources = sumo.resources(host)
|
@@ -62,7 +62,7 @@ class CLI < Thor
|
|
62
62
|
def role(role, id=nil)
|
63
63
|
inst = sumo.find(id) || sumo.running.first || abort("No running instances")
|
64
64
|
task "Setup #{role}" do
|
65
|
-
sumo.setup_role(inst[:hostname], role)
|
65
|
+
sumo.setup_role(inst[:hostname], inst[:instance_id], role)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
data/lib/sumo.rb
CHANGED
@@ -15,7 +15,7 @@ class Sumo
|
|
15
15
|
|
16
16
|
result = ec2.run_instances(
|
17
17
|
:image_id => ami,
|
18
|
-
:instance_type => config['instance_size']
|
18
|
+
:instance_type => config['instance_size'],
|
19
19
|
:key_name => 'sumo',
|
20
20
|
:security_group => [ 'sumo' ],
|
21
21
|
:availability_zone => config['availability_zone']
|
@@ -75,6 +75,14 @@ class Sumo
|
|
75
75
|
)
|
76
76
|
result["volumeId"]
|
77
77
|
end
|
78
|
+
|
79
|
+
def format_volume(volume, instance, device, mountpoint)
|
80
|
+
commands = [
|
81
|
+
"if [ ! -d #{mountpoint} ]; then sudo mkdir #{mountpoint}; fi",
|
82
|
+
"if [ -b /dev/#{device}1 ]; then sudo mount /dev/#{device}1 #{mountpoint}; else echo ',,L' | sudo sfdisk /dev/#{device} && sudo mkfs.xfs /dev/#{device}1 && sudo mount /dev/#{device}1 #{mountpoint}; fi"
|
83
|
+
]
|
84
|
+
ssh(instance, commands)
|
85
|
+
end
|
78
86
|
|
79
87
|
def destroy_volume(volume)
|
80
88
|
ec2.delete_volume(:volume_id => volume)
|
@@ -91,7 +99,9 @@ class Sumo
|
|
91
99
|
instances << {
|
92
100
|
:instance_id => item.instanceId,
|
93
101
|
:status => item.instanceState.name,
|
94
|
-
:hostname => item.dnsName
|
102
|
+
:hostname => item.dnsName,
|
103
|
+
:local_dns => item.privateDnsName,
|
104
|
+
:private_ip => item.privateIpAddress
|
95
105
|
}
|
96
106
|
end
|
97
107
|
end
|
@@ -147,13 +157,30 @@ class Sumo
|
|
147
157
|
end
|
148
158
|
end
|
149
159
|
|
160
|
+
def wait_for_private_ip(instance_id)
|
161
|
+
raise ArgumentError unless instance_id and instance_id.match(/^i-/)
|
162
|
+
loop do
|
163
|
+
if inst = instance_info(instance_id)
|
164
|
+
if private_ip = inst[:private_ip]
|
165
|
+
return private_ip
|
166
|
+
end
|
167
|
+
end
|
168
|
+
sleep 1
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
150
172
|
def wait_for_ssh(hostname)
|
151
173
|
raise ArgumentError unless hostname
|
152
174
|
loop do
|
153
175
|
begin
|
154
176
|
Timeout::timeout(4) do
|
155
177
|
TCPSocket.new(hostname, 22)
|
156
|
-
|
178
|
+
IO.popen("ssh -i #{keypair_file} #{config['user']}@#{hostname} > #{config['logfile'] || "~/.sumo/ssh.log"} 2>&1", "w") do |pipe|
|
179
|
+
pipe.puts "ls"
|
180
|
+
end
|
181
|
+
if $?.success?
|
182
|
+
return
|
183
|
+
end
|
157
184
|
end
|
158
185
|
rescue SocketError, Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
159
186
|
end
|
@@ -162,36 +189,51 @@ class Sumo
|
|
162
189
|
|
163
190
|
def bootstrap_chef(hostname)
|
164
191
|
commands = [
|
165
|
-
'apt-get update',
|
166
|
-
'apt-get autoremove -y',
|
167
|
-
'apt-get install -y ruby ruby-dev rubygems git-core',
|
168
|
-
'
|
169
|
-
'gem install chef ohai --no-rdoc --no-ri',
|
170
|
-
config['cookbooks_url'] ? "git clone #{config['cookbooks_url']} chef-cookbooks" : "echo done"
|
192
|
+
'sudo apt-get update',
|
193
|
+
'sudo apt-get autoremove -y',
|
194
|
+
'if [ ! -f /usr/lib/ruby/1.8/net/https.rb ]; then sudo apt-get install -y xfsprogs xfsdump xfslibs-dev ruby ruby-dev rubygems libopenssl-ruby1.8 git-core; fi',
|
195
|
+
'if [ ! -d /etc/chef ]; then sudo mkdir /etc/chef; fi',
|
196
|
+
'if [ ! -d /var/lib/gems/1.8/gems/chef-* ]; then sudo gem install chef ohai --no-rdoc --no-ri; fi',
|
197
|
+
config['cookbooks_url'] ? "if [ -d chef-cookbooks ]; then cd chef-cookbooks; git pull; else git clone #{config['cookbooks_url']} chef-cookbooks; fi" : "echo done"
|
171
198
|
]
|
172
199
|
ssh(hostname, commands)
|
173
|
-
if config['cookbooks_dir']
|
200
|
+
if !config['cookbooks_url'] && config['cookbooks_dir']
|
174
201
|
scp(hostname, config['cookbooks_dir'], "chef-cookbooks")
|
175
202
|
end
|
203
|
+
if config['chef-validation']
|
204
|
+
scp(hostname, config['chef-validation'], "validation.pem")
|
205
|
+
ssh(hostname, ["sudo mv validation.pem /etc/chef/"])
|
206
|
+
end
|
176
207
|
end
|
177
208
|
|
178
|
-
def setup_role(hostname, role)
|
209
|
+
def setup_role(hostname, instance_id, role)
|
179
210
|
commands = [
|
180
|
-
|
181
|
-
"/var/lib/gems/1.8/bin/chef-solo -c config.
|
211
|
+
"if [ ! -f /etc/chef/client.pem ]; then cd chef-cookbooks",
|
212
|
+
"sudo /var/lib/gems/1.8/bin/chef-solo -c config/solo.rb -j roles/bootstrap.json -r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz",
|
213
|
+
"if [ -f config/client.rb ]; then sudo cp config/client.rb /etc/chef/client.rb; fi",
|
214
|
+
"sudo /var/lib/gems/1.8/bin/chef-client",
|
215
|
+
"sudo rm /etc/chef/validation.pem; fi"
|
182
216
|
]
|
183
217
|
ssh(hostname, commands)
|
218
|
+
`knife node run_list add #{instance_id} "role[#{role}]"`
|
219
|
+
ssh(hostname, ["sudo /var/lib/gems/1.8/bin/chef-client"])
|
184
220
|
end
|
185
221
|
|
186
222
|
def ssh(hostname, cmds)
|
187
223
|
unless IO.read(File.expand_path("~/.ssh/known_hosts")).include?(hostname)
|
188
224
|
`ssh-keyscan -t rsa #{hostname} >> $HOME/.ssh/known_hosts`
|
225
|
+
if config['deploy_key']
|
226
|
+
scp(hostname, config['deploy_key'], ".ssh/id_rsa")
|
227
|
+
end
|
228
|
+
if config['known_hosts']
|
229
|
+
scp(hostname, config['known_hosts'], ".ssh/known_hosts")
|
230
|
+
end
|
189
231
|
end
|
190
|
-
IO.popen("ssh -i #{keypair_file} #{config['user']}@#{hostname} > ~/.sumo/ssh.log 2>&1", "w") do |pipe|
|
232
|
+
IO.popen("ssh -i #{keypair_file} #{config['user']}@#{hostname} > #{config['logfile'] || "~/.sumo/ssh.log"} 2>&1", "w") do |pipe|
|
191
233
|
pipe.puts cmds.join(' && ')
|
192
234
|
end
|
193
235
|
unless $?.success?
|
194
|
-
abort "failed\nCheck ~/.sumo/ssh.log for the output"
|
236
|
+
abort "failed\nCheck #{config['logfile'] || "~/.sumo/ssh.log"} for the output"
|
195
237
|
end
|
196
238
|
end
|
197
239
|
|
@@ -242,7 +284,7 @@ class Sumo
|
|
242
284
|
end
|
243
285
|
|
244
286
|
def fetch_resources(hostname)
|
245
|
-
cmd = "ssh -i #{keypair_file} #{config['user']}@#{hostname} 'cat /root/resources' 2>&1"
|
287
|
+
cmd = "ssh -i #{keypair_file} #{config['user']}@#{hostname} 'sudo cat /root/resources' 2>&1"
|
246
288
|
out = IO.popen(cmd, 'r') { |pipe| pipe.read }
|
247
289
|
abort "failed to read resources, output:\n#{out}" unless $?.success?
|
248
290
|
parse_resources(out, hostname)
|
@@ -266,11 +308,16 @@ class Sumo
|
|
266
308
|
@config ||= default_config.merge read_config
|
267
309
|
end
|
268
310
|
|
311
|
+
def set(key, value)
|
312
|
+
config[key] = value
|
313
|
+
end
|
314
|
+
|
269
315
|
def default_config
|
270
316
|
{
|
271
|
-
'user' => '
|
272
|
-
'ami' => 'ami-
|
273
|
-
'availability_zone' => 'us-east-
|
317
|
+
'user' => 'ubuntu',
|
318
|
+
'ami' => 'ami-1234de7b', # Ubuntu 10.04 LTS (Lucid Lynx)
|
319
|
+
'availability_zone' => 'us-east-1d',
|
320
|
+
'instance_size' => 't1.micro'
|
274
321
|
}
|
275
322
|
end
|
276
323
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cardmagic-sumo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Wiggins
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-24 00:00:00 -07:00
|
19
19
|
default_executable: sumo
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|