Class: Puppet::Provider::SyslogServer::CiscoNexus

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

Overview

Implementation for the syslog_server type using the Resource API.

Instance Method Summary collapse

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



18
19
20
# File 'lib/puppet/provider/syslog_server/cisco_nexus.rb', line 18

def canonicalize(_context, resources)
  resources
end

#delete(context, name) ⇒ Object



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

def delete(context, name)
  context.notice("Destroying '#{name}'")
  @syslog_servers = Cisco::SyslogServer.syslogservers
  @syslog_servers[name].destroy if @syslog_servers[name]
end

#get(_context, servers = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/puppet/provider/syslog_server/cisco_nexus.rb', line 22

def get(_context, servers=nil)
  require 'cisco_node_utils'
  current_states = []
  @syslog_servers = Cisco::SyslogServer.syslogservers
  if servers.nil? || servers.empty?
    @syslog_servers.each do |server, instance|
      current_states << get_current_state(server, instance)
    end
  else
    servers.each do |server|
      individual_server = @syslog_servers[server]
      next if individual_server.nil?
      current_states << get_current_state(server, individual_server)
    end
  end
  current_states
end

#get_current_state(server, instance) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/provider/syslog_server/cisco_nexus.rb', line 40

def get_current_state(server, instance)
  {
    name:           server,
    ensure:         'present',
    severity_level: instance.severity_level.nil? ? instance.severity_level : instance.severity_level.to_i,
    port:           instance.port.nil? ? instance.port : instance.port.to_i,
    vrf:            instance.vrf,
    facility:       instance.facility,
  }
end

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



51
52
53
54
55
56
57
58
59
# File 'lib/puppet/provider/syslog_server/cisco_nexus.rb', line 51

def update(context, name, should)
  context.notice("Setting '#{name}' with #{should.inspect}")
  options = { 'name' => name }
  [:severity_level, :port, :vrf, :facility].each do |property|
    next unless should[property]
    options[property.to_s] = should[property].to_s
  end
  Cisco::SyslogServer.new(options)
end