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

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

Class Method Summary collapse

Class Method Details

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

TODO: Generalize me!



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puppet/util/network_device/cisco_ios/model/interface/base.rb', line 7

def self.ifprop(base, param, base_command = param, &block)
  base.register_scoped param, /^(interface\s+(\S+).*?)^!/m do
    cmd 'sh run'
    match /^\s*#{base_command}\s+(.*?)\s*$/
    after :description
    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



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/puppet/util/network_device/cisco_ios/model/interface/base.rb', line 24

def self.register(base)
  ifprop(base, :description)
  ifprop(base, :mode, "switchport mode")
  ifprop(base, :access, "switchport access vlan") do
    after :mode
  end
  ifprop(base, :trunk_allowed_vlan, "switchport trunk allowed vlan") do
    after :mode
  end
  ifprop(base, :trunk_encapsulation, "switchport trunk encapsulation") do
    before :mode
  end
  ifprop(base, :trunk_native_vlan, "switchport trunk native vlan") do
    after :mode
  end
  ifprop(base, :negotiate) do
    match do |txt|
      !!(txt.match(/^\s*switchport nonegotiate\s*$/)) ? :false : :true # http://projects.puppetlabs.com/issues/17519
    end
    after :mode
    add do |transport, value|
      if value == :false
        transport.command("switchport nonegotiate")
      else
        transport.command("no switchport nonegotiate")
      end
    end
    # This is just a dummy
    remove {|*_| }
  end

  ifprop(base, :port_security, "switchport port-security") do
    match do |txt|
      port_sec = txt.match(/^\s*switchport port-security\s*$/)
      violation = txt.scan(/^\s*switchport port-security violation\s+(.*?)\s*$/).flatten.first
      if port_sec and violation
        violation
        # this is here so we can make sure that leftovers are removed
      elsif !port_sec and violation
        violation
      end
    end
    after :mode
    add do |transport, value|
      transport.command("switchport port-security")
      transport.command("switchport port-security violation #{value}")
    end
    remove do |transport, old_value|
      transport.command("no switchport port-security")
      transport.command("no switchport port-security violation #{old_value}")
    end
  end

  ifprop(base, :port_security_mac_address, "switchport port-security mac-address") do
    after :port_security
  end
  ifprop(base, :port_security_aging_time, "switchport port-security aging time") do
    after :port_security
  end
  ifprop(base, :port_security_aging_type, "switchport port-security aging type") do
    after :port_security
  end

  ifprop(base, :spanning_tree) do
    match do |txt|
      txt.match(/^\s*spanning-tree portfast\s*$/) ? :leaf : :node
    end
    after :mode
    add do |transport, value|
      if value == :leaf
        transport.command("spanning-tree portfast")
      end
    end
    remove do |transport, old_value|
      if old_value == :leaf
        transport.command("spanning-tree portfast disable")
      end
    end
  end

  ifprop(base, :spanning_tree_bpduguard) do
    match do |txt|
      txt.match(/^\s*spanning-tree bpduguard enable\s*$/) ? :present : :absent
    end
    after :spanning_tree
    add do |transport, _|
      transport.command("spanning-tree bpduguard enable")
    end
    remove do |transport, _|
      transport.command("spanning-tree bpduguard disable")
    end
  end

  ifprop(base, :spanning_tree_guard, "spanning-tree guard") do
    after :spanning_tree
  end
  ifprop(base, :spanning_tree_cost, "spanning-tree cost") do
    after :spanning_tree
  end
  ifprop(base, :spanning_tree_port_priority, "spanning-tree port-priority") do
    after :spanning_tree
  end
  ifprop(base, :dhcp_snooping_limit_rate, "ip dhcp snooping limit rate")
  ifprop(base, :dhcp_snooping_trust) do
    match do |txt|
      txt.match(/^\s*ip dhcp snooping trust\s*$/) ? :present : :absent
    end
    add do |transport, _|
      transport.command("ip dhcp snooping trust")
    end
    remove do |transport, _|
      transport.command("no ip dhcp snooping trust")
    end
  end

  if base.facts && base.facts['canonicalized_hardwaremodel'] == 'c4500'
    base.register_new_module('c4500', 'hardware')
  end

  if base.facts && base.facts['canonicalized_hardwaremodel'] == 'c2960'
    base.register_new_module('c2960', 'hardware')
  end
end