inprovise 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/inprovise/cmd_helper.rb +4 -0
- data/lib/inprovise/execution_context.rb +5 -1
- data/lib/inprovise/group.rb +2 -2
- data/lib/inprovise/helper/linux.rb +8 -2
- data/lib/inprovise/helper/windows.rb +4 -0
- data/lib/inprovise/infra.rb +6 -2
- data/lib/inprovise/local_file.rb +15 -2
- data/lib/inprovise/node.rb +7 -2
- data/lib/inprovise/remote_file.rb +21 -7
- data/lib/inprovise/version.rb +1 -1
- data/test/local_file_test.rb +9 -2
- data/test/remote_file_test.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjA2NmY3ZWEzYjMzZWZhN2NiZTQ1MTkzODNlMjFhZmMyZDA5MzYzMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzMxY2Q2NzNiMmYyZjg4YjRlOTFhNDBlNmM0YTZiNzM5OTg5ZDNhNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDk2Nzc2ZDZlYjhjNjFiMmM0NzdiMDFiOWNmNjIyYWNlOTdjMDViOTQxOGRi
|
10
|
+
ZjQwMGUwYWZmYzU0YjBmZTI0MjZmZjE2NjAyZjQwMGEzNmMyODk5ZjRjOWQ4
|
11
|
+
MDgwNjBiNzZlYTBiNTQxYjUyNDUzMWViODQwNGI0Y2QzMTZjZTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjA0ZWY1YmJmODJjMjhlZTIzYmJhYzE0OTMzNTMyMmE4NjkwN2E2OGUyMjcy
|
14
|
+
MzdkZDQxODMwZDNiOTNhOTlkYTcyMGQ2NGQ3ZGIzNDc5MmFiNWI5ZDFhNGZm
|
15
|
+
Y2ZhYWYwYzEwZDRhZWE0NzAwODUzNDYzMDYyMTk3Y2I5ZjI0ZTI=
|
data/lib/inprovise/cmd_helper.rb
CHANGED
@@ -183,8 +183,12 @@ class Inprovise::ExecutionContext
|
|
183
183
|
@node.copy(from, to)
|
184
184
|
end
|
185
185
|
|
186
|
+
def move(from, to)
|
187
|
+
@node.move(from, to)
|
188
|
+
end
|
189
|
+
|
186
190
|
def local(path)
|
187
|
-
Inprovise::LocalFile.new(path)
|
191
|
+
Inprovise::LocalFile.new(self, path)
|
188
192
|
end
|
189
193
|
|
190
194
|
def remote(path)
|
data/lib/inprovise/group.rb
CHANGED
@@ -61,7 +61,7 @@ class Inprovise::Infrastructure::Group < Inprovise::Infrastructure::Target
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.json_create(o)
|
64
|
-
data = o[
|
65
|
-
new(data[
|
64
|
+
data = o['data']
|
65
|
+
new(data['name'], Inprovise::Infrastructure.symbolize_keys(data['config']), data['targets'])
|
66
66
|
end
|
67
67
|
end
|
@@ -41,6 +41,8 @@ Inprovise::CmdHelper.define('linux') do
|
|
41
41
|
def sudo
|
42
42
|
return self if @exec == :sudo_run
|
43
43
|
@sudo ||= self.class.new(@channel, true)
|
44
|
+
@sudo.set_cwd(@cwd)
|
45
|
+
@sudo
|
44
46
|
end
|
45
47
|
|
46
48
|
# file management
|
@@ -83,7 +85,7 @@ Inprovise::CmdHelper.define('linux') do
|
|
83
85
|
begin
|
84
86
|
@channel.exists?(path)
|
85
87
|
rescue
|
86
|
-
exec(%{if [ -f #{path} ]; then echo
|
88
|
+
exec(%{if [ -f #{path} ]; then echo true; else echo false; fi}).strip == 'true'
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
@@ -109,6 +111,10 @@ Inprovise::CmdHelper.define('linux') do
|
|
109
111
|
exec("cp #{real_path(from)} #{real_path(to)}")
|
110
112
|
end
|
111
113
|
|
114
|
+
def move(from, to)
|
115
|
+
exec("mv #{real_path(from)} #{real_path(to)}")
|
116
|
+
end
|
117
|
+
|
112
118
|
def delete(path)
|
113
119
|
path = real_path(path)
|
114
120
|
begin
|
@@ -175,7 +181,7 @@ Inprovise::CmdHelper.define('linux') do
|
|
175
181
|
end
|
176
182
|
|
177
183
|
def sudo_run(cmd, forcelog=false)
|
178
|
-
@channel.run(
|
184
|
+
@channel.run(%{sudo sh -c "#{cmd}"}, forcelog)
|
179
185
|
end
|
180
186
|
|
181
187
|
end
|
data/lib/inprovise/infra.rb
CHANGED
@@ -9,8 +9,12 @@ require 'monitor'
|
|
9
9
|
module Inprovise::Infrastructure
|
10
10
|
|
11
11
|
# setup JSON parameters
|
12
|
-
JSON.
|
13
|
-
|
12
|
+
JSON.create_id = 'json_class'
|
13
|
+
|
14
|
+
def self.symbolize_keys(hsh)
|
15
|
+
return hsh unless Hash === hsh
|
16
|
+
hsh.reduce({}) {|h, (k,v)| h[k.to_sym] = symbolize_keys(v); h }
|
17
|
+
end
|
14
18
|
|
15
19
|
class << self
|
16
20
|
def targets
|
data/lib/inprovise/local_file.rb
CHANGED
@@ -10,7 +10,8 @@ require 'etc'
|
|
10
10
|
class Inprovise::LocalFile
|
11
11
|
attr_reader :path
|
12
12
|
|
13
|
-
def initialize(path)
|
13
|
+
def initialize(context, path)
|
14
|
+
@context = context
|
14
15
|
@path = resolve(path)
|
15
16
|
end
|
16
17
|
|
@@ -50,19 +51,31 @@ class Inprovise::LocalFile
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def copy_to(destination)
|
54
|
+
destination = self.class.new(destination) if String === destination
|
53
55
|
if destination.is_local?
|
54
56
|
duplicate(destination)
|
55
57
|
else
|
56
58
|
upload(destination)
|
57
59
|
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def move_to(destination)
|
63
|
+
destination = self.class.new(destination) if String === destination
|
64
|
+
if destination.is_local?
|
65
|
+
FileUtils.mv(path, destination.path)
|
66
|
+
else
|
67
|
+
upload(destination)
|
68
|
+
end
|
58
69
|
destination
|
59
70
|
end
|
60
71
|
|
61
72
|
def copy_from(source)
|
73
|
+
source = self.class.new(source) if String === source
|
62
74
|
source.copy_to(self)
|
63
75
|
end
|
64
76
|
|
65
77
|
def duplicate(destination)
|
78
|
+
destination = self.class.new(destination) if String === destination
|
66
79
|
FileUtils.cp(path, destination.path)
|
67
80
|
destination
|
68
81
|
end
|
@@ -70,7 +83,7 @@ class Inprovise::LocalFile
|
|
70
83
|
def upload(destination)
|
71
84
|
destination = @context.remote(destination) if String === destination
|
72
85
|
if destination.is_local?
|
73
|
-
|
86
|
+
duplicate(destination)
|
74
87
|
else
|
75
88
|
destination.upload(self)
|
76
89
|
end
|
data/lib/inprovise/node.rb
CHANGED
@@ -126,6 +126,11 @@ class Inprovise::Infrastructure::Node < Inprovise::Infrastructure::Target
|
|
126
126
|
helper.copy(from, to)
|
127
127
|
end
|
128
128
|
|
129
|
+
def move(from, to)
|
130
|
+
log.execute("MOVE: #{from} #{to}") if Inprovise.verbosity > 0
|
131
|
+
helper.move(from, to)
|
132
|
+
end
|
133
|
+
|
129
134
|
def delete(path)
|
130
135
|
log.execute("DELETE: #{path}") if Inprovise.verbosity > 0
|
131
136
|
helper.delete(path)
|
@@ -228,8 +233,8 @@ class Inprovise::Infrastructure::Node < Inprovise::Infrastructure::Target
|
|
228
233
|
end
|
229
234
|
|
230
235
|
def self.json_create(o)
|
231
|
-
data = o[
|
232
|
-
new(data[
|
236
|
+
data = o['data']
|
237
|
+
new(data['name'], Inprovise::Infrastructure.symbolize_keys(data['config']))
|
233
238
|
end
|
234
239
|
|
235
240
|
private
|
@@ -45,35 +45,49 @@ class Inprovise::RemoteFile
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def copy_to(destination)
|
48
|
+
destination = @context.remote(destination) if String === destination
|
48
49
|
if destination.is_local?
|
49
50
|
download(destination)
|
50
51
|
else
|
51
52
|
duplicate(destination)
|
52
53
|
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def move_to(destination)
|
57
|
+
destination = @context.remote(destination) if String === destination
|
58
|
+
if destination.is_local?
|
59
|
+
download(destination)
|
60
|
+
else
|
61
|
+
@context.move(path, destination.path)
|
62
|
+
end
|
53
63
|
destination
|
54
64
|
end
|
55
65
|
|
56
|
-
def copy_from(
|
57
|
-
|
66
|
+
def copy_from(source)
|
67
|
+
source = @context.remote(source) if String === source
|
68
|
+
source.copy_to(self)
|
58
69
|
end
|
59
70
|
|
60
71
|
def duplicate(destination)
|
72
|
+
destination = @context.remote(destination) if String === destination
|
61
73
|
@context.copy(path, destination.path)
|
62
74
|
destination
|
63
75
|
end
|
64
76
|
|
65
77
|
def download(destination)
|
66
|
-
if String === destination
|
67
|
-
|
78
|
+
destination = @context.local(destination) if String === destination
|
79
|
+
if destination.is_local?
|
80
|
+
@context.download(path, destination.path)
|
68
81
|
else
|
69
82
|
@context.copy(path, destination.path)
|
70
83
|
end
|
71
|
-
|
84
|
+
destination
|
72
85
|
end
|
73
86
|
|
74
87
|
def upload(source)
|
75
|
-
if String === source
|
76
|
-
|
88
|
+
source = @context.local(source) if String === source
|
89
|
+
if source.is_local?
|
90
|
+
@context.upload(source.path, path)
|
77
91
|
else
|
78
92
|
@context.copy(source.path, path)
|
79
93
|
end
|
data/lib/inprovise/version.rb
CHANGED
data/test/local_file_test.rb
CHANGED
@@ -7,8 +7,15 @@ require_relative 'test_helper'
|
|
7
7
|
|
8
8
|
describe Inprovise::LocalFile do
|
9
9
|
before :each do
|
10
|
+
@node = Inprovise::Infrastructure::Node.new('Node1', {host: 'host.address.net', channel: 'test', helper: 'test'})
|
11
|
+
@log = Inprovise::Logger.new(@node, 'remote_file_test')
|
12
|
+
@context = Inprovise::ExecutionContext.new(@node, @log, Inprovise::ScriptIndex.default)
|
10
13
|
@local_file_path = File.join(File.dirname(__FILE__), 'fixtures', 'example.txt')
|
11
|
-
@local_file = Inprovise::LocalFile.new(@local_file_path)
|
14
|
+
@local_file = Inprovise::LocalFile.new(@context, @local_file_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
after :each do
|
18
|
+
reset_infrastructure!
|
12
19
|
end
|
13
20
|
|
14
21
|
describe 'path' do
|
@@ -36,7 +43,7 @@ describe Inprovise::LocalFile do
|
|
36
43
|
end
|
37
44
|
|
38
45
|
describe 'copy_to' do
|
39
|
-
before(:each) { @destination = Inprovise::LocalFile.new("/tmp/example-#{Time.now.to_i}.txt") }
|
46
|
+
before(:each) { @destination = Inprovise::LocalFile.new(@context, "/tmp/example-#{Time.now.to_i}.txt") }
|
40
47
|
after(:each) { @destination.delete! }
|
41
48
|
|
42
49
|
it 'copies a file to another local location' do
|
data/test/remote_file_test.rb
CHANGED
@@ -10,9 +10,9 @@ describe Inprovise::RemoteFile do
|
|
10
10
|
@node = Inprovise::Infrastructure::Node.new('Node1', {host: 'host.address.net', channel: 'test', helper: 'test'})
|
11
11
|
@log = Inprovise::Logger.new(@node, 'remote_file_test')
|
12
12
|
@local_file_path = File.join(File.dirname(__FILE__), 'fixtures', 'example.txt')
|
13
|
-
@local_file = Inprovise::LocalFile.new(@local_file_path)
|
14
13
|
@remote_file_path = '/tmp/example.txt'
|
15
14
|
@context = Inprovise::ExecutionContext.new(@node, @log, Inprovise::ScriptIndex.default)
|
15
|
+
@local_file = Inprovise::LocalFile.new(@context, @local_file_path)
|
16
16
|
@remote_file = Inprovise::RemoteFile.new(@context, @remote_file_path)
|
17
17
|
end
|
18
18
|
|
@@ -67,7 +67,7 @@ describe Inprovise::RemoteFile do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'copies a file to local location by downlaoding it' do
|
70
|
-
@local_destination = Inprovise::LocalFile.new("/tmp/example-#{Time.now.to_i}.txt")
|
70
|
+
@local_destination = Inprovise::LocalFile.new(@context, "/tmp/example-#{Time.now.to_i}.txt")
|
71
71
|
@node.helper.expects(:download)
|
72
72
|
.with(@remote_file.path, @local_destination.path)
|
73
73
|
.returns(nil)
|