octosh 0.0.7 → 0.0.8
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/README.md +20 -0
- data/lib/octosh/helper.rb +2 -11
- data/lib/octosh/shell.rb +41 -7
- data/lib/octosh/version.rb +1 -1
- data/lib/octosh/worker/worker.rb +14 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -44,6 +44,26 @@ Instead of inline scripting, you can also pass a path to a script to run on each
|
|
44
44
|
|
45
45
|
```octosh -s /path/to/script -u someuser -p -r 192.168.0.100,192.168.0.101,192.168.0.102```
|
46
46
|
|
47
|
+
There's also...
|
48
|
+
|
49
|
+
|
50
|
+
INTERACTIVE MODE
|
51
|
+
----------------
|
52
|
+
|
53
|
+
Interactive mode can be activate with the `-i` flag, for example...
|
54
|
+
|
55
|
+
```octosh -i -u someuser -p -r 192.168.0.100,192.168.0.101,192.168.0.102```
|
56
|
+
|
57
|
+
You will be prompted for the password(s), and then be greeted by the Octoshell prompt. From here, you can operate as normal as you would on a single server, but all commands will be ran on all servers, color-coded per server.
|
58
|
+
|
59
|
+
There are a few special commands however (IN PROGRESS)…
|
60
|
+
|
61
|
+
* `put PATH` -- Upload file at PATH to the CWD on the remote hosts
|
62
|
+
* `get FILE` -- Download FILE to the CWD on the local machine. Files will be stored in the format "FILENAME-HOST.EXT"
|
63
|
+
* `exit` -- Cleanly close the conneciton to all servers and quit OSH
|
64
|
+
|
65
|
+
|
66
|
+
|
47
67
|
|
48
68
|
ROADMAP
|
49
69
|
-------
|
data/lib/octosh/helper.rb
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
module Octosh
|
2
|
-
|
3
|
-
module OUTPUT_COLORS
|
4
|
-
RED = 31
|
5
|
-
GREEN = 32
|
6
|
-
YELLOW = 33
|
7
|
-
BLUE = 34
|
8
|
-
MAGENTA = 35
|
9
|
-
CYAN = 36
|
10
|
-
end
|
11
|
-
|
2
|
+
|
12
3
|
module COLORS
|
13
|
-
COLORS = [
|
4
|
+
COLORS = [:default, :blue, :green, :yellow, :red, :magenta, :cyan, :white, :light_black, :light_red, :light_green, :light_yellow, :light_blue, :light_magenta, :light_cyan]
|
14
5
|
end
|
15
6
|
|
16
7
|
class Helper
|
data/lib/octosh/shell.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
1
3
|
module Octosh
|
4
|
+
|
5
|
+
module Commands
|
6
|
+
GET = :get
|
7
|
+
PUT = :put
|
8
|
+
EXIT = :exit
|
9
|
+
end
|
10
|
+
|
2
11
|
class Shell
|
3
|
-
|
12
|
+
|
4
13
|
@workers = []
|
5
14
|
@password = nil
|
6
15
|
|
@@ -26,10 +35,6 @@ module Octosh
|
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
29
|
-
def colorize(text, color_code)
|
30
|
-
"\e[#{color_code}m#{text}\e[0m"
|
31
|
-
end
|
32
|
-
|
33
38
|
def prompt_for_password(password_prompt, uniform_password, host="current host")
|
34
39
|
if password_prompt
|
35
40
|
# Password authentication
|
@@ -44,13 +49,42 @@ module Octosh
|
|
44
49
|
end
|
45
50
|
|
46
51
|
def start
|
52
|
+
|
53
|
+
puts "Starting Octoshell connected to #{@workers.length} hosts"
|
54
|
+
@workers.each do |worker|
|
55
|
+
puts worker.host.colorize(worker.options[:color].to_sym)
|
56
|
+
end
|
57
|
+
|
47
58
|
while true
|
48
59
|
print ">> "
|
49
|
-
command =
|
60
|
+
command = ""
|
61
|
+
begin
|
62
|
+
command = gets.chomp!
|
63
|
+
rescue Interrupt
|
64
|
+
disconnect
|
65
|
+
exit
|
66
|
+
end
|
67
|
+
preprocess_command(command || "")
|
50
68
|
Parallel.each(@workers, :in_threads => @workers.length) do |worker|
|
51
|
-
|
69
|
+
output = worker.exec(command) || ""
|
70
|
+
print output.colorize(worker.options[:color].to_sym)
|
52
71
|
end
|
53
72
|
end
|
54
73
|
end
|
74
|
+
|
75
|
+
def preprocess_command(command)
|
76
|
+
if command.downcase == "exit"
|
77
|
+
disconnect
|
78
|
+
exit
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def disconnect
|
83
|
+
@workers.each do |worker|
|
84
|
+
print "Closing connection to #{worker.host} . . . ".colorize(worker.options[:color].to_sym)
|
85
|
+
worker.disconnect
|
86
|
+
puts "OK".colorize(worker.options[:color].to_sym)
|
87
|
+
end
|
88
|
+
end
|
55
89
|
end
|
56
90
|
end
|
data/lib/octosh/version.rb
CHANGED
data/lib/octosh/worker/worker.rb
CHANGED
@@ -32,7 +32,21 @@ module Octosh
|
|
32
32
|
forward_agent = @options[:forward_agent] || false
|
33
33
|
@ssh = Net::SSH.start(@host, @user, :password => @password, :forward_agent => forward_agent)
|
34
34
|
@connected = true
|
35
|
+
return true
|
35
36
|
end
|
37
|
+
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
|
41
|
+
def disconnect
|
42
|
+
if connected?
|
43
|
+
@ssh.close
|
44
|
+
@ssh = nil
|
45
|
+
@connected = false
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
|
49
|
+
return false
|
36
50
|
end
|
37
51
|
|
38
52
|
def exec(command)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octosh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,7 +50,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
50
|
version: '0'
|
51
51
|
segments:
|
52
52
|
- 0
|
53
|
-
hash:
|
53
|
+
hash: 3656941387445534681
|
54
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|