puppetclassify 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24cffc7fa8e47a8e736fe56d25a790e3c2a60874
4
- data.tar.gz: 4d03c7f46734ceb251c63b07b0eeda4b6c6a3381
3
+ metadata.gz: 9f483cde63ad46f3c698a9777189eb30294a799a
4
+ data.tar.gz: 1bd815ddd7911c47dac2fe888ff8cfda0d27bfae
5
5
  SHA512:
6
- metadata.gz: 0843dcbb300e3596b08dfa42531391182f7f0490b167ea18a6f323f12d125858906559269ae1f1d5c252205876071af8157d22ed6ee384f20a3c458609c2f76d
7
- data.tar.gz: 91e4466dce0c364f03ae29f8ee79491959ff99e75d3bf9cea32df7561f6fb74a434d780017b44ced948c2cccbc29ac85c230dd2b7529ff411c8f8825ad0eb706
6
+ metadata.gz: 1e7754f2bb28972767f75372bbc1ffca2c85143d57b3456fc1a9d8a796f1df0b54b656d6e495b1cf14bdf0231c046c9f5917b1f1941b58a4900ccd55be9950c1
7
+ data.tar.gz: 93fbf3cd6a7e65157fe8b79de043d8be8b99b7593d7a52f99b5f5170ebbe7bfff94f39fd66aea02413457c4c1c88b31f53f1abdaf3e8ae636f1bb1133b73a8bc
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A ruby library to interface with the classifier service
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/puppetclassify.svg)](https://badge.fury.io/rb/puppetclassify)
6
+
5
7
  ## How to install
6
8
 
7
9
  ```
@@ -27,7 +29,8 @@ require 'puppetclassify'
27
29
  auth_info = {
28
30
  "ca_certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/ca.pem",
29
31
  "certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/myhostname.vm.pem",
30
- "private_key_path" => "/etc/puppetlabs/puppet/ssl/private_keys/myhostname.vm.pem"
32
+ "private_key_path" => "/etc/puppetlabs/puppet/ssl/private_keys/myhostname.vm.pem",
33
+ "read_timeout" => 90 # optional timeout, defaults to 90 if this key doesn't exist
31
34
  }
32
35
 
33
36
  classifier_url = 'https://puppetmaster.local:4433/classifier-api'
@@ -57,6 +60,55 @@ group_delta = {"variables"=>{"key"=>"value"}, "id"=>my_group_id, "classes"=>{"mo
57
60
  puppetclassify.groups.update_group(group_delta)
58
61
  ```
59
62
 
63
+ ### Retrieving classification of a node
64
+
65
+ Because the Console classifies nodes based on rules, you may want to submit a
66
+ complete `facts` hash for rules to match. See [the API docs](https://docs.puppetlabs.com/pe/latest/nc_classification.html)
67
+ for examples.
68
+
69
+ You can retrieve facts for the local node either using Facter from Ruby or the
70
+ command line. For example:
71
+
72
+ ```ruby
73
+ #! /opt/puppetlabs/puppet/bin/ruby
74
+ require 'facter'
75
+
76
+ facts = { 'fact' => Facter.to_hash }
77
+ ```
78
+
79
+ or:
80
+
81
+ ```ruby
82
+ #! /usr/bin/env ruby
83
+ require 'json'
84
+
85
+ facts = { 'fact' => JSON.parse(`facter -j`) }
86
+ ```
87
+
88
+ Once you have the facts, retrieving classification of a node is simple:
89
+
90
+ ```ruby
91
+ #! /opt/puppetlabs/puppet/bin/ruby
92
+ require 'facter'
93
+ require 'puppetclassify'
94
+
95
+ # URL of classifier as well as certificates and private key for auth
96
+ auth_info = {
97
+ "ca_certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/ca.pem",
98
+ "certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/myhostname.vm.pem",
99
+ "private_key_path" => "/etc/puppetlabs/puppet/ssl/private_keys/myhostname.vm.pem"
100
+ }
101
+
102
+ classifier_url = 'https://puppetmaster.local:4433/classifier-api'
103
+ puppetclassify = PuppetClassify.new(classifier_url, auth_info)
104
+
105
+ # gather facts
106
+ facts = { 'fact' => Facter.to_hash }
107
+
108
+ # Get a node's classification
109
+ puppetclassify.classification.get('myhostname.puppetlabs.vm', facts)
110
+ ```
111
+
60
112
  ## Library Docs
61
113
 
62
114
  [rubydoc](http://www.rubydoc.info/gems/puppetclassify/0.1.0)
data/lib/puppet_https.rb CHANGED
@@ -7,7 +7,7 @@ class PuppetHttps
7
7
  # - ca_certificate_path
8
8
  # - certificate_path
9
9
  # - private_key_path
10
- #
10
+ # - read_timeout
11
11
 
12
12
  @settings = settings
13
13
  end
@@ -17,6 +17,7 @@ class PuppetHttps
17
17
  # connection.set_debug_output $stderr
18
18
  connection.use_ssl = true
19
19
  connection.ssl_version = :TLSv1
20
+ connection.read_timeout = @settings['read_timeout'] || 90 #A default timeout value in seconds
20
21
 
21
22
  connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
22
23
  ca_file = @settings['ca_certificate_path']
@@ -6,8 +6,13 @@ class Classification
6
6
  @puppet_https = puppet_https
7
7
  end
8
8
 
9
- def get(name)
10
- class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}")
9
+ def get(name, facts={})
10
+ unless facts.class == Hash
11
+ STDERR.puts "Facts should be a hash, not a #{facts.class}"
12
+ return false
13
+ end
14
+
15
+ class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}", facts.to_json)
11
16
 
12
17
  unless class_res.code.to_i == 200
13
18
  STDERR.puts "An error occured retreiving the classification of node #{name}: HTTP #{class_res.code} #{class_res.message}"
@@ -17,8 +22,13 @@ class Classification
17
22
  end
18
23
  end
19
24
 
20
- def explain(name)
21
- class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}/explanation")
25
+ def explain(name, facts={})
26
+ unless facts.class == Hash
27
+ STDERR.puts "Facts should be a hash, not a #{facts.class}"
28
+ return false
29
+ end
30
+
31
+ class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}/explanation", facts.to_json)
22
32
 
23
33
  unless class_res.code.to_i == 200
24
34
  STDERR.puts "An error occured retreiving the classification explanation of node #{name}: HTTP #{class_res.code} #{class_res.message}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetclassify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cain