commutateurs 0.0.4 → 0.0.6
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.
- checksums.yaml +4 -4
 - data/lib/commutateurs/device.rb +37 -0
 - data/lib/commutateurs/ssh.rb +7 -3
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a2ffce63f0f44087e1a319c8e68217261132bb37
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8384ac86ce8683ece9d7008b29860967792309d2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6858c1e589ccba063f67d37d5582967ce802ab74dd64aa1670ae82268e0c46bbe2670d5c7a34e4caa67972a2209107fe6b341493249b80b0a41eef10a65fbcba
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 88b24ae71009ce16c857da63130ac4b16a67894a3669417323f99d0a54beb83d1bdb3d8f50900bcdb591365087cd8ae18da16a6e56cc94166572cec288dc6e08
         
     | 
    
        data/lib/commutateurs/device.rb
    CHANGED
    
    | 
         @@ -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
         
     | 
    
        data/lib/commutateurs/ssh.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                         
     | 
| 
      
 37 
     | 
    
         
            +
                        # p data
         
     | 
| 
      
 38 
     | 
    
         
            +
                        @debug.call(data) if @verbose
         
     | 
| 
       37 
39 
     | 
    
         
             
                        @buf << data
         
     | 
| 
       38 
40 
     | 
    
         
             
                      }
         
     | 
| 
       39 
     | 
    
         
            -
                      ch.on_extended_data { |ch,type,data|  
     | 
| 
      
 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 
     | 
    
         |