conn 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/conn/dsl.rb +22 -6
- data/lib/conn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e697aab8b46137d969752cbb5b8b7757aa6b7ff
|
4
|
+
data.tar.gz: c8e6841c7f1495110de6f40c23dfa6828e862134
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 219bf093cadabd36f006a09a8631797302378d2f74dae9e7e1278e6ed3de739379e17a62552f1b556abec8c95e6003ce3834adbc9b491f4598adc56ebea46f69
|
7
|
+
data.tar.gz: f71f33a9da416deb6cf671487f3ebc91c8ac90cd5e685532db35725885dc6813a996a2c54066f27111c8ec4c5f00bf050baf93aa236a2862fda31fb62bc16f66
|
data/lib/conn/dsl.rb
CHANGED
@@ -8,14 +8,12 @@ require 'conn/pty_ssh'
|
|
8
8
|
module Conn
|
9
9
|
module DSL
|
10
10
|
def ssh(hostname, &blk)
|
11
|
-
config = Net::SSH::Config.for(hostname)
|
12
|
-
user = config[:user] || Etc.getlogin
|
13
11
|
queue = Queue.new
|
14
12
|
cmd_loop = Thread.new do
|
15
13
|
blk.call(queue)
|
16
14
|
queue.respond_to?(:close) ? queue.close : (queue << false)
|
17
15
|
end
|
18
|
-
Net::SSH.start(hostname
|
16
|
+
Net::SSH.start(*to_ssh_config(hostname)) do |ssh|
|
19
17
|
ssh.loop do
|
20
18
|
msg = queue.pop
|
21
19
|
if msg
|
@@ -36,6 +34,25 @@ module Conn
|
|
36
34
|
cmd_loop.join if cmd_loop.alive?
|
37
35
|
end
|
38
36
|
|
37
|
+
def ssh_try!(hostname)
|
38
|
+
Net::SSH.start(*to_ssh_config(hostname, timeout: 3)) do |ssh|
|
39
|
+
ssh.exec! 'uptime'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def ssh_try(hostname)
|
44
|
+
ssh_try!(hostname)
|
45
|
+
rescue => e
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def to_ssh_config(hostname, **opts)
|
51
|
+
config = Net::SSH::Config.for(hostname).merge(opts)
|
52
|
+
user = config[:user] || Etc.getlogin
|
53
|
+
[hostname, user, config]
|
54
|
+
end
|
55
|
+
|
39
56
|
def input(str)
|
40
57
|
puts "%s %s" % ["SSH<<".green.bold, str.yellow]
|
41
58
|
end
|
@@ -48,16 +65,15 @@ module Conn
|
|
48
65
|
puts "%s %s" % ["SSH!>".red.bold, str.red]
|
49
66
|
end
|
50
67
|
|
68
|
+
public
|
51
69
|
using Conn::PtySSH
|
52
70
|
def ssh_pty(hostname, &blk)
|
53
|
-
config = Net::SSH::Config.for(hostname)
|
54
|
-
user = config[:user] || Etc.getlogin
|
55
71
|
queue = Queue.new
|
56
72
|
cmd_loop = Thread.new do
|
57
73
|
blk.call(queue)
|
58
74
|
queue.respond_to?(:close) ? queue.close : (queue << false)
|
59
75
|
end
|
60
|
-
Net::SSH.start(hostname
|
76
|
+
Net::SSH.start(*to_ssh_config(hostname)) do |ssh|
|
61
77
|
ssh.loop do
|
62
78
|
msg = queue.pop
|
63
79
|
if msg
|
data/lib/conn/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio KONDO
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.2.
|
110
|
+
rubygems_version: 2.2.3
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Super simple server connector
|