commutateurs 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f8b3f8a708ba9954596932659d2a92045aa92cf
4
- data.tar.gz: 796be42b15b763d9872c700c038b3652c102d20b
3
+ metadata.gz: a2ffce63f0f44087e1a319c8e68217261132bb37
4
+ data.tar.gz: 8384ac86ce8683ece9d7008b29860967792309d2
5
5
  SHA512:
6
- metadata.gz: 016b0409906947accbabfe981f22dc444de0cd9133178d34500f3ff8fd11f03f84866f6b1cc22b55e672b56f18252110d8fa899f39d23e988c0fd5b6842b27f3
7
- data.tar.gz: 5d5463fb8daf2f0b2f8f0b3ebe751381db6fb4942d1b56b8237e20ddf46a71ca0f4d6f4d87b6ab2a1271e01277fb272d445e224685860d51acf96cec49d22ef1
6
+ metadata.gz: 6858c1e589ccba063f67d37d5582967ce802ab74dd64aa1670ae82268e0c46bbe2670d5c7a34e4caa67972a2209107fe6b341493249b80b0a41eef10a65fbcba
7
+ data.tar.gz: 88b24ae71009ce16c857da63130ac4b16a67894a3669417323f99d0a54beb83d1bdb3d8f50900bcdb591365087cd8ae18da16a6e56cc94166572cec288dc6e08
@@ -23,6 +23,37 @@ module Commutateurs
23
23
  end
24
24
  end
25
25
 
26
+ class HP < Base
27
+ def initialize(host, credentials, verbose = false)
28
+ super
29
+ @transport.default_prompt = /(Press any key to continue|# )/
30
+ @transport.debug = Proc.new { |line| $stderr.print(Commutateurs.clean(line)) }
31
+ end
32
+
33
+ def connect
34
+ @transport.connect
35
+ @transport.command("\n")
36
+ @transport.command("terminal length 1000")
37
+ end
38
+
39
+ def configuration
40
+ execute('write term')
41
+ end
42
+
43
+ def save
44
+ raise "Not implemented yet"
45
+ end
46
+
47
+ def disconnect
48
+ @transport.send 'exit'
49
+ @transport.close
50
+ end
51
+
52
+ def execute(arg)
53
+ Commutateurs.clean(super(arg))
54
+ end
55
+ end
56
+
26
57
  class Cisco < Base
27
58
  def initialize(host, credentials, verbose = false)
28
59
  super
@@ -108,4 +139,10 @@ module Commutateurs
108
139
  @transport.close
109
140
  end
110
141
  end
142
+
143
+ def clean(arg)
144
+ cleaned = ""
145
+ (arg || "").each_byte { |x| cleaned << x unless x > 127 }
146
+ cleaned
147
+ end
111
148
  end
@@ -3,11 +3,12 @@
3
3
  module Commutateurs
4
4
  class Ssh
5
5
  attr_accessor :user, :password, :host, :port
6
- attr_accessor :default_prompt, :timeout
6
+ attr_accessor :default_prompt, :timeout, :debug
7
7
 
8
8
  def initialize(verbose)
9
9
  @timeout = 10
10
10
  @verbose = verbose
11
+ @debug = Proc.new { |line| $stderr.print(line) }
11
12
  end
12
13
 
13
14
  def command(cmd, options = {})
@@ -33,10 +34,11 @@ module Commutateurs
33
34
  raise "failed to open ssh shell channel" unless success
34
35
 
35
36
  ch.on_data { |ch,data|
36
- $stderr.print data if @verbose
37
+ # p data
38
+ @debug.call(data) if @verbose
37
39
  @buf << data
38
40
  }
39
- ch.on_extended_data { |ch,type,data| $stderr.print data if type == 1; @buf << data if type == 1 }
41
+ ch.on_extended_data { |ch,type,data| @debug.call(data) if type == 1; @buf << data if type == 1 }
40
42
  ch.on_close { @eof = true }
41
43
 
42
44
  @channel = ch
@@ -62,6 +64,8 @@ module Commutateurs
62
64
  sock = @ssh.transport.socket
63
65
 
64
66
  while not @eof
67
+ # p prompt
68
+ # p line
65
69
  break if line =~ prompt and @buf == ''
66
70
  break if sock.closed?
67
71
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commutateurs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Rose