summaryrefslogtreecommitdiff
path: root/lib/oxidized/model/junos.rb
blob: 737a0009b1eec4947877ba4be0e9d1667ca5741f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class JunOS < Oxidized::Model
  comment '# '

  def telnet
    @input.class.to_s.match(/Telnet/)
  end

  cmd :all do |cfg|
    cfg = cfg.lines.to_a[1..-2].join if screenscrape
    cfg.gsub!(/  scale-subscriber (\s+)(\d+)/, '  scale-subscriber                <count>')
    cfg.lines.map { |line| line.rstrip }.join("\n") + "\n"
  end

  cmd :secret do |cfg|
    cfg.gsub!(/encrypted-password (\S+).*/, 'encrypted-password <secret removed>')
    cfg.gsub!(/pre-shared-key ascii-text (\S+).*/, 'pre-shared-key ascii-text <secret removed>')
    cfg.gsub!(/pre-shared-key hexadecimal (\S+).*/, 'pre-shared-key hexadecimal <secret removed>')
    cfg.gsub!(/authentication-key (\S+).*/, 'authentication-key <secret removed>')
    cfg.gsub!(/community (\S+) {/, 'community <hidden> {')
    cfg
  end

  cmd 'show configuration | display omit'

  cmd 'show version' do |cfg|
    @model = $1 if cfg.match(/^Model: (\S+)/)
    comment cfg
  end

  post do
    out = ''
    case @model
    when 'mx960'
      out << cmd('show chassis fabric reachability') { |cfg| comment cfg }
    when /^(ex22|ex33|ex4|ex8|qfx)/
      out << cmd('show virtual-chassis') { |cfg| comment cfg }
    end
    out
  end

  cmd('show chassis hardware') { |cfg| comment cfg }
  cmd('show system license') { |cfg| comment cfg }
  cmd('show system license keys') { |cfg| comment cfg }

  cfg :telnet do
    username(/^login:/)
    password(/^Password:/)
  end

  cfg :ssh do
    exec true # don't run shell, run each command in exec channel
  end

  cfg :telnet, :ssh do
    post_login 'set cli screen-length 0'
    post_login 'set cli screen-width 0'
    pre_logout 'exit'
  end
end