Class: Puppet::DataBinding::Jerakiaserver
- Inherits:
-
Indirector::Code
- Object
- Indirector::Code
- Puppet::DataBinding::Jerakiaserver
- Defined in:
- lib/puppet/indirector/data_binding/jerakiaserver.rb
Instance Attribute Summary collapse
-
#jerakia ⇒ Object
readonly
Returns the value of attribute jerakia.
-
#scope_cache ⇒ Object
readonly
Returns the value of attribute scope_cache.
Instance Method Summary collapse
- #find(request) ⇒ Object
-
#initialize(*args) ⇒ Jerakiaserver
constructor
A new instance of Jerakiaserver.
- #scope_valid?(identifier, metadata) ⇒ Boolean
- #send_scope(identifier, scope) ⇒ Object
- #store_scope(identifier, uuid, scope) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Jerakiaserver
Returns a new instance of Jerakiaserver.
13 14 15 16 17 |
# File 'lib/puppet/indirector/data_binding/jerakiaserver.rb', line 13 def initialize(*args) @jerakia=::Jerakia::Client.new @scope_cache = {} super end |
Instance Attribute Details
#jerakia ⇒ Object (readonly)
Returns the value of attribute jerakia.
9 10 11 |
# File 'lib/puppet/indirector/data_binding/jerakiaserver.rb', line 9 def jerakia @jerakia end |
#scope_cache ⇒ Object (readonly)
Returns the value of attribute scope_cache.
10 11 12 |
# File 'lib/puppet/indirector/data_binding/jerakiaserver.rb', line 10 def scope_cache @scope_cache end |
Instance Method Details
#find(request) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/puppet/indirector/data_binding/jerakiaserver.rb', line 37 def find(request) # Jerakia doesn't do anything with lookup_options, this behaviour is achieved # using schemas, therefore we always return nil here for the key return nil if request.key == 'lookup_options' lookupdata=request.key.split(/::/) key=lookupdata.pop namespace=lookupdata.join('/') = request.[:variables].to_hash.reject { |k, v| v.is_a?(Puppet::Resource) } # If we are on an earlier version of Puppet that doesn't have trusted facts, # use the fqdn fact to identify us. Puppet 4 uses trusted. if ['trusted'] identifier = ['trusted']['certname'] else identifier = ['fqdn'] end send_scope(identifier, ) unless scope_valid?(identifier, ) = { :namespace => namespace, :scope => 'server', :scope_opts => { 'identifier' => identifier, 'realm' => 'puppet' } } begin lookup = jerakia.lookup(key, ) rescue Jerakia::Client::ScopeNotFoundError => e send_scope(identifier, ) lookup = jerakia.lookup(key, ) rescue => e raise Puppet::DataBinding::LookupError.new("Jerakia data lookup failed #{e.class}", e.) end if lookup.is_a?(Hash) raise Puppet::DataBinding::LookupError.new("Jerakia data lookup failed", lookup['message']) unless lookup['status'] = 'ok' return lookup['payload'] else raise Puppet::DataBinding::LookupError.new("Jerakia data lookup failed", "Expected a hash but got a #{lookup.class}") end end |
#scope_valid?(identifier, metadata) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/puppet/indirector/data_binding/jerakiaserver.rb', line 31 def scope_valid?(identifier, ) return false unless @scope_cache.include?(identifier) return false unless @scope_cache[identifier][:scope] == return true end |
#send_scope(identifier, scope) ⇒ Object
26 27 28 29 |
# File 'lib/puppet/indirector/data_binding/jerakiaserver.rb', line 26 def send_scope(identifier, scope) returndata = jerakia.send_scope('puppet', identifier, scope) store_scope(identifier, returndata['uuid'], scope) end |
#store_scope(identifier, uuid, scope) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/puppet/indirector/data_binding/jerakiaserver.rb', line 19 def store_scope(identifier, uuid, scope) @scope_cache[identifier] = { :uuid => uuid, :scope => scope } end |