Class: Puppet::Provider::SyslogServer::CiscoIos

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

Overview

Utility functions to parse out the Interface

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_instance(hash_should, hash_current) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/puppet/provider/syslog_server/cisco_ios.rb', line 25

def self.commands_from_instance(hash_should, hash_current)
  commands_array = []
  if hash_current[:vrf] != hash_should[:vrf] && hash_should[:ensure] != 'absent'
    commands_array << if hash_current[:vrf]
                        PuppetX::CiscoIOS::Utility.set_values({ name: hash_should[:name], vrf: "vrf #{hash_current[:vrf]}", ensure: 'absent' }, commands_hash)
                      else
                        PuppetX::CiscoIOS::Utility.set_values({ name: hash_should[:name], ensure: 'absent' }, commands_hash)
                      end
  end

  hash_should[:vrf] = "vrf #{hash_should[:vrf]}" if hash_should[:vrf]
  hash_should[:vrf] = "vrf #{hash_current[:vrf]}" if hash_current[:vrf] != hash_should[:vrf] && hash_current[:vrf] && hash_should[:ensure] != 'present'
  command = PuppetX::CiscoIOS::Utility.set_values(hash_should, commands_hash)
  command = command.to_s.gsub(%r{name }, '')
  commands_array.push(command)
  commands_array
end

.commands_hashObject



9
10
11
# File 'lib/puppet/provider/syslog_server/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/syslog_server/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[:severity_level] = PuppetX::CiscoIOS::Utility.convert_level_name_to_int(new_instance[:severity_level]) unless new_instance[:severity_level].nil?
    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



72
73
74
# File 'lib/puppet/provider/syslog_server/cisco_ios.rb', line 72

def canonicalize(_context, resources)
  resources
end

#commands_hashObject



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

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

#get(context, _names = nil) ⇒ Object



47
48
49
50
51
# File 'lib/puppet/provider/syslog_server/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?
  Puppet::Provider::SyslogServer::CiscoIos.instances_from_cli(output)
end

#set(context, changes) ⇒ Object



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

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

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



63
64
65
66
67
68
# File 'lib/puppet/provider/syslog_server/cisco_ios.rb', line 63

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