Class: Puppet::Provider::IosSnmpGlobal::CiscoIos

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

Overview

Configure the domain name of the device

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_instance(instance) ⇒ Object



24
25
26
27
28
# File 'lib/puppet/provider/ios_snmp_global/cisco_ios.rb', line 24

def self.commands_from_instance(instance)
  commands = []
  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_snmp_global/cisco_ios.rb', line 6

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

.convert_to_boolean(value) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/puppet/provider/ios_snmp_global/cisco_ios.rb', line 30

def self.convert_to_boolean(value)
  if value.nil?
    false
  else
    true
  end
end

.false_to_unset(value) ⇒ Object



38
39
40
41
# File 'lib/puppet/provider/ios_snmp_global/cisco_ios.rb', line 38

def self.false_to_unset(value)
  return 'unset' if value == false
  value
end

.instances_from_cli(output) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puppet/provider/ios_snmp_global/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.delete_if { |_k, v| v.nil? }
  new_instance[:system_shutdown] = Puppet::Provider::IosSnmpGlobal::CiscoIos.convert_to_boolean(new_instance[:system_shutdown])
  new_instance[:manager] = Puppet::Provider::IosSnmpGlobal::CiscoIos.convert_to_boolean(new_instance[:manager])
  new_instance[:ifmib_ifindex_persist] = Puppet::Provider::IosSnmpGlobal::CiscoIos.convert_to_boolean(new_instance[:ifmib_ifindex_persist])
  new_instance[:manager_session_timeout] = 'unset' unless new_instance[:manager_session_timeout]
  new_instance[:contact] = 'unset' unless new_instance[:contact]
  new_instance[:trap_source] = 'unset' unless new_instance[:trap_source]
  new_instance_fields << new_instance
  new_instance_fields
end

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



73
74
75
# File 'lib/puppet/provider/ios_snmp_global/cisco_ios.rb', line 73

def canonicalize(_context, resources)
  resources
end

#commands_hashObject



43
44
45
# File 'lib/puppet/provider/ios_snmp_global/cisco_ios.rb', line 43

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

#get(context, _names = nil) ⇒ Object



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

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

#set(context, changes) ⇒ Object



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

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



63
64
65
66
67
68
69
70
71
# File 'lib/puppet/provider/ios_snmp_global/cisco_ios.rb', line 63

def update(context, _name, should)
  should.each do |key, value|
    should[key] = Puppet::Provider::IosSnmpGlobal::CiscoIos.false_to_unset(value)
  end
  array_of_commands_to_run = Puppet::Provider::IosSnmpGlobal::CiscoIos.commands_from_instance(should)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
end