Class: Puppet::ResourceApi::ResourceShim
- Inherits:
-
Object
- Object
- Puppet::ResourceApi::ResourceShim
- Defined in:
- lib/puppet/resource_api/glue.rb
Overview
A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet
Instance Attribute Summary collapse
-
#attr_def ⇒ Object
readonly
Returns the value of attribute attr_def.
-
#catalog ⇒ Object
readonly
Returns the value of attribute catalog.
-
#namevars ⇒ Object
readonly
Returns the value of attribute namevars.
-
#typename ⇒ Object
readonly
Returns the value of attribute typename.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#filtered_keys ⇒ Object
attribute names that are not title, namevars, or rsapi_custom_insync_trigger.
-
#initialize(resource_hash, typename, namevars, attr_def, catalog = nil) ⇒ ResourceShim
constructor
A new instance of ResourceShim.
- #prune_parameters(*_args) ⇒ Object
- #title ⇒ Object
- #to_hash ⇒ Object
-
#to_hiera_hash ⇒ Object
Required to enable ‘puppet device –resource …
-
#to_hierayaml ⇒ Object
Convert our resource to yaml for Hiera purposes.
- #to_json ⇒ Object
- #to_manifest ⇒ Object
Constructor Details
#initialize(resource_hash, typename, namevars, attr_def, catalog = nil) ⇒ ResourceShim
Returns a new instance of ResourceShim.
12 13 14 15 16 17 18 |
# File 'lib/puppet/resource_api/glue.rb', line 12 def initialize(resource_hash, typename, namevars, attr_def, catalog = nil) @values = resource_hash.dup.freeze # whatevs @typename = typename @namevars = namevars @attr_def = attr_def @catalog = catalog end |
Instance Attribute Details
#attr_def ⇒ Object (readonly)
Returns the value of attribute attr_def.
10 11 12 |
# File 'lib/puppet/resource_api/glue.rb', line 10 def attr_def @attr_def end |
#catalog ⇒ Object (readonly)
Returns the value of attribute catalog.
10 11 12 |
# File 'lib/puppet/resource_api/glue.rb', line 10 def catalog @catalog end |
#namevars ⇒ Object (readonly)
Returns the value of attribute namevars.
10 11 12 |
# File 'lib/puppet/resource_api/glue.rb', line 10 def namevars @namevars end |
#typename ⇒ Object (readonly)
Returns the value of attribute typename.
10 11 12 |
# File 'lib/puppet/resource_api/glue.rb', line 10 def typename @typename end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
10 11 12 |
# File 'lib/puppet/resource_api/glue.rb', line 10 def values @values end |
Instance Method Details
#filtered_keys ⇒ Object
attribute names that are not title, namevars, or rsapi_custom_insync_trigger
64 65 66 |
# File 'lib/puppet/resource_api/glue.rb', line 64 def filtered_keys values.keys.reject { |k| k == :title || k == :rsapi_custom_insync_trigger || !attr_def[k] || (attr_def[k][:behaviour] == :namevar && @namevars.size == 1) } end |
#prune_parameters(*_args) ⇒ Object
24 25 26 27 |
# File 'lib/puppet/resource_api/glue.rb', line 24 def prune_parameters(*_args) # puts "not pruning #{args.inspect}" if args.length > 0 self end |
#title ⇒ Object
20 21 22 |
# File 'lib/puppet/resource_api/glue.rb', line 20 def title values[:title] || values[@namevars.first] end |
#to_hash ⇒ Object
59 60 61 |
# File 'lib/puppet/resource_api/glue.rb', line 59 def to_hash values end |
#to_hiera_hash ⇒ Object
Required to enable ‘puppet device –resource … –to_yaml` workflow
42 43 44 |
# File 'lib/puppet/resource_api/glue.rb', line 42 def to_hiera_hash to_hierayaml end |
#to_hierayaml ⇒ Object
Convert our resource to yaml for Hiera purposes.
47 48 49 50 |
# File 'lib/puppet/resource_api/glue.rb', line 47 def to_hierayaml attributes = Hash[filtered_keys.map { |k| [k.to_s, values[k]] }] "#{YAML.dump('type' => { title => attributes }).split("\n").drop(2).join("\n")}\n" end |
#to_json ⇒ Object
52 53 54 55 56 57 |
# File 'lib/puppet/resource_api/glue.rb', line 52 def to_json(*) attrs = filtered_keys.map { |k| [k.to_s, values[k]] unless values[k].nil? } attributes = Hash[*attrs.compact.flatten] resource = { title => attributes } resource.to_json end |
#to_manifest ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/puppet/resource_api/glue.rb', line 29 def to_manifest (["#{@typename} { #{Puppet::Parameter.format_value_for_display(title)}: "] + filtered_keys.map do |k| cs = ' ' ce = '' if attr_def[k] && attr_def[k][:behaviour] && attr_def[k][:behaviour] == :read_only cs = '#' ce = ' # Read Only' end "#{cs} #{k} => #{Puppet::Parameter.format_value_for_display(values[k])},#{ce}" unless values[k].nil? end + ['}']).compact.join("\n") end |