Module: AugeasProviders::Provider
- Included in:
- Mounttab::Fstab, Mounttab::Vfstab
- Defined in:
- lib/augeasproviders/provider.rb
Overview
Mixin to add Augeas-related helpers to Puppet providers.
Handles basics such as opening, accessing and saving changes via an Augeas handle, plus standard configuration from a Puppet resource (e.g. the ‘target` parameter).
To use, include in the provider:
Puppet::Type.type(:example).provide(:augeas) do
include AugeasProviders::Provider
# [..]
end
Defined Under Namespace
Modules: ClassMethods
Class Attribute Summary collapse
-
.loadpath ⇒ Object
private
Override Augeas’ loadpath, usually for testing with a separate Augeas checkout.
Class Method Summary collapse
Instance Method Summary collapse
-
#aug_handler ⇒ Augeas
private
Returns an Augeas handler.
-
#aug_version ⇒ String
Returns the Augeas version used.
-
#augclose!(aug) ⇒ Object
Close the shared Augeas handler.
-
#augopen(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... } ⇒ Augeas
Opens Augeas and returns a handle to use.
-
#augopen!(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... } ⇒ Augeas
Opens Augeas and returns a handle to use.
-
#augsave!(aug, reload = false) ⇒ Object
Saves all changes made in the current Augeas handle and checks for any errors while doing so.
-
#destroy ⇒ Object
Default method to destroy a resource can be overridden if necessary.
-
#exists? ⇒ Boolean
Default method to determine the existence of a resource can be overridden if necessary.
-
#flush ⇒ Object
Default method to flush a resource.
-
#parsed_as?(text, path, lens = nil) ⇒ Boolean
Returns whether text is parsed as path using lens.
-
#path_label(aug, path) ⇒ String
Wrapper around Augeas#label for older versions of Augeas.
-
#quoteit(value, oldvalue = nil) ⇒ String
Automatically quote a value.
-
#readquote(value) ⇒ Symbol
Detect what type of quoting a value uses.
-
#resource_path ⇒ String
Gets the Augeas path expression representing the individual resource inside the file, that represents the current Puppet resource.
-
#setvars(aug) ⇒ Object
Sets useful Augeas variables for the session:.
-
#supported?(feature) ⇒ Boolean
Returns whether a feature is supported.
-
#target ⇒ String
Gets the path expression representing the file being managed for the current Puppet resource.
-
#unquoteit(value) ⇒ String
Automatically unquote a value.
Class Attribute Details
.loadpath ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Augeas’ loadpath, usually for testing with a separate Augeas checkout.
28 29 30 |
# File 'lib/augeasproviders/provider.rb', line 28 def loadpath @loadpath end |
Class Method Details
.included(base) ⇒ Object
31 32 33 |
# File 'lib/augeasproviders/provider.rb', line 31 def self.included(base) base.send(:extend, ClassMethods) end |
Instance Method Details
#aug_handler ⇒ Augeas
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an Augeas handler.
On Puppet >= 3.4, stores and returns a shared Augeas handler for all instances of the class
815 816 817 |
# File 'lib/augeasproviders/provider.rb', line 815 def aug_handler self.class.aug_handler end |
#aug_version ⇒ String
Returns the Augeas version used
724 725 726 |
# File 'lib/augeasproviders/provider.rb', line 724 def aug_version self.class.aug_version end |
#augclose!(aug) ⇒ Object
Close the shared Augeas handler.
804 805 806 |
# File 'lib/augeasproviders/provider.rb', line 804 def augclose!(aug) self.class.augclose!(aug) end |
#augopen(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... } ⇒ Augeas
Opens Augeas and returns a handle to use. It loads only the file for the current Puppet resource using AugeasProviders::Provider::ClassMethods#lens.
If called with a block, this will be yielded to and the Augeas handle closed after the block has executed (on Puppet < 3.4.0). Otherwise, the handle will be returned and not closed automatically. On Puppet >= 3.4, the handle will be closed by ‘post_resource_eval`. On older versions, the caller is responsible for closing it to free resources.
If ‘yield_resource` is set to true, the supplied `resource` will be passed as a yieldparam to the block, after the `aug` handle. Any arguments passed after `yield_resource` will be added as yieldparams to the block.
763 764 765 |
# File 'lib/augeasproviders/provider.rb', line 763 def augopen(yield_resource = false, *yield_params, &block) self.class.augopen(self.resource, yield_resource, *yield_params, &block) end |
#augopen!(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... } ⇒ Augeas
Opens Augeas and returns a handle to use. It loads only the file for the current Puppet resource using AugeasProviders::Provider::ClassMethods#lens. #augsave! is called after the block is evaluated.
If called with a block, this will be yielded to and the Augeas handle closed after the block has executed (on Puppet < 3.4.0). Otherwise, the handle will be returned and not closed automatically. On Puppet >= 3.4, the handle will be closed by ‘post_resource_eval`. On older versions, the caller is responsible for closing it to free resources.
785 786 787 |
# File 'lib/augeasproviders/provider.rb', line 785 def augopen!(yield_resource = false, *yield_params, &block) self.class.augopen!(self.resource, yield_resource, *yield_params, &block) end |
#augsave!(aug, reload = false) ⇒ Object
Saves all changes made in the current Augeas handle and checks for any errors while doing so.
796 797 798 |
# File 'lib/augeasproviders/provider.rb', line 796 def augsave!(aug, reload = false) self.class.augsave!(aug, reload) end |
#destroy ⇒ Object
Default method to destroy a resource can be overridden if necessary
922 923 924 925 926 |
# File 'lib/augeasproviders/provider.rb', line 922 def destroy augopen! do |aug| aug.rm('$resource') end end |
#exists? ⇒ Boolean
Default method to determine the existence of a resource can be overridden if necessary
914 915 916 917 918 |
# File 'lib/augeasproviders/provider.rb', line 914 def exists? augopen do |aug| not aug.match('$resource').empty? end end |
#flush ⇒ Object
Default method to flush a resource
On Puppet >= 3.4, this takes care of saving the tree for the shared Augeas handler.
This method can be overridden in your provider but you should make sure to call ‘super` to ensure that the tree will be saved in Puppet >= 3.4
936 937 938 |
# File 'lib/augeasproviders/provider.rb', line 936 def flush augsave!(aug_handler, true) if supported?(:post_resource_eval) end |
#parsed_as?(text, path, lens = nil) ⇒ Boolean
Returns whether text is parsed as path using lens
907 908 909 910 |
# File 'lib/augeasproviders/provider.rb', line 907 def parsed_as?(text, path, lens = nil) lens ||= self.class.lens(self.resource) self.class.parsed_as?(text, path, lens) end |
#path_label(aug, path) ⇒ String
Wrapper around Augeas#label for older versions of Augeas
825 826 827 |
# File 'lib/augeasproviders/provider.rb', line 825 def path_label(aug, path) self.class.path_label(aug, path) end |
#quoteit(value, oldvalue = nil) ⇒ String
Automatically quote a value
835 836 837 |
# File 'lib/augeasproviders/provider.rb', line 835 def quoteit(value, oldvalue = nil) self.class.quoteit(value, self.resource, oldvalue) end |
#readquote(value) ⇒ Symbol
Detect what type of quoting a value uses
844 845 846 |
# File 'lib/augeasproviders/provider.rb', line 844 def readquote(value) self.class.readquote(value) end |
#resource_path ⇒ String
Gets the Augeas path expression representing the individual resource inside the file, that represents the current Puppet resource.
If no block was set by the provider’s class method, it returns the path expression representing the top-level of the file.
858 859 860 |
# File 'lib/augeasproviders/provider.rb', line 858 def resource_path self.class.resource_path(self.resource) end |
#setvars(aug) ⇒ Object
Sets useful Augeas variables for the session:
-
‘$target` points to the root of the target file
-
‘$resource` points to path defined by #resource_path
It also sets ‘/augeas/context` to the target file so relative paths can be used, before the variables are set.
If supplied with a resource, it will be used to determine the path to the used file.
876 877 878 |
# File 'lib/augeasproviders/provider.rb', line 876 def setvars(aug) self.class.setvars(aug, self.resource) end |
#supported?(feature) ⇒ Boolean
Returns whether a feature is supported.
The following features are currently supported:
-
‘:regexpi`: whether Augeas supports an ’i’ flag in regexp expressions
-
‘:post_resource_eval`: whether Puppet supports `post_resource_eval` hooks
738 739 740 |
# File 'lib/augeasproviders/provider.rb', line 738 def supported?(feature) self.class.supported?(feature) end |
#target ⇒ String
Gets the path expression representing the file being managed for the current Puppet resource.
887 888 889 |
# File 'lib/augeasproviders/provider.rb', line 887 def target self.class.target(self.resource) end |
#unquoteit(value) ⇒ String
Automatically unquote a value
896 897 898 |
# File 'lib/augeasproviders/provider.rb', line 896 def unquoteit(value) self.class.unquoteit(value) end |