Class: Puppet::Util::NetworkDevice::Cisco_ios::Model::Acl

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet/util/network_device/cisco_ios/model/acl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, facts, options) ⇒ Acl

Returns a new instance of Acl.



10
11
12
13
14
15
16
17
18
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 10

def initialize(transport, facts, options)
  super(transport, facts)
  # Initialize some defaults
  @params         ||= {}
  @name           = options[:name] if options.key? :name

  # Register all needed Modules based on the availiable Facts
  register_modules
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 8

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 8

def params
  @params
end

Instance Method Details

#mod_const_baseObject



24
25
26
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 24

def mod_const_base
  return Puppet::Util::NetworkDevice::Cisco_ios::Model::Acl
end

#mod_path_baseObject



20
21
22
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 20

def mod_path_base
  return 'puppet/util/network_device/cisco_ios/model/acl'
end

#param_classObject



28
29
30
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 28

def param_class
  return Puppet::Util::NetworkDevice::Cisco_ios::Model::ScopedValue
end

#register_modulesObject



73
74
75
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 73

def register_modules
  register_new_module(:base)
end

#remove_acl(is) ⇒ Object



69
70
71
# File 'lib/puppet/util/network_device/cisco_ios/model/acl.rb', line 69

def remove_acl(is)
  transport.command("no ip access-list #{is[:type]} #{is[:name]}")
end

#update(is = {}, should = {}) ⇒ Object

Raises:

  • (Puppet::Error)


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

def update(is = {}, should = {})
  return unless configuration_changed?(is, should)

  should_present = should[:ensure] == :present
  is.delete(:ensure)
  should.delete(:ensure)

  missing_commands = [is.keys, should.keys].flatten.uniq.sort - @params.keys.flatten.uniq.sort
  missing_commands.delete(:name)

  raise Puppet::Error, "Undefined commands for #{missing_commands.join(', ')}" unless missing_commands.empty?

  [is.keys, should.keys].flatten.uniq.sort.each do |property|
    next if property == :ensure || property == :name
    next if should[property] == :undef
    if should[property] == :absent || should[property].nil? then
      @params[property].value = :absent
    else
      @params[property].value = should[property]
    end
  end

  before_update
  if should_present then
    transport.command("ip access-list standard #{@name}", :prompt => /\(config-std-nacl\)#\z/n)
    Puppet::Util::NetworkDevice::Sorter.new(@params).tsort.each do |param|
      # We dont want to change undefined values
      next if should[param.name] == :undef || should[param.name].nil?
      param.update(@transport, is[param.name]) unless is[param.name] == should[param.name]
    end
    transport.command("exit")
  else
    remove_acl(is)
  end
  after_update
end