Class: Puppet::Provider::SyslogSettings::CiscoNexus
- Inherits:
-
Object
- Object
- Puppet::Provider::SyslogSettings::CiscoNexus
- Defined in:
- lib/puppet/provider/syslog_settings/cisco_nexus.rb
Overview
Implementation for the syslog_settings type using the Resource API.
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #get(_context, _names = nil) ⇒ Object
- #set(context, changes) ⇒ Object
- #tidy_up_syslog_logfile(should) ⇒ Object
- #update(context, name, should) ⇒ Object
- #validate_should(should) ⇒ Object
- #validate_syslog_logfile(should) ⇒ Object
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/puppet/provider/syslog_settings/cisco_nexus.rb', line 36 def canonicalize(_context, resources) resources.each do |resource| resource.each do |k, v| resource[k] = 'unset' if v.nil? || v == (nil || -1) end end resources end |
#get(_context, _names = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/puppet/provider/syslog_settings/cisco_nexus.rb', line 56 def get(_context, _names=nil) require 'cisco_node_utils' @syslog_settings = Cisco::SyslogSettings.syslogsettings['default'] current_state = { name: 'default', } SYSLOG_SETTINGS_ARRAY_PROPS.each do |property| value = @syslog_settings.send(property) current_state[property] = value ? [value] : ['unset'] end SYSLOG_SETTINGS_NON_BOOL_PROPS.each do |property| value = @syslog_settings.send(property) current_state[property] = value ? value : 'unset' end SYSLOG_SETTINGS_INTEGER_PROPS.each do |property| value = @syslog_settings.send(property) if value != 'unset' current_state[property] = value ? value.to_i : 'unset' else current_state[property] = value end end [current_state] end |
#set(context, changes) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/puppet/provider/syslog_settings/cisco_nexus.rb', line 45 def set(context, changes) changes.each do |name, change| should = change[:should] is = change[:is] if should != is update(context, name, should) end end end |
#tidy_up_syslog_logfile(should) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/puppet/provider/syslog_settings/cisco_nexus.rb', line 132 def tidy_up_syslog_logfile(should) @syslog_settings = Cisco::SyslogSettings.syslogsettings['default'] SYSLOG_CONFIG_PROPS.delete(:logfile_severity_level) SYSLOG_CONFIG_PROPS.delete(:logfile_name) SYSLOG_CONFIG_PROPS.delete(:logfile_size) # use the configured logfile name if logfile_name is not supplied unless should[:logfile_name] should[:logfile_name] = @syslog_settings.logfile_name end if should[:logfile_name] == 'unset' should[:logfile_severity_level] = nil should[:logfile_name] = nil should[:logfile_size] = nil else return unless (should[:logfile_severity_level] && should[:logfile_name]) || (@syslog_settings.logfile_severity_level && @syslog_settings.logfile_name) # use the configured logfile_severity_level name if logfile_severity_level is not supplied unless should[:logfile_severity_level] should[:logfile_severity_level] = @syslog_settings.logfile_severity_level end end if should[:logfile_size] && should[:logfile_size] != -1 should[:logfile_size] = "size #{should[:logfile_size]}" else should[:logfile_size] = '' end @syslog_settings.send('logfile_name=', should[:logfile_name], should[:logfile_severity_level], should[:logfile_size]) if @syslog_settings.respond_to?('logfile_name=') end |
#update(context, name, should) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/puppet/provider/syslog_settings/cisco_nexus.rb', line 85 def update(context, name, should) validate_should(should) validate_syslog_logfile(should) context.notice("Setting '#{name}' with #{should.inspect}") @syslog_settings = Cisco::SyslogSettings.syslogsettings['default'] tidy_up_syslog_logfile(should) SYSLOG_CONFIG_PROPS.each do |property| next unless should[property] # Other platforms require array for some types - Nexus does not should[property] = should[property][0] if should[property].is_a?(Array) # Call the AutoGen setters for the @syslog_settings node_utils object. should[property] = nil if should[property] == 'unset' || should[property] == -1 @syslog_settings.send("#{property}=", should[property]) if @syslog_settings.respond_to?("#{property}=") end end |
#validate_should(should) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/puppet/provider/syslog_settings/cisco_nexus.rb', line 122 def validate_should(should) raise Puppet::ResourceError, "This provider only supports a namevar of 'default'." unless should[:name].to_s == 'default' raise Puppet::ResourceError, "This provider does not support the 'enable' property. "\ 'Syslog servers are enabled implicitly when using the syslog_server resource.' if should[:enable] raise Puppet::ResourceError, "This provider does not support the 'vrf' property. " if should[:vrf] end |
#validate_syslog_logfile(should) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/puppet/provider/syslog_settings/cisco_nexus.rb', line 102 def validate_syslog_logfile(should) raise Puppet::ResourceError, 'This provider requires that a logfile_name and logfile_severity_level are both specified in order '\ 'to set logfile settings.' if should[:logfile_name].to_s != 'unset' && ((should[:logfile_name] && !should[:logfile_severity_level]) || (should[:logfile_severity_level] && !should[:logfile_name])) raise Puppet::ResourceError, 'This provider requires that a logfile_name is unset in order to unset logfile_severity_level' if should[:logfile_name].to_s != 'unset' && (should[:logfile_severity_level].to_s == 'unset' || should[:logfile_severity_level] == -1) raise Puppet::ResourceError, 'This provider does not support setting the logfile_severity_level when logfile_name is unset' if should[:logfile_name].to_s == 'unset' && (should[:logfile_severity_level] && (should[:logfile_severity_level].to_s != 'unset' && should[:logfile_severity_level] != -1)) raise Puppet::ResourceError, 'This provider requires that a logfile_name and logfile_severity_level are both specified in order '\ 'to set logfile_size.' if should[:logfile_size] && !should[:logfile_name] && !should[:logfile_severity_level] end |