Class: Puppet::Util::NetworkDevice::Cisco_ios::Model::Snmp_community

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, facts, options) ⇒ Snmp_community

Returns a new instance of Snmp_community.



12
13
14
15
16
17
18
19
20
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 12

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

#base_cmdObject

Returns the value of attribute base_cmd.



10
11
12
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 10

def base_cmd
  @base_cmd
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#get_base_cmdObject

Raises:

  • (ArgumentError)


46
47
48
49
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 46

def get_base_cmd
  raise ArgumentError, "Base Command not set for #{self.class}" if base_cmd.nil?
  ERB.new(base_cmd).result(binding)
end

#mod_const_baseObject



55
56
57
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 55

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

#mod_path_baseObject



51
52
53
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 51

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

#param_classObject



59
60
61
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 59

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

#register_modulesObject



63
64
65
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 63

def register_modules
  register_new_module(:base)
end

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

Since we have to construct a single string of our Options override update here to implent the needed custom logic TODO: Extract the Common behaviour into seperated Methods that can be overloaded so we dont have all that duplication

Raises:

  • (Puppet::Error)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/puppet/util/network_device/cisco_ios/model/snmp_community.rb', line 26

def update(is = {}, should = {})
  # Delete the Property here since we cant really compare params in a propertys validate block
  # Puppet Magic...
  should.delete(:acl_type)
  return unless configuration_changed?(is, should, :keep_ensure => true)
  missing_commands = [is.keys, should.keys].flatten.uniq.sort - @params.keys.flatten.uniq.sort
  missing_commands.delete(:ensure)
  missing_commands.delete(:acl_type)
  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 == :acl_type
    next if should[property] == :undef
    @params[property].value = :absent if should[property] == :absent || should[property].nil?
    @params[property].value = should[property] unless should[property] == :absent || should[property].nil?
  end
  before_update
  perform_update
  after_update
end