Class: Puppet::Provider::SnmpCommunity::CiscoIos

Inherits:
ResourceApi::SimpleProvider
  • Object
show all
Defined in:
lib/puppet/provider/snmp_community/cisco_ios.rb

Overview

SNMP Community Puppet Provider for Cisco IOS devices

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_instance(property_hash) ⇒ Object



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

def self.commands_from_instance(property_hash)
  commands_array = []
  commands_array.push(PuppetX::CiscoIOS::Utility.set_values(property_hash, commands_hash))
  commands_array
end

.commands_hashObject



9
10
11
# File 'lib/puppet/provider/snmp_community/cisco_ios.rb', line 9

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

.instances_from_cli(output) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/puppet/provider/snmp_community/cisco_ios.rb', line 13

def self.instances_from_cli(output)
  new_instance_fields = []
  output.scan(%r{#{PuppetX::CiscoIOS::Utility.get_instances(commands_hash)}}).each do |raw_instance_fields|
    new_instance = PuppetX::CiscoIOS::Utility.parse_resource(raw_instance_fields, commands_hash)
    new_instance[:ensure] = 'present'
    new_instance.delete_if { |_k, v| v.nil? }

    new_instance_fields << new_instance
  end
  new_instance_fields
end

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



59
60
61
# File 'lib/puppet/provider/snmp_community/cisco_ios.rb', line 59

def canonicalize(_context, resources)
  resources
end

#commands_hashObject



31
32
33
# File 'lib/puppet/provider/snmp_community/cisco_ios.rb', line 31

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

#delete(context, name) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/puppet/provider/snmp_community/cisco_ios.rb', line 51

def delete(context, name)
  clear_hash = { name: name, ensure: 'absent' }
  array_of_commands_to_run = Puppet::Provider::SnmpCommunity::CiscoIos.commands_from_instance(clear_hash)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
end

#get(context, _names = nil) ⇒ Object



35
36
37
38
39
40
# File 'lib/puppet/provider/snmp_community/cisco_ios.rb', line 35

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::SnmpCommunity::CiscoIos.instances_from_cli(output)
  PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value)
end

#update(context, _name, should) ⇒ Object Also known as: create



42
43
44
45
46
47
# File 'lib/puppet/provider/snmp_community/cisco_ios.rb', line 42

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