Module: Puppet::Util::NetworkDevice::Cisco_ios::Model::Line::Base

Defined in:
lib/puppet/util/network_device/cisco_ios/model/line/base.rb

Class Method Summary collapse

Class Method Details

.lineprop(base, param, base_command = param, &block) ⇒ Object



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
# File 'lib/puppet/util/network_device/cisco_ios/model/line/base.rb', line 6

def self.lineprop(base, param, base_command = param, &block)
  base.register_scoped param, /^(line\s+((?:con|vty)\s+\d+(?:\s+\d+)?)\s*\n(?:\s[^\n]*\n)*)/ do
    cmd 'sh run'
    match /^\s*#{base_command}\s+(.*)$/
    scope_match do |scope, scope_name|
      matches = scope_name.match /(con|vty)\s+(\d+)(?:\s+(\d+))?/
      return unless matches
      type = matches[1]
      from = matches[2].to_i
      if matches[3].nil?
        # single number
        [ [scope, "#{type} #{from}"] ]
      else
        # range
        to = matches[3].to_i
        (from..to).collect { |vty| [scope, "#{type} #{vty}"] }
      end
    end
    add do |transport, value|
      transport.command("#{base_command} #{value}")
    end
    remove do |transport, old_value|
      transport.command("no #{base_command} #{old_value}")
    end
    # Pass the Block to a Helper Method so we are in the right
    # Scope when evaluating the block
    evaluate(&block) if block
  end
end

.register(base) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puppet/util/network_device/cisco_ios/model/line/base.rb', line 36

def self.register(base)
  lineprop(base, :access_class, 'access-class') do
    match /^\s*access-class\s+(.*)$/
  end

  lineprop(base, :logging) do
    match /^\s*logging\s+(.*)$/
  end

  lineprop(base, :exec_timeout) do
    match do |txt|
      matches = /^\s*exec-timeout\s+(\d+)\s+(\d+).*$/.match txt
      if matches
        matches[1].to_i * 60 + matches[2].to_i
      else
        600 # ios doesn't show the config if it has this value
      end
    end

    add do |transport,value|
      secs = value.to_i % 60
      mins = (value.to_i - secs) / 60
      transport.command("exec-timeout #{mins} #{secs}")
    end
    remove do |transport,old_value|
      transport.command("no exec-timeout")
    end
  end

  lineprop(base, :transport, 'transport input') do
    match /^\s*transport\s+input\s+(all|none|ssh|telnet)$/
    remove { |*_| }
  end
end