vos 0.3.12 → 0.3.13
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/lib/old/ssh.rb +3 -3
- data/lib/vos.rb +2 -2
- data/lib/vos/box.rb +14 -14
- data/lib/vos/box/marks.rb +5 -5
- data/lib/vos/box/shell.rb +14 -14
- data/lib/vos/box/vfs.rb +8 -8
- data/lib/vos/drivers/abstract.rb +1 -1
- data/lib/vos/drivers/local.rb +18 -18
- data/lib/vos/drivers/specification.rb +4 -4
- data/lib/vos/drivers/ssh.rb +36 -36
- data/lib/vos/drivers/ssh_vfs_storage.rb +26 -26
- data/lib/vos/helpers/ubuntu.rb +18 -18
- data/lib/vos/support.rb +6 -6
- data/readme.md +8 -4
- data/spec/box_spec.rb +13 -13
- data/spec/config.example.yml +1 -1
- data/spec/drivers/local_spec.rb +2 -2
- data/spec/drivers/ssh_spec.rb +3 -3
- metadata +7 -7
data/lib/old/ssh.rb
CHANGED
data/lib/vos.rb
CHANGED
data/lib/vos/box.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Vos
|
2
2
|
class Box
|
3
3
|
include Shell, Marks, Vfs
|
4
|
-
|
4
|
+
|
5
5
|
def initialize *args
|
6
6
|
first = args.first
|
7
7
|
if args.empty?
|
@@ -10,12 +10,12 @@ module Vos
|
|
10
10
|
if first.is_a? Hash
|
11
11
|
options = first
|
12
12
|
options[:host] ||= 'localhost'
|
13
|
-
else
|
13
|
+
else
|
14
14
|
options = args[1] || {}
|
15
15
|
raise 'invalid arguments' unless options.is_a?(Hash)
|
16
16
|
options[:host] = first.to_s
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
@driver = options[:host] == 'localhost' ? Drivers::Local.new : Drivers::Ssh.new(options)
|
20
20
|
elsif args.size == 1
|
21
21
|
@driver = first
|
@@ -25,30 +25,30 @@ module Vos
|
|
25
25
|
end
|
26
26
|
|
27
27
|
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# driver
|
30
|
-
#
|
30
|
+
#
|
31
31
|
attr_reader :driver
|
32
|
-
|
32
|
+
|
33
33
|
def open &block
|
34
34
|
driver.open &block
|
35
|
-
end
|
35
|
+
end
|
36
36
|
def close
|
37
37
|
driver.close
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
#
|
40
|
+
|
41
|
+
#
|
42
42
|
# Miscellaneous
|
43
|
-
#
|
43
|
+
#
|
44
44
|
def inspect; driver.to_s end
|
45
45
|
alias_method :to_s, :inspect
|
46
|
-
|
46
|
+
|
47
47
|
def host; driver.host end
|
48
|
-
|
48
|
+
|
49
49
|
def local?; host == 'localhost' end
|
50
|
-
|
51
|
-
class << self
|
50
|
+
|
51
|
+
class << self
|
52
52
|
def local; @local ||= Box.new end
|
53
53
|
end
|
54
54
|
end
|
data/lib/vos/box/marks.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Vos
|
2
2
|
class Box
|
3
3
|
module Marks
|
4
|
-
def mark! key
|
4
|
+
def mark! key
|
5
5
|
marks_dir.file(key).create
|
6
6
|
@marks_cache = nil
|
7
7
|
end
|
@@ -10,18 +10,18 @@ module Vos
|
|
10
10
|
marks_cache.include? key.to_s
|
11
11
|
end
|
12
12
|
alias_method :marked?, :has_mark?
|
13
|
-
|
13
|
+
|
14
14
|
def clear_marks!
|
15
15
|
marks_dir.destroy
|
16
16
|
@marks_cache = nil
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def marks_dir
|
20
20
|
dir "/marks"
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
protected
|
24
|
-
def marks_cache
|
24
|
+
def marks_cache
|
25
25
|
@marks_cache ||= marks_dir.files(bang: false).collect{|file| file.name}
|
26
26
|
end
|
27
27
|
end
|
data/lib/vos/box/shell.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Vos
|
2
2
|
class Box
|
3
|
-
module Shell
|
3
|
+
module Shell
|
4
4
|
def bash cmd, *args
|
5
5
|
self['/'].bash cmd, *args
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def bash_without_path cmd, *args
|
9
9
|
check = args.shift if args.first.is_a?(Regexp)
|
10
10
|
options = args.last || {}
|
@@ -14,7 +14,7 @@ module Vos
|
|
14
14
|
|
15
15
|
unless code == 0
|
16
16
|
puts stdout_and_stderr
|
17
|
-
raise "can't execute '#{cmd}'!"
|
17
|
+
raise "can't execute '#{cmd}'!"
|
18
18
|
end
|
19
19
|
|
20
20
|
if check and (stdout_and_stderr !~ check)
|
@@ -24,18 +24,18 @@ module Vos
|
|
24
24
|
|
25
25
|
stdout_and_stderr
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def exec cmd
|
29
29
|
open{driver.exec(env(cmd))}
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
attr_writer :env
|
33
33
|
def env command_or_env_variables = nil, &block
|
34
34
|
@env ||= default_env
|
35
|
-
|
36
|
-
if block
|
35
|
+
|
36
|
+
if block
|
37
37
|
before = env.clone
|
38
|
-
begin
|
38
|
+
begin
|
39
39
|
if variables = command_or_env_variables
|
40
40
|
raise 'invalid arguments' unless variables.is_a? Hash
|
41
41
|
@env.merge! variables
|
@@ -58,26 +58,26 @@ module Vos
|
|
58
58
|
raise 'invalid arguments'
|
59
59
|
end
|
60
60
|
end
|
61
|
-
end
|
61
|
+
end
|
62
62
|
def default_env
|
63
63
|
{}
|
64
64
|
end
|
65
65
|
def wrap_cmd env_str, cmd
|
66
66
|
%(#{env_str}#{' && ' unless env_str.empty?}#{cmd})
|
67
67
|
end
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
def home path = nil
|
71
71
|
open{@home = bash('cd ~; pwd').gsub("\n", '')} unless @home
|
72
72
|
path ? self[@home][path] : self[@home]
|
73
|
-
end
|
74
|
-
|
73
|
+
end
|
74
|
+
|
75
75
|
# def generate_tmp_dir_name
|
76
76
|
# open do
|
77
77
|
# driver.generate_tmp_dir_name
|
78
78
|
# end
|
79
79
|
# end
|
80
|
-
|
80
|
+
|
81
81
|
# def inspect
|
82
82
|
# "<Box: #{options[:host]}>"
|
83
83
|
# end
|
data/lib/vos/box/vfs.rb
CHANGED
@@ -4,28 +4,28 @@ module Vos
|
|
4
4
|
def open_fs &block
|
5
5
|
open &block
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def to_entry
|
9
9
|
'/'.to_entry_on(self)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def to_file
|
13
13
|
to_entry.file
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def to_dir
|
17
17
|
to_entry.dir
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# def [] path
|
21
21
|
# to_entry[path]
|
22
22
|
# end
|
23
23
|
# alias_method :/, :[]
|
24
|
-
|
24
|
+
|
25
25
|
%w(
|
26
|
-
entry dir file
|
26
|
+
entry dir file
|
27
27
|
entries dirs files
|
28
|
-
[] /
|
28
|
+
[] /
|
29
29
|
tmp
|
30
30
|
).each do |m|
|
31
31
|
script = <<-RUBY
|
@@ -41,7 +41,7 @@ end
|
|
41
41
|
|
42
42
|
module Vfs
|
43
43
|
class Dir
|
44
|
-
def bash cmd, *args
|
44
|
+
def bash cmd, *args
|
45
45
|
storage.bash_without_path "cd #{path} && #{cmd}", *args
|
46
46
|
end
|
47
47
|
end
|
data/lib/vos/drivers/abstract.rb
CHANGED
data/lib/vos/drivers/local.rb
CHANGED
@@ -2,42 +2,42 @@ require 'vfs/storages/local'
|
|
2
2
|
|
3
3
|
module Vos
|
4
4
|
module Drivers
|
5
|
-
class Local < Abstract
|
6
|
-
#
|
5
|
+
class Local < Abstract
|
6
|
+
#
|
7
7
|
# Vfs
|
8
|
-
#
|
8
|
+
#
|
9
9
|
include Vfs::Storages::Local::LocalVfsHelper
|
10
10
|
def open &block
|
11
11
|
block.call self if block
|
12
12
|
end
|
13
13
|
alias_method :open_fs, :open
|
14
14
|
def close; end
|
15
|
-
|
16
|
-
|
17
|
-
#
|
15
|
+
|
16
|
+
|
17
|
+
#
|
18
18
|
# Shell
|
19
|
-
#
|
20
|
-
def exec command
|
21
|
-
code, stdout, stderr = Open3.popen3 command do |stdin, stdout, stderr, waitth|
|
19
|
+
#
|
20
|
+
def exec command
|
21
|
+
code, stdout, stderr = Open3.popen3 command do |stdin, stdout, stderr, waitth|
|
22
22
|
[waitth.value.to_i, stdout.read, stderr.read]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
return code, stdout, stderr
|
26
26
|
end
|
27
|
-
|
28
|
-
|
27
|
+
|
28
|
+
|
29
29
|
def bash command
|
30
|
-
code, stdout_and_stderr = Open3.popen2e command do |stdin, stdout_and_stderr, wait_thread|
|
30
|
+
code, stdout_and_stderr = Open3.popen2e command do |stdin, stdout_and_stderr, wait_thread|
|
31
31
|
[wait_thread.value.to_i, stdout_and_stderr.read]
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
return code, stdout_and_stderr
|
35
35
|
end
|
36
|
-
|
37
|
-
|
38
|
-
#
|
36
|
+
|
37
|
+
|
38
|
+
#
|
39
39
|
# Other
|
40
|
-
#
|
40
|
+
#
|
41
41
|
def to_s; '' end
|
42
42
|
def host; 'localhost' end
|
43
43
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
shared_examples_for 'vos driver' do
|
1
|
+
shared_examples_for 'vos driver' do
|
2
2
|
it 'should respond to :host' do
|
3
3
|
@driver.host.should_not be_nil
|
4
4
|
end
|
5
|
-
|
5
|
+
|
6
6
|
describe "shell" do
|
7
7
|
it 'exec' do
|
8
8
|
@driver.open do |d|
|
9
9
|
d.exec("echo 'ok'").should == [0, "ok\n", ""]
|
10
10
|
end
|
11
|
-
end
|
12
|
-
|
11
|
+
end
|
12
|
+
|
13
13
|
it 'bash' do
|
14
14
|
@driver.open do |d|
|
15
15
|
d.bash("echo 'ok'").should == [0, "ok\n"]
|
data/lib/vos/drivers/ssh.rb
CHANGED
@@ -3,31 +3,31 @@ require 'net/sftp'
|
|
3
3
|
|
4
4
|
module Vos
|
5
5
|
module Drivers
|
6
|
-
class Ssh < Abstract
|
6
|
+
class Ssh < Abstract
|
7
7
|
DEFAULT_OPTIONS = {
|
8
8
|
config: true
|
9
9
|
}
|
10
|
-
|
10
|
+
|
11
11
|
def initialize options = {}
|
12
|
-
super
|
12
|
+
super
|
13
13
|
raise ":host not provided!" unless options[:host]
|
14
14
|
@options = DEFAULT_OPTIONS.merge options
|
15
|
-
|
15
|
+
|
16
16
|
# config_options = Net::SSH.configuration_for(options[:host])
|
17
17
|
# options = DEFAULT_OPTIONS.merge(config_options).merge options
|
18
18
|
# raise ":user not provided (provide explicitly or in .ssh/config)!" unless options[:user]
|
19
19
|
end
|
20
|
-
|
21
|
-
|
22
|
-
#
|
20
|
+
|
21
|
+
|
22
|
+
#
|
23
23
|
# Establishing SSH channel
|
24
|
-
#
|
24
|
+
#
|
25
25
|
def open &block
|
26
26
|
if block
|
27
27
|
if @ssh
|
28
28
|
block.call self
|
29
29
|
else
|
30
|
-
begin
|
30
|
+
begin
|
31
31
|
open
|
32
32
|
block.call self
|
33
33
|
ensure
|
@@ -44,9 +44,9 @@ module Vos
|
|
44
44
|
@sftp = @ssh.sftp.connect
|
45
45
|
end
|
46
46
|
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def close
|
47
|
+
end
|
48
|
+
|
49
|
+
def close
|
50
50
|
if @ssh
|
51
51
|
@ssh.close
|
52
52
|
# @sftp.close not needed
|
@@ -55,16 +55,16 @@ module Vos
|
|
55
55
|
end
|
56
56
|
|
57
57
|
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# Vfs
|
60
|
-
#
|
60
|
+
#
|
61
61
|
include SshVfsStorage
|
62
62
|
alias_method :open_fs, :open
|
63
|
-
|
64
|
-
|
65
|
-
#
|
63
|
+
|
64
|
+
|
65
|
+
#
|
66
66
|
# Shell
|
67
|
-
#
|
67
|
+
#
|
68
68
|
def exec command
|
69
69
|
# somehow net-ssh doesn't executes ~/.profile, so we need to execute it manually
|
70
70
|
# command = ". ~/.profile && #{command}"
|
@@ -72,8 +72,8 @@ module Vos
|
|
72
72
|
stdout, stderr, code, signal = hacked_exec! ssh, command
|
73
73
|
|
74
74
|
return code, stdout, stderr
|
75
|
-
end
|
76
|
-
|
75
|
+
end
|
76
|
+
|
77
77
|
def bash command
|
78
78
|
# somehow net-ssh doesn't executes ~/.profile, so we need to execute it manually
|
79
79
|
# command = ". ~/.profile && #{command}"
|
@@ -81,55 +81,55 @@ module Vos
|
|
81
81
|
|
82
82
|
return code, stdout_and_stderr
|
83
83
|
end
|
84
|
-
|
85
|
-
|
86
|
-
#
|
84
|
+
|
85
|
+
|
86
|
+
#
|
87
87
|
# Miscellaneous
|
88
|
-
#
|
88
|
+
#
|
89
89
|
def to_s; options[:host] end
|
90
90
|
def host; options[:host] end
|
91
|
-
|
91
|
+
|
92
92
|
protected
|
93
93
|
attr_accessor :ssh, :sftp
|
94
|
-
|
94
|
+
|
95
95
|
def fix_path path
|
96
96
|
path.sub(/^\~/, home)
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
def home
|
100
100
|
unless @home
|
101
101
|
command = 'cd ~; pwd'
|
102
102
|
code, stdout, stderr = exec command
|
103
103
|
raise "can't execute '#{command}'!" unless code == 0
|
104
|
-
@home = stdout.gsub("\n", '')
|
104
|
+
@home = stdout.gsub("\n", '')
|
105
105
|
end
|
106
106
|
@home
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
# taken from here http://stackoverflow.com/questions/3386233/how-to-get-exit-status-with-rubys-netssh-library/3386375#3386375
|
110
110
|
def hacked_exec!(ssh, command, merge_stdout_and_stderr = false, &block)
|
111
111
|
stdout_data = ""
|
112
112
|
stderr_data = ""
|
113
113
|
exit_code = nil
|
114
114
|
exit_signal = nil
|
115
|
-
|
115
|
+
|
116
116
|
channel = ssh.open_channel do |channel|
|
117
117
|
channel.exec(command) do |ch, success|
|
118
118
|
raise "could not execute command: #{command.inspect}" unless success
|
119
119
|
|
120
120
|
channel.on_data{|ch2, data| stdout_data << data}
|
121
|
-
channel.on_extended_data do |ch2, type, data|
|
121
|
+
channel.on_extended_data do |ch2, type, data|
|
122
122
|
stdout_data << data if merge_stdout_and_stderr
|
123
123
|
stderr_data << data
|
124
124
|
end
|
125
125
|
channel.on_request("exit-status"){|ch,data| exit_code = data.read_long}
|
126
126
|
channel.on_request("exit-signal"){|ch, data| exit_signal = data.read_long}
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
channel.wait
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
channel.wait
|
131
131
|
[stdout_data, stderr_data, exit_code, exit_signal]
|
132
|
-
end
|
132
|
+
end
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
@@ -10,10 +10,10 @@ module Vos
|
|
10
10
|
@out.write data
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
14
|
-
#
|
13
|
+
|
14
|
+
#
|
15
15
|
# Attributes
|
16
|
-
#
|
16
|
+
#
|
17
17
|
def attributes path
|
18
18
|
|
19
19
|
stat = sftp.stat! fix_path(path)
|
@@ -21,22 +21,22 @@ module Vos
|
|
21
21
|
attrs[:file] = stat.file?
|
22
22
|
attrs[:dir] = stat.directory?
|
23
23
|
# stat.symlink?
|
24
|
-
|
24
|
+
|
25
25
|
# attributes special for file system
|
26
26
|
attrs[:updated_at] = stat.mtime
|
27
|
-
|
28
|
-
attrs
|
27
|
+
|
28
|
+
attrs
|
29
29
|
rescue Net::SFTP::StatusException
|
30
30
|
{}
|
31
31
|
end
|
32
32
|
|
33
|
-
def set_attributes path, attrs
|
33
|
+
def set_attributes path, attrs
|
34
34
|
raise 'not supported'
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# File
|
39
|
-
#
|
39
|
+
#
|
40
40
|
def read_file path, &block
|
41
41
|
sftp.file.open fix_path(path), 'r' do |is|
|
42
42
|
while buff = is.gets
|
@@ -45,15 +45,15 @@ module Vos
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def write_file path, append, &block
|
49
|
-
# there's no support for :append in Net::SFTP, so we just mimic it
|
50
|
-
if append
|
48
|
+
def write_file path, append, &block
|
49
|
+
# there's no support for :append in Net::SFTP, so we just mimic it
|
50
|
+
if append
|
51
51
|
attrs = attributes(path)
|
52
52
|
data = if attrs
|
53
53
|
if attrs[:file]
|
54
54
|
os = ""
|
55
55
|
read_file(path){|buff| os << buff}
|
56
|
-
delete_file path
|
56
|
+
delete_file path
|
57
57
|
os
|
58
58
|
else
|
59
59
|
raise "can't append to dir!"
|
@@ -69,8 +69,8 @@ module Vos
|
|
69
69
|
sftp.file.open fix_path(path), 'w' do |out|
|
70
70
|
block.call Writer.new(out)
|
71
71
|
end
|
72
|
-
end
|
73
|
-
end
|
72
|
+
end
|
73
|
+
end
|
74
74
|
|
75
75
|
def delete_file remote_file_path
|
76
76
|
sftp.remove! fix_path(remote_file_path)
|
@@ -81,9 +81,9 @@ module Vos
|
|
81
81
|
# end
|
82
82
|
|
83
83
|
|
84
|
-
#
|
84
|
+
#
|
85
85
|
# Dir
|
86
|
-
#
|
86
|
+
#
|
87
87
|
def create_dir path
|
88
88
|
sftp.mkdir! path
|
89
89
|
end
|
@@ -94,7 +94,7 @@ module Vos
|
|
94
94
|
|
95
95
|
def each_entry path, query, &block
|
96
96
|
raise "SshVfsStorage not support :each_entry with query!" if query
|
97
|
-
|
97
|
+
|
98
98
|
sftp.dir.foreach path do |stat|
|
99
99
|
next if stat.name == '.' or stat.name == '..'
|
100
100
|
if stat.directory?
|
@@ -104,13 +104,13 @@ module Vos
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# def efficient_dir_copy from, to, override
|
109
109
|
# return false if override # sftp doesn't support this behaviour
|
110
|
-
#
|
111
|
-
# from.storage.open_fs do |from_fs|
|
110
|
+
#
|
111
|
+
# from.storage.open_fs do |from_fs|
|
112
112
|
# to.storage.open_fs do |to_fs|
|
113
|
-
# if from_fs.local?
|
113
|
+
# if from_fs.local?
|
114
114
|
# sftp.upload! from.path, fix_path(to.path)
|
115
115
|
# true
|
116
116
|
# elsif to_fs.local?
|
@@ -123,11 +123,11 @@ module Vos
|
|
123
123
|
# end
|
124
124
|
# end
|
125
125
|
|
126
|
-
#
|
126
|
+
#
|
127
127
|
# Special
|
128
|
-
#
|
128
|
+
#
|
129
129
|
def tmp &block
|
130
|
-
tmp_dir = "/tmp/vfs_#{rand(10**3)}"
|
130
|
+
tmp_dir = "/tmp/vfs_#{rand(10**3)}"
|
131
131
|
if block
|
132
132
|
begin
|
133
133
|
create_dir tmp_dir
|
@@ -140,7 +140,7 @@ module Vos
|
|
140
140
|
tmp_dir
|
141
141
|
end
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
def local?; false end
|
145
145
|
end
|
146
146
|
end
|
data/lib/vos/helpers/ubuntu.rb
CHANGED
@@ -7,25 +7,25 @@ module Vos
|
|
7
7
|
def wrap_cmd env_str, cmd
|
8
8
|
%(source #{env_file.path} && #{env_str}#{' && ' unless env_str.empty?}#{cmd})
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def env_file
|
12
12
|
file '/etc/profile' ## file '/etc/environment'
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# def append_to_environment file, reload = true
|
16
|
-
# raise "#{file} must be an Entry" unless file.is_a? Vfs::Entry
|
17
|
-
#
|
16
|
+
# raise "#{file} must be an Entry" unless file.is_a? Vfs::Entry
|
17
|
+
#
|
18
18
|
# env_ext = dir '/etc/profile_ext'
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# remote_file = env_ext[file.name]
|
21
21
|
# file.copy_to! remote_file
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# require_clause = "source #{remote_file.path}"
|
24
24
|
# env_file.append "\n#{require_clause}\n" unless env_file.content.include? require_clause
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# reload_env if reload
|
27
27
|
# end
|
28
|
-
|
28
|
+
|
29
29
|
def reload_env
|
30
30
|
bash ". #{env_file.path}"
|
31
31
|
end
|
@@ -41,32 +41,32 @@ module Vfs
|
|
41
41
|
raise "symlink target '' not exist!" unless entry.exist?
|
42
42
|
storage.bash "ln -s#{'f' if options[:override]} #{entry.path} #{path}"
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def symlink_to! entry
|
46
46
|
symlink_to entry, override: true
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
class Dir
|
51
51
|
def rsync_to entry
|
52
|
-
raise "invalid argument!" unless entry.is_a? Entry
|
52
|
+
raise "invalid argument!" unless entry.is_a? Entry
|
53
53
|
raise "#{path} must be a Dir" unless dir?
|
54
54
|
raise "#{entry.path} can't be a File!" if entry.file?
|
55
|
-
|
55
|
+
|
56
56
|
if local? and !entry.local?
|
57
57
|
Box.local.bash("rsync -e 'ssh' -al --delete --stats --progress #{path}/ root@#{entry.storage.host}:#{entry.path}")
|
58
|
-
elsif entry.local? and !local?
|
58
|
+
elsif entry.local? and !local?
|
59
59
|
Box.local.bash("rsync -e 'ssh' -al --delete --stats --progress root@#{storage.host}:#{path}/ #{entry.path}")
|
60
60
|
else
|
61
61
|
raise "invalid usage!"
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
class File
|
67
67
|
def append_to_environment_of box, reload = true
|
68
|
-
raise "#{box} must be an Vos::Box" unless box.is_a? Vos::Box
|
69
|
-
|
68
|
+
raise "#{box} must be an Vos::Box" unless box.is_a? Vos::Box
|
69
|
+
|
70
70
|
remote_file = box.dir('/etc/profile_ext').file(name)
|
71
71
|
copy_to! remote_file
|
72
72
|
|
@@ -75,9 +75,9 @@ module Vfs
|
|
75
75
|
# #{name}
|
76
76
|
source #{remote_file.path}
|
77
77
|
BASH
|
78
|
-
|
78
|
+
|
79
79
|
box.env_file.append require_clause unless box.env_file.content.include? require_clause
|
80
|
-
|
80
|
+
|
81
81
|
box.reload_env if reload
|
82
82
|
end
|
83
83
|
end
|
data/lib/vos/support.rb
CHANGED
@@ -13,25 +13,25 @@ end
|
|
13
13
|
|
14
14
|
# class File
|
15
15
|
# class << self
|
16
|
-
# def ensure_dir_exist directory, options = {}
|
17
|
-
# options = options.symbolize_keys
|
16
|
+
# def ensure_dir_exist directory, options = {}
|
17
|
+
# options = options.symbolize_keys
|
18
18
|
# clean = options.delete :clean
|
19
19
|
# raise "unsupported options #{options.keys}!" unless options.empty?
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# FileUtils.rm_r directory, force: true if clean and File.exist?(directory)
|
22
22
|
# FileUtils.mkdir_p directory
|
23
23
|
# end
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# def copy_dir_content from, to
|
26
26
|
# Dir.glob "#{from}/*" do |item|
|
27
27
|
# FileUtils.cp_r item, to
|
28
28
|
# end
|
29
29
|
# end
|
30
|
-
#
|
30
|
+
#
|
31
31
|
# def copy_dir from, to
|
32
32
|
# FileUtils.cp_r from, to
|
33
33
|
# end
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# def delete_dir dir
|
36
36
|
# FileUtils.rm_r dir
|
37
37
|
# end
|
data/readme.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Vos - Virtual Operating System
|
2
2
|
|
3
|
-
Small abstraction over Operating System, mainly it should be used in conjunction with [Virtual File System][vfs] tool. Kind of
|
3
|
+
Small abstraction over Operating System, mainly it should be used in conjunction with [Virtual File System][vfs] tool. Kind of
|
4
4
|
Capistrano but without extra stuff and more universal, not forcing You to follow 'The Rails Way'.
|
5
5
|
|
6
6
|
Currently, there are following implementations available:
|
@@ -26,10 +26,14 @@ server.bash 'ls' # ls /
|
|
26
26
|
server['apps/cool_app'].bash 'rails production' # cd /apps/cool_app && rails production
|
27
27
|
```
|
28
28
|
|
29
|
-
For more details look also to [Virtual File System][vfs] project.
|
30
|
-
Or checkout configuration I use to control my production servers [My Cluster][my_cluster] in conjunction with small
|
29
|
+
For more details look also to [Virtual File System][vfs] project.
|
30
|
+
Or checkout configuration I use to control my production servers [My Cluster][my_cluster] in conjunction with small
|
31
31
|
configuration tool [Cluster Management][cluster_management].
|
32
|
-
|
32
|
+
|
33
|
+
## Please let me know about bugs and Your proposals, there's the 'Issues' tab at the top, feel free to submit.
|
34
|
+
|
35
|
+
Copyright (c) Alexey Petrushin http://petrush.in, released under the MIT license.
|
36
|
+
|
33
37
|
[vfs]: http://github.com/alexeypetrushin/vfs
|
34
38
|
[cluster_management]: http://github.com/alexeypetrushin/cluster_management
|
35
39
|
[my_cluster]: http://github.com/alexeypetrushin/my_cluster
|
data/spec/box_spec.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Vos::Box do
|
3
|
+
describe Vos::Box do
|
4
4
|
before do
|
5
5
|
@box = Vos::Box.new
|
6
6
|
@box.stub :puts
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe 'vfs integration' do
|
10
10
|
it 'smoke test' do
|
11
|
-
@box['/'].exist?.should be_true
|
11
|
+
@box['/'].exist?.should be_true
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it 'vfs integration' do
|
15
15
|
@box['/'].bash("echo 'ok'").should == "ok\n"
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
describe "shell" do
|
20
20
|
it 'bash' do
|
21
21
|
@box.bash("echo 'ok'").should == "ok\n"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it 'bash working dir should be /' do
|
25
25
|
@box.bash('pwd').should == "/\n"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it 'check with regex' do
|
29
29
|
@box.bash "echo 'ok'", /ok/
|
30
30
|
-> {@box.bash "echo 'ok'", /no/}.should raise_error(/not match/)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "exec" do
|
34
34
|
@box.exec("echo 'ok'").should == [0, "ok\n", ""]
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it 'home' do
|
38
38
|
@box.home.should_not be_nil
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it 'env' do
|
42
42
|
@box.env.should == {}
|
43
43
|
@box.env = {a: 'b'}
|
44
|
-
|
44
|
+
|
45
45
|
@box.env c: 'd' do
|
46
46
|
@box.env.should == {a: 'b', c: 'd'}
|
47
47
|
end
|
48
48
|
@box.env.should == {a: 'b'}
|
49
|
-
|
49
|
+
|
50
50
|
@box.env(c: 'd')
|
51
51
|
@box.env.should == {a: 'b', c: 'd'}
|
52
|
-
|
52
|
+
|
53
53
|
@box.env('ls').should == "a=b c=d && ls"
|
54
54
|
end
|
55
55
|
end
|
data/spec/config.example.yml
CHANGED
data/spec/drivers/local_spec.rb
CHANGED
data/spec/drivers/ssh_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'drivers/spec_helper'
|
2
2
|
|
3
3
|
describe Vos::Drivers::Ssh do
|
4
|
-
it_should_behave_like "vos driver"
|
4
|
+
it_should_behave_like "vos driver"
|
5
5
|
it_should_behave_like "vfs storage"
|
6
6
|
|
7
7
|
before :all do
|
8
8
|
@storage = @driver = Vos::Drivers::Ssh.new(config[:ssh_driver])
|
9
9
|
@driver.open
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
after :all do
|
13
13
|
@driver.close
|
14
|
-
end
|
14
|
+
end
|
15
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-08-10 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
16
|
-
requirement: &
|
16
|
+
requirement: &363240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *363240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: net-sftp
|
27
|
-
requirement: &
|
27
|
+
requirement: &640270 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *640270
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: vfs
|
38
|
-
requirement: &
|
38
|
+
requirement: &738060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *738060
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
executables: []
|