Class: Classification
- Inherits:
-
Object
- Object
- Classification
- Defined in:
- lib/puppetclassify/classification.rb
Instance Method Summary collapse
- #explain(name, facts = {}) ⇒ Object
- #get(name, facts = {}) ⇒ Object
-
#initialize(nc_api_url, puppet_https) ⇒ Classification
constructor
A new instance of Classification.
Constructor Details
#initialize(nc_api_url, puppet_https) ⇒ Classification
Returns a new instance of Classification.
4 5 6 7 |
# File 'lib/puppetclassify/classification.rb', line 4 def initialize(nc_api_url, puppet_https) @nc_api_url = nc_api_url @puppet_https = puppet_https end |
Instance Method Details
#explain(name, facts = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/puppetclassify/classification.rb', line 25 def explain(name, facts={}) unless facts.class == Hash STDERR.puts "Facts should be a hash, not a #{facts.class}" return false end class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}/explanation", facts.to_json) unless class_res.code.to_i == 200 STDERR.puts "An error occured retreiving the classification explanation of node #{name}: HTTP #{class_res.code} #{class_res.}" STDERR.puts class_res.body else JSON.parse(class_res.body) end end |
#get(name, facts = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppetclassify/classification.rb', line 9 def get(name, facts={}) unless facts.class == Hash STDERR.puts "Facts should be a hash, not a #{facts.class}" return false end class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}", facts.to_json) unless class_res.code.to_i == 200 STDERR.puts "An error occured retreiving the classification of node #{name}: HTTP #{class_res.code} #{class_res.}" STDERR.puts class_res.body else JSON.parse(class_res.body) end end |