scalarium 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/scalarium/cli.rb +58 -2
- data/lib/scalarium/version.rb +1 -1
- data/scalarium.gemspec +1 -1
- metadata +13 -13
data/CHANGELOG
CHANGED
data/lib/scalarium/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'net/ssh'
|
2
3
|
|
3
4
|
trap("INT"){ exit -1 }
|
4
5
|
|
@@ -39,6 +40,31 @@ class Scalarium
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
43
|
+
desc 'execute COMMAND', "Execute a command in a cloud"
|
44
|
+
method_option :cloud, :aliases => "-c", :desc => "only for clouds matchin this regexp"
|
45
|
+
method_option :instance, :aliases => "-i", :type => :array, :desc => "List of instances: -i instace1 instace2"
|
46
|
+
def execute(command)
|
47
|
+
|
48
|
+
capture_exceptions do
|
49
|
+
scalarium = ::Scalarium.new(get_token, options[:cloud])
|
50
|
+
instances = nil
|
51
|
+
|
52
|
+
if scalarium.clouds.size > 1
|
53
|
+
$stderr.puts "This operation should be done in only one cloud"
|
54
|
+
exit -1
|
55
|
+
elsif scalarium.clouds.size < 1
|
56
|
+
$stderr.puts "You should select at least one cloud"
|
57
|
+
exit -2
|
58
|
+
end
|
59
|
+
cloud = scalarium.clouds.first
|
60
|
+
hosts = get_instances(cloud, options[:instances]).map{|i| i.nickname}
|
61
|
+
|
62
|
+
hosts.threaded_each do |host|
|
63
|
+
run_remote_command(host, command)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
42
68
|
desc 'update_cookbooks', "Make instances to pull changes from recipies repository"
|
43
69
|
method_option :cloud, :aliases => "-c", :desc => "only for clouds matchin this regexp"
|
44
70
|
def update_cookbooks
|
@@ -47,7 +73,6 @@ class Scalarium
|
|
47
73
|
|
48
74
|
scalarium.clouds.each do |cloud|
|
49
75
|
puts "Updating cookbooks for #{cloud.name}"
|
50
|
-
next unless (ask "Continue? (say yes)").strip == "yes"
|
51
76
|
|
52
77
|
deploy_info = cloud.update_cookbooks!
|
53
78
|
|
@@ -175,7 +200,38 @@ class Scalarium
|
|
175
200
|
|
176
201
|
protected
|
177
202
|
|
203
|
+
def run_remote_command(host, command)
|
204
|
+
puts "Oppening connection to host #{host}" if $DEBUG
|
205
|
+
Net::SSH.start(host, ENV["USER"]) do |ssh|
|
206
|
+
puts "Executing #{command}" if $DEBUG
|
207
|
+
ssh.exec!(command) do |channel, stream, data|
|
208
|
+
Thread.exclusive do
|
209
|
+
case stream
|
210
|
+
when :stdout
|
211
|
+
$stdout.puts ("#{Color::GREEN}%10s: #{Color::CLEAR}%s" %[ host, data])
|
212
|
+
when :stderr
|
213
|
+
$stderr.puts ("#{Color::GREEN}%10s: #{Color::CLEAR}%s" %[ host, data])
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
rescue Net::SSH::AuthenticationFailed
|
219
|
+
Thread.exclusive do
|
220
|
+
$stderr.puts "#{Color::RED}Could not execute a command in #{host} because auth problems"
|
221
|
+
$stderr.puts "Check that you can access #{host} through 'ssh #{host}' as your username (ENV['USER'])#{Color::CLEAR}"
|
222
|
+
end
|
223
|
+
rescue SocketError
|
224
|
+
Thread.exclusive do
|
225
|
+
$stderr.puts "#{Color::RED}Cold not connect to #{host} due connection problems#{Color::CLEAR}"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
178
229
|
def get_instances_ids(cloud, instances)
|
230
|
+
get_instances(cloud, instances).map{|i| i.id }
|
231
|
+
end
|
232
|
+
|
233
|
+
def get_instances(cloud, instances)
|
234
|
+
return cloud.instances if instances.nil? || instances.empty?
|
179
235
|
posible_instances = cloud.instances.select{|instance|
|
180
236
|
instances.include?(instance.nickname.downcase)
|
181
237
|
}
|
@@ -187,7 +243,7 @@ class Scalarium
|
|
187
243
|
end
|
188
244
|
exit -3
|
189
245
|
end
|
190
|
-
posible_instances
|
246
|
+
posible_instances
|
191
247
|
end
|
192
248
|
|
193
249
|
def format_ssh_config_host(instance)
|
data/lib/scalarium/version.rb
CHANGED
data/scalarium.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_runtime_dependency 'rest-client'
|
22
|
-
s.add_runtime_dependency 'dispatch_queue'
|
22
|
+
s.add_runtime_dependency 'dispatch_queue', ">=1.1.0"
|
23
23
|
s.add_runtime_dependency 'thor'
|
24
24
|
s.add_development_dependency 'ruby-debug19'
|
25
25
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scalarium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &2169193260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2169193260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: dispatch_queue
|
27
|
-
requirement: &
|
27
|
+
requirement: &2169192640 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 1.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2169192640
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: thor
|
38
|
-
requirement: &
|
38
|
+
requirement: &2169192100 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2169192100
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: ruby-debug19
|
49
|
-
requirement: &
|
49
|
+
requirement: &2169191520 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2169191520
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &2169190980 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2169190980
|
69
69
|
description: Access your scalarium clouds from console
|
70
70
|
email:
|
71
71
|
- guillermo@cientifico.net
|