Class: Puppet::Provider::IosAaaNewModel::CiscoIos

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb

Overview

Configure aaa new model on the device

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_instance(instance) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb', line 24

def self.commands_from_instance(instance)
  commands = []
  instance[:enable] = if instance[:enable]
                        ''
                      else
                        'no '
                      end
  commands += PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(instance, commands_hash)
  commands
end

.commands_hashObject



6
7
8
# File 'lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb', line 6

def self.commands_hash
  @commands_hash ||= PuppetX::CiscoIOS::Utility.load_yaml(File.expand_path(__dir__) + '/command.yaml')
end

.instances_from_cli(output) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb', line 10

def self.instances_from_cli(output)
  new_instance_fields = []
  new_instance = PuppetX::CiscoIOS::Utility.parse_resource(output, commands_hash)
  new_instance[:name] = 'default'
  new_instance[:enable] = if new_instance[:enable]
                            true
                          else
                            false
                          end
  new_instance.delete_if { |_k, v| v.nil? }
  new_instance_fields << new_instance
  new_instance_fields
end

Instance Method Details

#commands_hashObject



35
36
37
# File 'lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb', line 35

def commands_hash
  Puppet::Provider::IosAaaNewModel::CiscoIos.commands_hash
end

#get(context) ⇒ Object



39
40
41
42
43
44
# File 'lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb', line 39

def get(context)
  output = context.transport.run_command_enable_mode(PuppetX::CiscoIOS::Utility.get_values(commands_hash))
  return [] if output.nil?
  return_value = Puppet::Provider::IosAaaNewModel::CiscoIos.instances_from_cli(output)
  PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value)
end

#set(context, changes) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb', line 46

def set(context, changes)
  changes.each do |name, change|
    should = change[:should]
    context.updating(name) do
      update(context, name, should)
    end
  end
end

#update(context, _name, should) ⇒ Object



55
56
57
58
59
60
# File 'lib/puppet/provider/ios_aaa_new_model/cisco_ios.rb', line 55

def update(context, _name, should)
  array_of_commands_to_run = Puppet::Provider::IosAaaNewModel::CiscoIos.commands_from_instance(should)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
end