Class: Puppet::Provider::ElasticKibana
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::ElasticKibana
- Defined in:
- lib/puppet/provider/elastic_kibana.rb
Overview
Parent class for Kibana plugin providers.
Class Attribute Summary collapse
-
.format_url ⇒ Object
Returns the value of attribute format_url.
-
.home_path ⇒ Object
Returns the value of attribute home_path.
-
.install_args ⇒ Object
Returns the value of attribute install_args.
-
.plugin_directory ⇒ Object
Returns the value of attribute plugin_directory.
-
.remove_args ⇒ Object
Returns the value of attribute remove_args.
Class Method Summary collapse
-
.instances ⇒ Array
Finds and returns all present resources on the host.
-
.prefetch(resources) ⇒ Object
Puppet prefetch boilerplate.
-
.present_plugins ⇒ Array<Hash>
Discovers plugins present on the system.
Instance Method Summary collapse
-
#create ⇒ Symbol
Sets the ensure property in the @property_flush hash.
-
#destroy ⇒ Symbol
Set flushed ensure property to absent.
-
#exists? ⇒ Boolean
Determine whether this resource is present on the system.
-
#flush ⇒ Object
Enforce the desired state dictated by the properties to flush from the provider.
-
#format_url ⇒ Proc
Formats a url for the plugin command-line argument.
-
#initialize(value = {}) ⇒ ElasticKibana
constructor
Provider constructor.
-
#plugin_url ⇒ Array<String>
Helps to format the plugin name for installation.
-
#run_plugin(args) ⇒ String
Wrap the plugin command in some helper functionality to set the right uid/gid.
-
#set_property_hash ⇒ Object
Repopulates the @property_hash to the on-system state for the provider.
-
#version ⇒ String
version property getter.
-
#version=(new_version) ⇒ String
version property setter.
Constructor Details
#initialize(value = {}) ⇒ ElasticKibana
Provider constructor
148 149 150 151 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 148 def initialize(value = {}) super(value) @property_flush = {} end |
Class Attribute Details
.format_url ⇒ Object
Returns the value of attribute format_url.
8 9 10 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 8 def format_url @format_url end |
.home_path ⇒ Object
Returns the value of attribute home_path.
8 9 10 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 8 def home_path @home_path end |
.install_args ⇒ Object
Returns the value of attribute install_args.
8 9 10 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 8 def install_args @install_args end |
.plugin_directory ⇒ Object
Returns the value of attribute plugin_directory.
8 9 10 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 8 def plugin_directory @plugin_directory end |
.remove_args ⇒ Object
Returns the value of attribute remove_args.
8 9 10 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 8 def remove_args @remove_args end |
Class Method Details
.instances ⇒ Array
Finds and returns all present resources on the host.
130 131 132 133 134 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 130 def self.instances present_plugins.map do |plugin| new plugin end end |
.prefetch(resources) ⇒ Object
Puppet prefetch boilerplate.
139 140 141 142 143 144 145 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 139 def self.prefetch(resources) instances.each do |prov| if (resource = resources[prov.name]) resource.provider = prov end end end |
.present_plugins ⇒ Array<Hash>
Discovers plugins present on the system. This is essentially the same way that the node code does it, so we do it in native ruby to speed up the process and grab arbitrary metadata from the plugin json (which should always be present).
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 27 def self.present_plugins plugins = Dir[File.join(home_path, plugin_directory, '*')].select do |directory| !File.basename(directory).start_with? '.' \ and File.exist? File.join(directory, 'package.json') end plugins.map do |plugin| j = JSON.parse(File.read(File.join(plugin, 'package.json'))) { name: File.basename(plugin), ensure: :present, provider: name, version: j['version'] } end end |
Instance Method Details
#create ⇒ Symbol
Sets the ensure property in the @property_flush hash.
102 103 104 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 102 def create @property_flush[:ensure] = :present end |
#destroy ⇒ Symbol
Set flushed ensure property to absent.
116 117 118 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 116 def destroy @property_flush[:ensure] = :absent end |
#exists? ⇒ Boolean
Determine whether this resource is present on the system.
109 110 111 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 109 def exists? @property_hash[:ensure] == :present end |
#flush ⇒ Object
Enforce the desired state dictated by the properties to flush from the provider.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 47 def flush if @property_flush[:ensure] == :absent # Simply remove the plugin if it should be gone run_plugin self.class.remove_args + [resource[:name]] else run_plugin self.class.remove_args + [resource[:name]] unless @property_flush[:version].nil? run_plugin self.class.install_args + plugin_url end set_property_hash end |
#format_url ⇒ Proc
Formats a url for the plugin command-line argument. Necessary since different versions of the Kibana plugin CLI tool accept URL arguments in differing ways.
17 18 19 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 17 def format_url self.class.format_url ||= ->(url, _) { [url] } end |
#plugin_url ⇒ Array<String>
Helps to format the plugin name for installation. That is, if we have a URL, pass it in correctly to the CLI tool.
73 74 75 76 77 78 79 80 81 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 73 def plugin_url if !resource[:url].nil? format_url.call resource[:url], binding elsif !resource[:organization].nil? [[resource[:organization], resource[:name], resource[:version]].join('/')] else [resource[:name]] end end |
#run_plugin(args) ⇒ String
Wrap the plugin command in some helper functionality to set the right uid/gid.
63 64 65 66 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 63 def run_plugin(args) stdout = execute([command(:plugin)] + args, uid: 'kibana', gid: 'kibana') stdout.exitstatus.zero? ? debug(stdout) : raise(Puppet::Error, stdout) end |
#set_property_hash ⇒ Object
Repopulates the @property_hash to the on-system state for the provider.
121 122 123 124 125 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 121 def set_property_hash @property_hash = self.class.present_plugins.find do |p| p[:name] == resource[:name] end end |
#version ⇒ String
version property getter
95 96 97 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 95 def version @property_hash[:version] end |
#version=(new_version) ⇒ String
version property setter
88 89 90 |
# File 'lib/puppet/provider/elastic_kibana.rb', line 88 def version=(new_version) @property_flush[:version] = new_version end |