puppetclassify 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -34
- data/lib/puppetclassify.rb +9 -0
- data/lib/puppetclassify/commands.rb +23 -0
- data/lib/puppetclassify/groups.rb +0 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 523f6019b4d5b7deb67a65980e47f0be7f049b29
|
4
|
+
data.tar.gz: fc27b32eafa867ffabc950a03ec04ec42d2e5878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a9c9cc102ffe563c6237adbdd7b9e389c96103147f2b8126761acf73e6c871cbf906499c57541909c24e412b7c5a240dc8ea815116b8fb3b4572e138e2e212a
|
7
|
+
data.tar.gz: f6667db9fd1432e0852c0624f7d1b2899639501228eb4e5da68af248098d507ff640f67b7d22d5ad4a186c8bf8e846cfcdb170e38ef29a5e2b3213d29af44612
|
data/README.md
CHANGED
@@ -25,9 +25,7 @@ Tickets: Open an issue or pull request directly on this repository
|
|
25
25
|
|
26
26
|
## How to use
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
If you are wanting to get all of the groups the classifier knows about:
|
28
|
+
Here is the basic configuration you'll need to use the puppetclassify class:
|
31
29
|
|
32
30
|
```ruby
|
33
31
|
require 'puppetclassify'
|
@@ -41,6 +39,13 @@ auth_info = {
|
|
41
39
|
|
42
40
|
classifier_url = 'https://puppetmaster.local:4433/classifier-api'
|
43
41
|
puppetclassify = PuppetClassify.new(classifier_url, auth_info)
|
42
|
+
```
|
43
|
+
|
44
|
+
### Basic case
|
45
|
+
|
46
|
+
If you are wanting to get all of the groups the classifier knows about:
|
47
|
+
|
48
|
+
```ruby
|
44
49
|
# Get all the groups
|
45
50
|
puppetclassify.groups.get_groups
|
46
51
|
```
|
@@ -50,17 +55,6 @@ puppetclassify.groups.get_groups
|
|
50
55
|
If you have a group you want to modify, but do not know the group ID:
|
51
56
|
|
52
57
|
```ruby
|
53
|
-
require 'puppetclassify'
|
54
|
-
# URL of classifier as well as certificates and private key for auth
|
55
|
-
auth_info = {
|
56
|
-
"ca_certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/ca.pem",
|
57
|
-
"certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/myhostname.vm.pem",
|
58
|
-
"private_key_path" => "/etc/puppetlabs/puppet/ssl/private_keys/myhostname.vm.pem"
|
59
|
-
}
|
60
|
-
|
61
|
-
classifier_url = 'https://puppetmaster.local:4433/classifier-api'
|
62
|
-
puppetclassify = PuppetClassify.new(classifier_url, auth_info)
|
63
|
-
|
64
58
|
my_group_id = puppetclassify.groups.get_group_id("My Group Name")
|
65
59
|
group_delta = {"variables"=>{"key"=>"value"}, "id"=>my_group_id, "classes"=>{"motd"=>{"content"=>"hello!"}}} # an example to update a groups variables and classes
|
66
60
|
puppetclassify.groups.update_group(group_delta)
|
@@ -98,15 +92,7 @@ Once you have the facts, retrieving classification of a node is simple:
|
|
98
92
|
require 'facter'
|
99
93
|
require 'puppetclassify'
|
100
94
|
|
101
|
-
#
|
102
|
-
auth_info = {
|
103
|
-
"ca_certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/ca.pem",
|
104
|
-
"certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/myhostname.vm.pem",
|
105
|
-
"private_key_path" => "/etc/puppetlabs/puppet/ssl/private_keys/myhostname.vm.pem"
|
106
|
-
}
|
107
|
-
|
108
|
-
classifier_url = 'https://puppetmaster.local:4433/classifier-api'
|
109
|
-
puppetclassify = PuppetClassify.new(classifier_url, auth_info)
|
95
|
+
# NOTE: Add setup information here for puppetclassify
|
110
96
|
|
111
97
|
# gather facts
|
112
98
|
facts = { 'fact' => Facter.to_hash }
|
@@ -121,18 +107,9 @@ If you want to "pin" a node to a specific group so it gets that classification,
|
|
121
107
|
invoke the pin_nodes command. And if you want to remove nodes from that group, you can run
|
122
108
|
the unpin_nodes command.
|
123
109
|
|
124
|
-
|
125
|
-
require 'puppetclassify'
|
126
|
-
# URL of classifier as well as certificates and private key for auth
|
127
|
-
auth_info = {
|
128
|
-
"ca_certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/ca.pem",
|
129
|
-
"certificate_path" => "/etc/puppetlabs/puppet/ssl/certs/myhostname.vm.pem",
|
130
|
-
"private_key_path" => "/etc/puppetlabs/puppet/ssl/private_keys/myhostname.vm.pem"
|
131
|
-
}
|
132
|
-
|
133
|
-
classifier_url = 'https://puppetmaster.local:4433/classifier-api'
|
134
|
-
puppetclassify = PuppetClassify.new(classifier_url, auth_info)
|
110
|
+
If you want to remove nodes from every group they are pinned to, use the unpin_from_all command.
|
135
111
|
|
112
|
+
```ruby
|
136
113
|
my_group_id = puppetclassify.groups.get_group_id("My Super Awesome Group Name")
|
137
114
|
|
138
115
|
nodes = ["hostname.com", "myotherhost.com", "anotherhost.com"]
|
@@ -141,6 +118,9 @@ puppetclassify.groups.pin_nodes(my_group_id, nodes)
|
|
141
118
|
|
142
119
|
# unpin nodes from group
|
143
120
|
puppetclassify.groups.unpin_nodes(my_group_id, nodes)
|
121
|
+
|
122
|
+
# unpin nodes from EVERY group
|
123
|
+
puppetlcassify.commands.unpin_from_all(nodes)
|
144
124
|
```
|
145
125
|
|
146
126
|
## Library Docs
|
data/lib/puppetclassify.rb
CHANGED
@@ -9,6 +9,7 @@ require 'puppetclassify/validate'
|
|
9
9
|
require 'puppetclassify/rules'
|
10
10
|
require 'puppetclassify/last_class_update'
|
11
11
|
require 'puppetclassify/classification'
|
12
|
+
require 'puppetclassify/commands'
|
12
13
|
|
13
14
|
class PuppetClassify
|
14
15
|
def initialize(nc_api_url, https_settings)
|
@@ -95,4 +96,12 @@ class PuppetClassify
|
|
95
96
|
@classification = Classification.new(@nc_api_url, @puppet_https)
|
96
97
|
end
|
97
98
|
end
|
99
|
+
|
100
|
+
def commands
|
101
|
+
if @commands
|
102
|
+
@commands
|
103
|
+
else
|
104
|
+
@commands = Commands.new(@nc_api_url, @puppet_https)
|
105
|
+
end
|
106
|
+
end
|
98
107
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'puppet_https'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Commands
|
5
|
+
def initialize(nc_api_url, puppet_https)
|
6
|
+
@puppet_https = puppet_https
|
7
|
+
@nc_api_url = nc_api_url
|
8
|
+
end
|
9
|
+
|
10
|
+
def unpin_from_all(nodes)
|
11
|
+
all_nodes = {}
|
12
|
+
all_nodes['nodes'] = nodes
|
13
|
+
|
14
|
+
response = @puppet_https.post("#{@nc_api_url}/v1/commands/unpin-from-all", all_nodes.to_json)
|
15
|
+
|
16
|
+
unless response.code.to_i != 200
|
17
|
+
nodez = JSON.parse(response.body)
|
18
|
+
else
|
19
|
+
STDERR.puts "An error occured with your request: HTTP #{response.code} #{response.message}"
|
20
|
+
STDERR.puts response.body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cain
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- lib/puppetclassify.rb
|
22
22
|
- lib/puppetclassify/classes.rb
|
23
23
|
- lib/puppetclassify/classification.rb
|
24
|
+
- lib/puppetclassify/commands.rb
|
24
25
|
- lib/puppetclassify/environments.rb
|
25
26
|
- lib/puppetclassify/groups.rb
|
26
27
|
- lib/puppetclassify/import_hierarchy.rb
|
@@ -39,17 +40,17 @@ require_paths:
|
|
39
40
|
- lib
|
40
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
42
|
requirements:
|
42
|
-
- -
|
43
|
+
- - ">="
|
43
44
|
- !ruby/object:Gem::Version
|
44
45
|
version: '0'
|
45
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
47
|
requirements:
|
47
|
-
- -
|
48
|
+
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
49
50
|
version: '0'
|
50
51
|
requirements: []
|
51
52
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.
|
53
|
+
rubygems_version: 2.2.2
|
53
54
|
signing_key:
|
54
55
|
specification_version: 4
|
55
56
|
summary: Puppet Classify!
|