class Puppet::ResourceApi::ResourceShim

A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet

Attributes

attr_def[R]
catalog[R]
namevars[R]
typename[R]
values[R]

Public Class Methods

new(resource_hash, typename, namevars, attr_def, catalog = nil) click to toggle source
# File lib/puppet/resource_api/glue.rb, line 11
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

Public Instance Methods

filtered_keys() click to toggle source

attribute names that are not title, namevars, or rsapi_custom_insync_trigger

# File lib/puppet/resource_api/glue.rb, line 63
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) click to toggle source
# File lib/puppet/resource_api/glue.rb, line 23
def prune_parameters(*_args)
  # puts "not pruning #{args.inspect}" if args.length > 0
  self
end
title() click to toggle source
# File lib/puppet/resource_api/glue.rb, line 19
def title
  values[:title] || values[@namevars.first]
end
to_hash() click to toggle source
# File lib/puppet/resource_api/glue.rb, line 58
def to_hash
  values
end
to_hiera_hash() click to toggle source

Required to enable ‘puppet device –resource … –to_yaml` workflow

# File lib/puppet/resource_api/glue.rb, line 41
def to_hiera_hash
  to_hierayaml
end
to_hierayaml() click to toggle source

Convert our resource to yaml for Hiera purposes.

# File lib/puppet/resource_api/glue.rb, line 46
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(*) click to toggle source
# File lib/puppet/resource_api/glue.rb, line 51
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() click to toggle source
# File lib/puppet/resource_api/glue.rb, line 28
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