Class: Puppet::Provider::Naginator

Inherits:
ParsedFile show all
Defined in:
lib/puppet/provider/naginator.rb

Overview

The base class for all Naginator providers.

Constant Summary collapse

NAME_STRING =
"## --PUPPET_NAME-- (called '_naginator_name' in the manifest)"

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Constants inherited from Puppet::Provider

Confine

Constants included from Util::Logging

Util::Logging::FILE_AND_LINE, Util::Logging::FILE_NO_LINE, Util::Logging::MM, Util::Logging::NO_FILE_LINE, Util::Logging::SUPPRESS_FILE_LINE

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary

Attributes inherited from ParsedFile

#property_hash

Attributes included from Util::FileParsing

#line_separator, #trailing_separator

Attributes inherited from Puppet::Provider

#resource

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ParsedFile

backup_target, clean, clear, #create, default_mode, #destroy, drop_native_header, #exists?, filetype, filetype=, #flush, flush, flush_target, header, initvars, instances, match_providers_with_resources, mk_resource_methods, modified, native_header_regex, prefetch, #prefetch, prefetch_all_targets, prefetch_target, record?, #record_type, resource_for_record, resource_type=, retrieve, target_object, target_records, targets

Methods included from Util::FileParsing

#clear_records, #fields, #handle_record_line, #handle_text_line, #lines, #parse, #parse_line, #record_line, #records?, #text_line, #to_file, #to_line, #valid_attr?

Methods included from Util

absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods inherited from Puppet::Provider

#<=>, #clear, #command, command, commands, declared_feature?, default?, default_match, defaultfor, execfail, #execfail, execpipe, #execpipe, execute, #execute, fact_match, feature_match, #flush, #get, has_command, initvars, #inspect, instances, mk_resource_methods, #name, optional_commands, post_resource_eval, prefetch, #set, specificity, supports_parameter?, #to_s

Methods included from Util::Logging

#clear_deprecation_warnings, #debug, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, #send_log, setup_facter_logging!, #warn_once

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Util::Warnings

clear_warnings, debug_once, notice_once, warnonce

Methods included from Confiner

#confine, #confine_collection, #suitable?

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

#initialize(resource = nil) ⇒ Naginator

Returns a new instance of Naginator.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/puppet/provider/naginator.rb', line 49

def initialize(resource = nil)
  if resource.is_a?(Nagios::Base)
    # We don't use a duplicate here, because some providers (ParsedFile, at least)
    # use the hash here for later events.
    @property_hash = resource
  elsif resource
    @resource = resource if resource
    # LAK 2007-05-09: Keep the model stuff around for backward compatibility
    @model = resource
    @property_hash = self.class.nagios_type.new
  else
    @property_hash = self.class.nagios_type.new
  end
end

Class Method Details

.nagios_typeObject

Retrieve the associated class from Nagios::Base.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppet/provider/naginator.rb', line 9

def self.nagios_type
  unless @nagios_type
    name = resource_type.name.to_s.sub(/^nagios_/, '')
    unless @nagios_type = Nagios::Base.type(name.to_sym)
      raise Puppet::DevError, "Could not find nagios type '#{name}'"
    end

    # And add our 'ensure' settings, since they aren't a part of
    # Naginator by default
    @nagios_type.send(:attr_accessor, :ensure, :target, :on_disk)
  end
  @nagios_type
end

.parse(text) ⇒ Object



23
24
25
26
27
# File 'lib/puppet/provider/naginator.rb', line 23

def self.parse(text)
    Nagios::Parser.new.parse(text.gsub(NAME_STRING, "_naginator_name"))
rescue => detail
    raise Puppet::Error, _("Could not parse configuration for %{resource}: %{detail}") % { resource: resource_type.name, detail: detail }, detail.backtrace
end

.skip_record?(record) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/puppet/provider/naginator.rb', line 41

def self.skip_record?(record)
  false
end

.to_file(records) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/provider/naginator.rb', line 29

def self.to_file(records)
  header + records.collect { |record|
      # Remap the TYPE_name or _naginator_name params to the
      # name if the record is a template (register == 0)
      if record.to_s =~ /register\s+0/
          record.to_s.sub("_naginator_name", "name").sub(record.type.to_s + "_name", "name")
      else
          record.to_s.sub("_naginator_name", NAME_STRING)
      end
  }.join("\n")
end

.valid_attr?(klass, attr_name) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/puppet/provider/naginator.rb', line 45

def self.valid_attr?(klass, attr_name)
  nagios_type.parameters.include?(attr_name)
end