bleetz 2.0 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bleetz.rb +24 -11
- data/lib/bleetz/conf.rb +38 -51
- metadata +47 -58
data/lib/bleetz.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'net/ssh'
|
3
|
+
require 'net/ssh/proxy/command'
|
3
4
|
require 'yaml'
|
4
5
|
require 'bleetz/conf.rb'
|
5
6
|
require 'bleetz/object.rb'
|
@@ -127,18 +128,29 @@ EOF
|
|
127
128
|
def connect
|
128
129
|
abort "You have to configure SSH options." if @@options.empty?
|
129
130
|
unless @ssh_test
|
130
|
-
@@before[@action.to_sym].each { |b|
|
131
|
+
@@before[@action.to_sym].each { |b|
|
132
|
+
execute!(b) } unless @@before[@action.to_sym].nil?
|
131
133
|
end
|
134
|
+
if @@options[:proxycmd]
|
135
|
+
cmd = @@options.delete(:proxycmd)
|
136
|
+
abort "You need specify a proxy command !" if cmd.nil?
|
137
|
+
begin
|
138
|
+
@@options[:proxy] = Net::SSH::Proxy::Command.new(cmd)
|
139
|
+
rescue Exception => e
|
140
|
+
abort "SSH proxy command error: #{e.message}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
@@options[:timeout] = 10 unless @@options[:timeout]
|
132
144
|
begin
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
145
|
+
Net::SSH.start(@@options.delete(:host),
|
146
|
+
@@options.delete(:username),
|
147
|
+
@@options) { |ssh|
|
148
|
+
if !@cmd_to_exec.empty?
|
149
|
+
@cmd_to_exec.each { |command|
|
150
|
+
output = ssh.exec!(command)
|
151
|
+
puts output if @verbose
|
152
|
+
}
|
153
|
+
end
|
142
154
|
}
|
143
155
|
rescue NotImplementedError => e
|
144
156
|
abort "SSH error: #{e.message}"
|
@@ -153,7 +165,8 @@ EOF
|
|
153
165
|
abort "Timed out trying to get a connection."
|
154
166
|
end
|
155
167
|
unless @ssh_test
|
156
|
-
@@after[@action.to_sym].each { |a|
|
168
|
+
@@after[@action.to_sym].each { |a|
|
169
|
+
execute!(a) } unless @@after[@action.to_sym].nil?
|
157
170
|
end
|
158
171
|
end
|
159
172
|
|
data/lib/bleetz/conf.rb
CHANGED
@@ -8,6 +8,14 @@ end
|
|
8
8
|
|
9
9
|
module Conf
|
10
10
|
|
11
|
+
MAIN_CALLS = {:func => ['action', 'before', 'after', 'set'],
|
12
|
+
:from => ['load']}
|
13
|
+
|
14
|
+
SUB_CALLS = {:shell => ['action', 'before', 'after'],
|
15
|
+
:call => ['action'],
|
16
|
+
:error => { :shell => "'shell'. 'shell' has to be called in 'action', 'before' or 'after' functions.",
|
17
|
+
:call => "'call'. 'call' has to be called in 'action' function."} }
|
18
|
+
|
11
19
|
@@before = {}
|
12
20
|
@@actions = {}
|
13
21
|
@@after = {}
|
@@ -19,17 +27,8 @@ module Conf
|
|
19
27
|
end
|
20
28
|
|
21
29
|
def action(action, desc = "")
|
22
|
-
|
23
|
-
|
24
|
-
begin
|
25
|
-
yield
|
26
|
-
rescue Exception => e
|
27
|
-
if e.class.eql? RuntimeError
|
28
|
-
raise BleetzException.new(e.message)
|
29
|
-
else
|
30
|
-
raise BleetzException.new("#{e.class}: #{e.message} in #{e.backtrace[0]}")
|
31
|
-
end
|
32
|
-
end
|
30
|
+
check_call(:action)
|
31
|
+
load_conf { yield }
|
33
32
|
h = { action.to_sym => @cmds }
|
34
33
|
t = { action.to_sym => desc.to_s }
|
35
34
|
@@actions = @@actions.merge(h)
|
@@ -37,17 +36,8 @@ module Conf
|
|
37
36
|
end
|
38
37
|
|
39
38
|
def before(action)
|
40
|
-
|
41
|
-
|
42
|
-
begin
|
43
|
-
yield
|
44
|
-
rescue Exception => e
|
45
|
-
if e.class.eql? RuntimeError
|
46
|
-
raise BleetzException.new(e.message)
|
47
|
-
else
|
48
|
-
raise BleetzException.new("#{e.class}: #{e.message} in #{e.backtrace[0]}")
|
49
|
-
end
|
50
|
-
end
|
39
|
+
check_call(:before)
|
40
|
+
load_conf { yield }
|
51
41
|
h = { action.to_sym => @before }
|
52
42
|
if @@before[action.to_sym].nil?
|
53
43
|
@@before = @@before.merge(h)
|
@@ -57,17 +47,8 @@ module Conf
|
|
57
47
|
end
|
58
48
|
|
59
49
|
def after(action)
|
60
|
-
|
61
|
-
|
62
|
-
begin
|
63
|
-
yield
|
64
|
-
rescue Exception => e
|
65
|
-
if e.class.eql? RuntimeError
|
66
|
-
raise BleetzException.new(e.message)
|
67
|
-
else
|
68
|
-
raise BleetzException.new("#{e.class}: #{e.message} in #{e.backtrace[0]}")
|
69
|
-
end
|
70
|
-
end
|
50
|
+
check_call(:after)
|
51
|
+
load_conf { yield }
|
71
52
|
h = { action.to_sym => @after }
|
72
53
|
if @@before[action.to_sym].nil?
|
73
54
|
@@after = @@after.merge(h)
|
@@ -77,7 +58,7 @@ module Conf
|
|
77
58
|
end
|
78
59
|
|
79
60
|
def shell(cmd)
|
80
|
-
|
61
|
+
check_call(:shell)
|
81
62
|
raise "'shell' needs a String as parameter." unless cmd.is_a? String
|
82
63
|
if caller[1][/`([^']*)'/, 1].eql?("action")
|
83
64
|
@cmds << cmd
|
@@ -89,36 +70,42 @@ module Conf
|
|
89
70
|
end
|
90
71
|
|
91
72
|
def call(action)
|
92
|
-
|
73
|
+
check_call(:call)
|
93
74
|
raise "'call :action_name'. You didn't pass a Symbol." unless action.is_a? Symbol
|
94
75
|
@cmds << action
|
95
76
|
end
|
96
77
|
|
97
78
|
def set(opt, value)
|
98
|
-
|
79
|
+
check_call(:set)
|
99
80
|
@@options[opt.to_sym] = value
|
100
81
|
end
|
101
82
|
|
102
83
|
private
|
103
84
|
|
104
|
-
def
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
85
|
+
def check_call(func)
|
86
|
+
if MAIN_CALLS[:func].include?(func.to_s)
|
87
|
+
parent_call = caller[2][/`([^']*)'/, 1]
|
88
|
+
unless MAIN_CALLS[:from].include?(parent_call)
|
89
|
+
raise "#{caller[1].split(" ")[0]} '#{func}'. Main functions cannot be called in functions."
|
90
|
+
end
|
91
|
+
else
|
92
|
+
parent_call = caller[4][/`([^']*)'/, 1]
|
93
|
+
unless SUB_CALLS[func].include?(parent_call)
|
94
|
+
raise "#{caller[1].split(" ")[0]} #{SUB_CALLS[:error][func]}"
|
95
|
+
end
|
115
96
|
end
|
116
97
|
end
|
117
98
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
|
99
|
+
def load_conf
|
100
|
+
@after = @cmds = @before = []
|
101
|
+
begin
|
102
|
+
yield
|
103
|
+
rescue Exception => e
|
104
|
+
if e.class.eql? RuntimeError
|
105
|
+
raise BleetzException.new(e.message)
|
106
|
+
else
|
107
|
+
raise BleetzException.new("#{e.class}: #{e.message} in #{e.backtrace[0]}")
|
108
|
+
end
|
122
109
|
end
|
123
110
|
end
|
124
111
|
|
metadata
CHANGED
@@ -1,95 +1,84 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bleetz
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '2.1'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
version: "2.0"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Thibaut Deloffre
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
20
15
|
name: highline
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
31
22
|
type: :runtime
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: net-ssh
|
35
23
|
prerelease: false
|
36
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: net-ssh
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
37
33
|
none: false
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
version: "0"
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
45
38
|
type: :runtime
|
46
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
47
46
|
description: Fast KISS deployment tool
|
48
47
|
email: tib@rocknroot.org
|
49
|
-
executables:
|
48
|
+
executables:
|
50
49
|
- bleetz
|
51
50
|
extensions: []
|
52
|
-
|
53
|
-
extra_rdoc_files:
|
51
|
+
extra_rdoc_files:
|
54
52
|
- LICENSE.txt
|
55
|
-
files:
|
53
|
+
files:
|
56
54
|
- lib/bleetz.rb
|
57
55
|
- lib/bleetz/conf.rb
|
58
56
|
- lib/bleetz/object.rb
|
59
57
|
- LICENSE.txt
|
60
58
|
- bin/bleetz
|
61
59
|
homepage: https://github.com/TibshoOT/bleetz
|
62
|
-
licenses:
|
60
|
+
licenses:
|
63
61
|
- BSD
|
64
62
|
post_install_message:
|
65
63
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
64
|
+
require_paths:
|
68
65
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
67
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
73
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
87
78
|
requirements: []
|
88
|
-
|
89
79
|
rubyforge_project:
|
90
80
|
rubygems_version: 1.8.24
|
91
81
|
signing_key:
|
92
82
|
specification_version: 3
|
93
83
|
summary: Fast KISS deployment tool
|
94
84
|
test_files: []
|
95
|
-
|