orca 0.3.2 → 0.3.3
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/Gemfile.lock +1 -1
- data/lib/orca.rb +1 -0
- data/lib/orca/execution_context.rb +22 -10
- data/lib/orca/extensions/apt.rb +3 -2
- data/lib/orca/logger.rb +53 -0
- data/lib/orca/node.rb +45 -17
- data/lib/orca/runner.rb +5 -3
- data/orca.gemspec +1 -1
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/lib/orca.rb
CHANGED
@@ -1,20 +1,32 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
1
3
|
class Orca::ExecutionContext
|
2
4
|
attr_reader :node
|
3
5
|
|
4
|
-
def initialize(node)
|
6
|
+
def initialize(node, log)
|
5
7
|
@node = node
|
8
|
+
@log = log
|
9
|
+
@node.log_to(@log)
|
6
10
|
end
|
7
11
|
|
8
12
|
def apply(blk)
|
9
13
|
instance_eval(&blk)
|
10
14
|
end
|
11
15
|
|
16
|
+
def run_local(cmd)
|
17
|
+
@log.local(cmd)
|
18
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
19
|
+
@log.stdout(stdout)
|
20
|
+
@log.stderr(stderr)
|
21
|
+
end
|
22
|
+
|
12
23
|
def run(cmd, opts={})
|
13
24
|
@node.execute(cmd, opts)
|
14
25
|
end
|
15
26
|
|
16
|
-
def log(msg)
|
17
|
-
@
|
27
|
+
def log(msg=nil)
|
28
|
+
@log.log(msg) if msg
|
29
|
+
@log
|
18
30
|
end
|
19
31
|
|
20
32
|
def sudo(cmd, opts={})
|
@@ -74,32 +86,32 @@ end
|
|
74
86
|
|
75
87
|
class Orca::MockExecutionContext < Orca::ExecutionContext
|
76
88
|
def run(cmd)
|
77
|
-
@
|
89
|
+
@log.mock_execute(cmd)
|
78
90
|
''
|
79
91
|
end
|
80
92
|
|
81
93
|
def sudo(cmd)
|
82
|
-
@
|
94
|
+
@log.mock_execute "sudo #{cmd}"
|
83
95
|
''
|
84
96
|
end
|
85
97
|
|
86
98
|
def upload(from, to)
|
87
|
-
@
|
99
|
+
@log.mock_execute("UPLOAD: #{from} => #{to}")
|
88
100
|
end
|
89
101
|
|
90
102
|
def download(from, to)
|
91
|
-
@
|
103
|
+
@log.mock_execute("DOWLOAD: #{from} => #{to}")
|
92
104
|
end
|
93
105
|
|
94
106
|
def remove(path)
|
95
|
-
@
|
107
|
+
@log.mock_execute("REMOVE: #{path}")
|
96
108
|
end
|
97
109
|
|
98
110
|
def stat(path)
|
99
|
-
@
|
111
|
+
@log.mock_execute("STAT: #{path}")
|
100
112
|
end
|
101
113
|
|
102
114
|
def setstat(path, opts)
|
103
|
-
@
|
115
|
+
@log.mock_execute("SET: #{path} - #{opts.inspect}")
|
104
116
|
end
|
105
117
|
end
|
data/lib/orca/extensions/apt.rb
CHANGED
@@ -37,10 +37,11 @@ Orca.extension :apt do
|
|
37
37
|
|
38
38
|
action 'ppa' do |repo|
|
39
39
|
sudo "DEBIAN_FRONTEND=noninteractive add-apt-repository #{repo} -y"
|
40
|
+
trigger 'apt:update', true
|
40
41
|
end
|
41
42
|
|
42
|
-
action 'update' do
|
43
|
-
sudo "DEBIAN_FRONTEND=noninteractive apt-get update -y -qq"
|
43
|
+
action 'update' do |force=false|
|
44
|
+
sudo "DEBIAN_FRONTEND=noninteractive apt-get update -y -qq", {:once => !force}
|
44
45
|
end
|
45
46
|
|
46
47
|
action 'exists' do |package_name, required_version=nil|
|
data/lib/orca/logger.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
class Orca::Logger
|
2
|
+
def initialize(node, package)
|
3
|
+
@node = node
|
4
|
+
@package = package
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_package(package)
|
8
|
+
@package = package
|
9
|
+
end
|
10
|
+
|
11
|
+
def command(msg)
|
12
|
+
say(msg, :yellow)
|
13
|
+
end
|
14
|
+
|
15
|
+
def local(cmd)
|
16
|
+
say(cmd, :cyan)
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(cmd)
|
20
|
+
say(cmd, :cyan)
|
21
|
+
end
|
22
|
+
|
23
|
+
def mock_execute(cmd)
|
24
|
+
execute(cmd)
|
25
|
+
end
|
26
|
+
|
27
|
+
def cached(cmd)
|
28
|
+
execute(cmd)
|
29
|
+
end
|
30
|
+
|
31
|
+
def sftp(cmd)
|
32
|
+
execute(cmd)
|
33
|
+
end
|
34
|
+
|
35
|
+
def log(msg)
|
36
|
+
say(msg)
|
37
|
+
end
|
38
|
+
|
39
|
+
def stdout(msg, force=false)
|
40
|
+
say(msg, :green) if force || Orca.verbose
|
41
|
+
end
|
42
|
+
|
43
|
+
def stderr(msg, force=false)
|
44
|
+
say(msg, :red) if force || Orca.verbose
|
45
|
+
end
|
46
|
+
|
47
|
+
def say(msg, color=nil)
|
48
|
+
msg.to_s.split("\n").each do |line|
|
49
|
+
out = color ? line.send(color) : line
|
50
|
+
Thread.exclusive { puts "#{@node.to_s} [#{@package.name.bold}] #{out}" }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/orca/node.rb
CHANGED
@@ -20,6 +20,7 @@ class Orca::Node
|
|
20
20
|
@host = host
|
21
21
|
@options = options
|
22
22
|
@connection = nil
|
23
|
+
@history = []
|
23
24
|
Orca::Node.register(self)
|
24
25
|
end
|
25
26
|
|
@@ -32,17 +33,17 @@ class Orca::Node
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def upload(from, to)
|
35
|
-
log(
|
36
|
+
log.sftp("UPLOAD: #{from} => #{to}")
|
36
37
|
sftp.upload!(from, to)
|
37
38
|
end
|
38
39
|
|
39
40
|
def download(from, to)
|
40
|
-
log(
|
41
|
+
log.sftp("DOWLOAD: #{from} => #{to}")
|
41
42
|
sftp.download!(from, to)
|
42
43
|
end
|
43
44
|
|
44
45
|
def remove(path)
|
45
|
-
log(
|
46
|
+
log.sftp("REMOVE: #{path}")
|
46
47
|
begin
|
47
48
|
sftp.remove!(path)
|
48
49
|
rescue Net::SFTP::StatusException
|
@@ -51,12 +52,12 @@ class Orca::Node
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def stat(path)
|
54
|
-
log(
|
55
|
+
log.sftp("STAT: #{path}")
|
55
56
|
sftp.stat!(path)
|
56
57
|
end
|
57
58
|
|
58
59
|
def setstat(path, opts)
|
59
|
-
log(
|
60
|
+
log.sftp("SET: #{path} - #{opts.inspect}")
|
60
61
|
sftp.setstat!(path, opts)
|
61
62
|
end
|
62
63
|
|
@@ -65,25 +66,23 @@ class Orca::Node
|
|
65
66
|
end
|
66
67
|
|
67
68
|
def execute(cmd, opts={})
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
data.split("\n").each do |line|
|
73
|
-
msg = stream == :stdout ? line.green : line.red
|
74
|
-
log(stream, msg) if opts[:log] || Orca.verbose
|
75
|
-
end
|
69
|
+
if should_execute?(cmd, opts)
|
70
|
+
really_execute(cmd, opts)
|
71
|
+
else
|
72
|
+
cached_execute(cmd, opts)
|
76
73
|
end
|
77
|
-
output
|
78
74
|
end
|
79
75
|
|
80
76
|
def sudo(cmd, opts={})
|
81
77
|
execute("sudo #{cmd}", opts)
|
82
78
|
end
|
83
79
|
|
84
|
-
def log
|
85
|
-
|
86
|
-
|
80
|
+
def log
|
81
|
+
@log
|
82
|
+
end
|
83
|
+
|
84
|
+
def log_to(log)
|
85
|
+
@log = log
|
87
86
|
end
|
88
87
|
|
89
88
|
def connection
|
@@ -108,4 +107,33 @@ class Orca::Node
|
|
108
107
|
hsh
|
109
108
|
end
|
110
109
|
end
|
110
|
+
|
111
|
+
def cached_execute(cmd, opts={})
|
112
|
+
log.cached(cmd)
|
113
|
+
last_output(cmd)
|
114
|
+
end
|
115
|
+
|
116
|
+
def really_execute(cmd, opts={})
|
117
|
+
log.execute(cmd.cyan)
|
118
|
+
output = ""
|
119
|
+
connection.exec! cmd do |channel, stream, data|
|
120
|
+
output += data if stream == :stdout
|
121
|
+
data.split("\n").each do |line|
|
122
|
+
log.send(stream, line, opts[:log])
|
123
|
+
end
|
124
|
+
end
|
125
|
+
@history << {cmd:cmd, output:output}
|
126
|
+
output
|
127
|
+
end
|
128
|
+
|
129
|
+
def should_execute?(cmd, opts)
|
130
|
+
return true unless opts[:once]
|
131
|
+
last_output(cmd).nil?
|
132
|
+
end
|
133
|
+
|
134
|
+
def last_output(cmd)
|
135
|
+
results = @history.select {|h| h[:cmd] == cmd }
|
136
|
+
return nil unless results && results.size > 0
|
137
|
+
results.last[:output]
|
138
|
+
end
|
111
139
|
end
|
data/lib/orca/runner.rb
CHANGED
@@ -4,6 +4,7 @@ class Orca::Runner
|
|
4
4
|
@package = package
|
5
5
|
@perform = true
|
6
6
|
@skip_dependancies = skip_dependancies
|
7
|
+
@log = Orca::Logger.new(@node, package)
|
7
8
|
end
|
8
9
|
|
9
10
|
def packages
|
@@ -14,7 +15,7 @@ class Orca::Runner
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def execute(command_name)
|
17
|
-
@
|
18
|
+
@log.say packages.map(&:name).join(', ').yellow
|
18
19
|
packages.each do |pkg|
|
19
20
|
send(:"execute_#{command_name}", pkg)
|
20
21
|
end
|
@@ -64,8 +65,9 @@ class Orca::Runner
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def exec(pkg, command_name)
|
67
|
-
@
|
68
|
-
|
68
|
+
@log.set_package(pkg)
|
69
|
+
@log.command(command_name)
|
70
|
+
context = @perform ? Orca::ExecutionContext.new(@node, @log) : Orca::MockExecutionContext.new(@node, @log)
|
69
71
|
cmds = pkg.command(command_name)
|
70
72
|
cmds.map {|cmd| context.apply(cmd) }
|
71
73
|
end
|
data/orca.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
11
11
|
gem.name = "orca"
|
12
12
|
gem.require_paths = ["lib"]
|
13
|
-
gem.version = '0.3.
|
13
|
+
gem.version = '0.3.3'
|
14
14
|
gem.add_dependency('colored')
|
15
15
|
gem.add_dependency('net-ssh')
|
16
16
|
gem.add_dependency('net-sftp')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colored
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/orca/extensions/file_sync.rb
|
101
101
|
- lib/orca/group.rb
|
102
102
|
- lib/orca/local_file.rb
|
103
|
+
- lib/orca/logger.rb
|
103
104
|
- lib/orca/node.rb
|
104
105
|
- lib/orca/package.rb
|
105
106
|
- lib/orca/package_index.rb
|
@@ -132,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
133
|
version: '0'
|
133
134
|
segments:
|
134
135
|
- 0
|
135
|
-
hash: -
|
136
|
+
hash: -3898811184980038862
|
136
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
138
|
none: false
|
138
139
|
requirements:
|
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
142
|
version: '0'
|
142
143
|
segments:
|
143
144
|
- 0
|
144
|
-
hash: -
|
145
|
+
hash: -3898811184980038862
|
145
146
|
requirements: []
|
146
147
|
rubyforge_project:
|
147
148
|
rubygems_version: 1.8.23
|