cloudler 0.1.5 → 0.2.0
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/bin/cloud +26 -4
- data/lib/cloudler.rb +70 -56
- metadata +2 -2
data/bin/cloud
CHANGED
@@ -1,22 +1,44 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'cloudler'
|
4
|
-
|
4
|
+
action = ARGV.shift
|
5
|
+
if action == 'init'
|
5
6
|
Cloudler.init
|
6
|
-
elsif
|
7
|
+
elsif action == 'test'
|
8
|
+
if File.exists? 'Cloudfile'
|
9
|
+
File.open 'Cloudfile', 'r' do |f|
|
10
|
+
config = f.read
|
11
|
+
eval config
|
12
|
+
end
|
13
|
+
|
14
|
+
Cloudler.test_connection
|
15
|
+
else
|
16
|
+
puts "It doesn't like this is a cloudler project. Try running 'cloud init'"
|
17
|
+
end
|
18
|
+
elsif action == 'run'
|
7
19
|
if File.exists? 'Cloudfile'
|
8
20
|
File.open 'Cloudfile', 'r' do |f|
|
9
21
|
config = f.read
|
10
22
|
eval config
|
11
23
|
end
|
12
24
|
|
13
|
-
|
25
|
+
if ARGV.length > 0
|
26
|
+
Cloudler.run ARGV.collect {|a| a.to_sym}
|
27
|
+
else
|
28
|
+
Cloudler.run
|
29
|
+
end
|
14
30
|
else
|
15
31
|
puts "It doesn't like this is a cloudler project. Try running 'cloud init'"
|
16
32
|
end
|
17
33
|
else
|
18
|
-
puts "Usage: cloud [command]"
|
34
|
+
puts "Usage: cloud [command] [args]"
|
19
35
|
puts " commands:"
|
20
36
|
puts " init -- create a new cloudler project"
|
37
|
+
puts " test -- test the cloudler settings"
|
21
38
|
puts " run -- run a cloud project"
|
39
|
+
puts " If you want to run only part of the actions, you can use:"
|
40
|
+
puts " upload -- Upload files"
|
41
|
+
puts " precommands -- Run the precommands"
|
42
|
+
puts " gems -- Install the gems"
|
43
|
+
puts " command -- Run the command"
|
22
44
|
end
|
data/lib/cloudler.rb
CHANGED
@@ -3,41 +3,26 @@ require 'net/scp'
|
|
3
3
|
|
4
4
|
class Cloudler
|
5
5
|
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.2.0'
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
class << self
|
9
|
+
attr_accessor :hosts, :username, :command, :gems, :password, :files, :precommands, :path
|
10
10
|
end
|
11
|
-
|
12
|
-
def self.
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.password= password
|
25
|
-
@password = password
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.files= files
|
29
|
-
@files = files
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.precommands= precommands
|
33
|
-
@precommands = precommands
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.path= path
|
37
|
-
@path = path
|
11
|
+
|
12
|
+
def self.test_connection
|
13
|
+
@hosts.each do |host|
|
14
|
+
begin
|
15
|
+
Net::SSH.start(host, @username, :password => @password) do |ssh|
|
16
|
+
puts "Connected to #{host} successfully."
|
17
|
+
end
|
18
|
+
rescue
|
19
|
+
puts "Error connecting to #{host}."
|
20
|
+
end
|
21
|
+
end
|
38
22
|
end
|
39
23
|
|
40
|
-
def self.run
|
24
|
+
def self.run to_run = [:upload, :precommands, :gems, :command]
|
25
|
+
# Set some defaults
|
41
26
|
@files ||= []
|
42
27
|
@gems ||= []
|
43
28
|
@precommands ||= []
|
@@ -50,44 +35,73 @@ class Cloudler
|
|
50
35
|
|
51
36
|
@hosts.each do |host|
|
52
37
|
Net::SSH.start(host, @username, :password => @password) do |ssh|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
ssh.scp.upload!(@files.join(' '), @path, :recursive => true)
|
58
|
-
else
|
59
|
-
ssh.scp.upload!('.', @path, :recursive => true)
|
38
|
+
if to_run.member? :upload
|
39
|
+
puts "Uploading files..."
|
40
|
+
upload_files ssh
|
41
|
+
puts "Files uploaded."
|
60
42
|
end
|
61
|
-
|
62
|
-
puts "Files uploaded."
|
63
43
|
|
64
|
-
if
|
65
|
-
|
66
|
-
|
67
|
-
ssh
|
68
|
-
|
69
|
-
end
|
44
|
+
if to_run.member? :precommands
|
45
|
+
if @precommands.length > 0
|
46
|
+
puts "Executing pre-commands"
|
47
|
+
execute_precommands ssh
|
48
|
+
puts "Pre-commands executed."
|
70
49
|
end
|
71
|
-
puts "Pre-commands executed."
|
72
50
|
end
|
73
51
|
|
74
|
-
if
|
75
|
-
|
76
|
-
|
77
|
-
|
52
|
+
if to_run.member? :gems
|
53
|
+
if @gems.length > 0
|
54
|
+
puts "Installing gems..."
|
55
|
+
install_gems ssh
|
56
|
+
puts "Gems installed"
|
78
57
|
end
|
79
|
-
puts "Gems installed"
|
80
58
|
end
|
81
59
|
|
82
|
-
|
83
|
-
|
84
|
-
|
60
|
+
if to_run.member? :command
|
61
|
+
puts "Executing command..."
|
62
|
+
execute_command ssh
|
63
|
+
puts "Command finished."
|
85
64
|
end
|
86
|
-
puts "Command finished."
|
87
65
|
end
|
88
66
|
end
|
89
67
|
end
|
90
68
|
|
69
|
+
def self.upload_files ssh
|
70
|
+
ssh.exec! "rm -rf #{@path}"
|
71
|
+
ssh.exec! "mkdir #{@path}"
|
72
|
+
|
73
|
+
# By default, Cloudler uploads the entire current directory
|
74
|
+
if @files.length > 0
|
75
|
+
ssh.scp.upload!(@files.join(' '), @path, :recursive => true)
|
76
|
+
else
|
77
|
+
ssh.scp.upload!('.', @path, :recursive => true)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.execute_precommands ssh
|
82
|
+
@precommands.each do |command|
|
83
|
+
# We cd to @path so that the user can modify or run their uploaded files if
|
84
|
+
# they need to
|
85
|
+
ssh.exec "cd #{@path} && #{command}" do |ch,stream,data|
|
86
|
+
puts data
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.install_gems ssh
|
92
|
+
ssh.exec! "gem install #{@gems.join ' '}" do |ch, stream, data|
|
93
|
+
puts data
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.execute_command ssh
|
98
|
+
# We cd to @path so that the user has access to their uploaded files when
|
99
|
+
# they try to run them
|
100
|
+
ssh.exec! "cd #{@path} && #{@command}" do |ch, stream, data|
|
101
|
+
puts data
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
91
105
|
def self.init
|
92
106
|
File.open "Cloudfile", 'w' do |f|
|
93
107
|
f.write <<-EOS
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cloudler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bruce Spang
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-24 00:00:00 -05:00
|
14
14
|
default_executable: cloud
|
15
15
|
dependencies: []
|
16
16
|
|