Class: PuppetX::Puppetlabs::CD4PEApi::CompileHandler
- Inherits:
-
Object
- Object
- PuppetX::Puppetlabs::CD4PEApi::CompileHandler
- Defined in:
- lib/puppet_x/puppetlabs/cd4pe_api/compile_handler.rb
Overview
Provides a rest api handler for custom cdpe compiler
Instance Method Summary collapse
- #call(request, response) ⇒ Object
-
#setup_node_cache ⇒ void
Sets up a special node cache "write only yaml" that collects and stores node data in yaml but never finds or reads anything (this since a real cache causes stale data to be served in circumstances when the cache can not be cleared).
- #setup_terminuses ⇒ Object
Instance Method Details
#call(request, response) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 |
# File 'lib/puppet_x/puppetlabs/cd4pe_api/compile_handler.rb', line 9 def call(request, response) # Get all the current indirector configs to restore at the end terminus = Puppet[:catalog_terminus] t_class = Puppet::Resource::Catalog.indirection.terminus_class node_cache = Puppet::Resource::Catalog.indirection.cache_class content = Puppet::FileServing::Content.indirection.terminus_class = Puppet::FileServing::Metadata.indirection.terminus_class file = Puppet::FileBucket::File.indirection.terminus_class fact_term = Puppet::Node::Facts.indirection.terminus_class reports = Puppet[:report] node_terminus = Puppet::Node.indirection.terminus_class # Ensure that the baseline and preview catalogs are not stored via the # catalog indirection (may go to puppet-db) # # TODO: Is there a better way to disable the cache ? Puppet::Node::Facts.indirection.cache_class = false setup_terminuses setup_node_cache ret = { catalog: nil, logs: [], } begin Puppet[:catalog_terminus] = :cdpe_compiler Puppet[:report] = false Puppet::Node.indirection.terminus_class = :cdpe Puppet::Resource::Catalog.indirection.terminus_class = :cdpe_compiler node = request[:params][:rest] environment = request[:params][:environment] = { preview_environment: environment, back_channel: { logs: [] }, } catalog = Puppet::Resource::Catalog.indirection.find(node, ) unless catalog.nil? ret[:catalog] = catalog.to_data_hash end rescue ret[:catalog] = nil ensure Puppet[:catalog_terminus] = terminus Puppet::Node.indirection.terminus_class = node_terminus Puppet::Resource::Catalog.indirection.cache_class = node_cache Puppet::FileServing::Content.indirection.terminus_class = content Puppet::FileServing::Metadata.indirection.terminus_class = Puppet::FileBucket::File.indirection.terminus_class = file Puppet::Resource::Catalog.indirection.terminus_class = t_class Puppet::Node::Facts.indirection.terminus_class = fact_term Puppet[:report] = reports end [:back_channel][:logs].each do |log| begin ret[:logs] << log.to_data_hash rescue ret[:logs] << log end end response.respond_with(200, 'application/json', ret.to_json) end |
#setup_node_cache ⇒ void
This method returns an undefined value.
Sets up a special node cache "write only yaml" that collects and stores node data in yaml but never finds or reads anything (this since a real cache causes stale data to be served in circumstances when the cache can not be cleared).
93 94 95 |
# File 'lib/puppet_x/puppetlabs/cd4pe_api/compile_handler.rb', line 93 def setup_node_cache Puppet::Node.indirection.cache_class = Puppet[:node_cache_terminus] end |
#setup_terminuses ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/puppet_x/puppetlabs/cd4pe_api/compile_handler.rb', line 75 def setup_terminuses require 'puppet/file_serving/content' require 'puppet/file_serving/metadata' Puppet::FileServing::Content.indirection.terminus_class = :file_server Puppet::FileServing::Metadata.indirection.terminus_class = :file_server Puppet::Resource::Catalog.indirection.cache_class = false Puppet::FileBucket::File.indirection.terminus_class = :file Puppet::Node::Facts.indirection.terminus_class = :puppetdb end |