Class: Puppet::Util::NetworkDevice::Cisco_ios::Model::Aaa_group

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, facts, options) ⇒ Aaa_group

Returns a new instance of Aaa_group.



10
11
12
13
14
15
16
17
18
# File 'lib/puppet/util/network_device/cisco_ios/model/aaa_group.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/aaa_group.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/aaa_group.rb', line 8

def params
  @params
end

Instance Method Details

#construct_server_cmdObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/puppet/util/network_device/cisco_ios/model/aaa_group.rb', line 68

def construct_server_cmd
  p = {
    :server => @params[:server],
    :acct_port => @params[:acct_port],
    :auth_port => @params[:auth_port],
  }
  Puppet::Util::NetworkDevice::Sorter \
    .new(p) \
    .tsort \
    .collect { |p| p.get_fragment if p.fragment and p.value and p.supported? } \
    .reject { |f| f.nil? } \
    .join " "
end

#mod_const_baseObject



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

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

#mod_path_baseObject



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

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

#param_classObject



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

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

#register_modulesObject



32
33
34
# File 'lib/puppet/util/network_device/cisco_ios/model/aaa_group.rb', line 32

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



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

def update(is = {}, should = {})
  return unless configuration_changed?(is, should)
  before_update
  if should[:ensure] == :present
    missing_commands = [is.keys, should.keys].flatten.uniq.sort - @params.keys.flatten.uniq.sort
    missing_commands.delete(:name)
    missing_commands.delete(:protocol)
    missing_commands.delete(:ensure)
    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 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
    transport.command("aaa group server #{should[:protocol]} #{@name}", :prompt => /\(config-sg-#{should[:protocol]}\)#\z/n)
    transport.command(construct_server_cmd)
    transport.command("exit")
    [:local_authentication, :local_authorization].each do |auth|
      if !is[auth] and should[auth]
        @params[auth].update(@transport, is[auth])
      end
    end
  else
    transport.command("no aaa group server #{is[:protocol]} #{@name}")
  end
  after_update
end