Skip to content

Commit 8736d4d

Browse files
authored
Merge pull request #33 from WhatsARanjit/config_data
Added Console config_data support
2 parents ae27e20 + 1da4d19 commit 8736d4d

File tree

10 files changed

+148
-43
lines changed

10 files changed

+148
-43
lines changed

.travis.yml

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
language: ruby
2-
env:
3-
- PUPPET_VERSION=4.7.0
4-
- PUPPET_VERSION=4.7.0
5-
- PUPPET_VERSION=4.6.2
6-
- PUPPET_VERSION=4.6.1
7-
- PUPPET_VERSION=4.5.2
8-
- PUPPET_VERSION=4.5.2
9-
- PUPPET_VERSION=4.5.1
10-
- PUPPET_VERSION=4.5.0
11-
- PUPPET_VERSION=4.4.2
12-
- PUPPET_VERSION=4.4.1
13-
- PUPPET_VERSION=4.4.0
14-
- PUPPET_VERSION=4.3.2
15-
- PUPPET_VERSION=4.3.2
16-
- PUPPET_VERSION=4.3.2
17-
- PUPPET_VERSION=4.3.1
18-
- PUPPET_VERSION=4.3.1
19-
- PUPPET_VERSION=4.3.0
20-
- PUPPET_VERSION=4.2.3
21-
- PUPPET_VERSION=4.2.2
22-
- PUPPET_VERSION=4.2.2
23-
- PUPPET_VERSION=4.2.2
24-
- PUPPET_VERSION=4.2.1
25-
- PUPPET_VERSION=4.2.0
26-
- PUPPET_VERSION=4.2.0
27-
- PUPPET_VERSION=4.1.0
28-
- PUPPET_VERSION=4.0.0
29-
- PUPPET_VERSION=3.8.1
30-
- PUPPET_VERSION=3.7.0
31-
rvm:
32-
- 2.2.0
33-
- 2.1.0
34-
- 2.0.0
2+
matrix:
3+
include:
4+
# 2017.3.1
5+
- rvm: 2.4.1
6+
env: PUPPET_VERSION=5.3.1
7+
# 2017.2.4
8+
- rvm: 2.1.9
9+
env: PUPPET_VERSION=4.10.8
10+
# 2017.1.0
11+
- rvm: 2.1.9
12+
env: PUPPET_VERSION=4.9.4
13+
# 2016.5.2
14+
- rvm: 2.1.9
15+
env: PUPPET_VERSION=4.8.2
16+
# 2016.4.7
17+
- rvm: 2.1.9
18+
env: PUPPET_VERSION=4.10.5
19+
# 2016.2.1
20+
- rvm: 2.1.9
21+
env: PUPPET_VERSION=4.5.2
22+
# 2016.1.2
23+
- rvm: 2.1.9
24+
env: PUPPET_VERSION=4.4.2
25+
# 2015.3.3
26+
- rvm: 2.1.8
27+
env: PUPPET_VERSION=4.3.2
28+
# 2015.2.3
29+
- rvm: 2.1.7
30+
env: PUPPET_VERSION=4.2.3
31+
# 3.8.6
32+
- rvm: 2.1.7
33+
env: PUPPET_VERSION=3.8.6
34+
# 3.7.1
35+
- rvm: 2.1.7
36+
env: PUPPET_VERSION=3.7.1
3537
script:
3638
- "bundle exec rake spec"

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2017-10-20 - Release 0.6.0
2+
3+
### Summary
4+
5+
- Added `pin` action to face
6+
- Added `data` parameter to `node_group` type for Console data
7+
- Added support for `data` parameter to `https` provider
8+
- Added `config_data` argument to puppet-less provider
9+
110
## 2017-08-20 - Release 0.5.0
211

312
### Summary

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ node_group { 'PE MCollective':
125125

126126
Default (empty array): `[]`
127127

128+
* `variables`
129+
130+
Global variables for the node group expressed in a hash as `{ 'var' => 'value' }`.
131+
132+
Default (empty hash): `{}`
133+
134+
* `data`
135+
136+
Configuration data supplied for automatic parameter lookup for the group.
137+
Data for the node group expressed in a hash as `{ 'class' => { 'param' => 'value' }}`.
138+
This parameter is supported for PE >=2017.3.x.
139+
140+
Default (empty hash): `{}`
141+
128142
## Functions
129143

130144
### node_groups()
@@ -142,7 +156,8 @@ Retrieve all or one node_group and its data.
142156
"rule"=>["and", ["~", "name", ".*"]],
143157
"variables"=>{}, "id"=>"00000000-0000-4000-8000-000000000000",
144158
"environment"=>"production",
145-
"classes"=>{}
159+
"classes"=>{},
160+
"config_data"=>{}
146161
},
147162
"Production environment"=>{
148163
"environment_trumps"=>false,
@@ -152,7 +167,8 @@ Retrieve all or one node_group and its data.
152167
"variables"=>{},
153168
"id"=>"7233f964-951e-4a7f-88ea-72676ed3104d",
154169
"environment"=>"production",
155-
"classes"=>{}
170+
"classes"=>{},
171+
"config_data"=>{}
156172
},
157173
...
158174
}
@@ -169,7 +185,8 @@ Retrieve all or one node_group and its data.
169185
"rule"=>["and", ["~", "name", ".*"]],
170186
"variables"=>{}, "id"=>"00000000-0000-4000-8000-000000000000",
171187
"environment"=>"production",
172-
"classes"=>{}
188+
"classes"=>{},
189+
"config_data"=>{}
173190
}
174191
}
175192
```
@@ -199,6 +216,7 @@ ACTIONS:
199216
classified List classification information
200217
environments Query environment sync status
201218
groups List group information
219+
pin Pin a node to a group
202220
unpin Unpin a node from all groups
203221
204222
See 'puppet man node_manager' or 'man puppet-node_manager' for full help.

lib/puppet/face/node_manager.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@
141141
end
142142
end
143143

144+
action :pin do
145+
summary 'Pin a node to a group'
146+
arguments 'nodename'
147+
148+
option '--node_group GROUP' do
149+
summary 'Node group to pin to'
150+
default_to { '00000000-0000-4000-8000-000000000000' }
151+
end
152+
153+
when_invoked do |*args|
154+
nodename = args.first
155+
options = args.last
156+
require 'pry'; binding.pry
157+
158+
if options[:node_group]
159+
'Success' if classifier.pin_node(nodename, options[:node_group])
160+
else
161+
end
162+
end
163+
164+
when_rendering :console do |output|
165+
case output
166+
when Hash
167+
if output.length <= 1
168+
JSON.pretty_generate output.values[0]
169+
else
170+
output.keys
171+
end
172+
else
173+
output
174+
end
175+
end
176+
end
177+
144178
action :unpin do
145179
summary 'Unpin a node from all groups'
146180
arguments 'nodename'

lib/puppet/provider/node_group/https.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def self.friendly_name
3434
:rule => 'rule',
3535
:variables => 'variables',
3636
:description => 'description',
37+
:config_data => 'data',
3738
}
3839
end
3940

@@ -82,6 +83,7 @@ def create
8283
key = k.to_s
8384
# key changed for usability
8485
key = 'environment_trumps' if key == 'override_environment'
86+
key = 'config_data' if key == 'data'
8587
send_data[key] = v
8688
end
8789
# namevar may not be in this hash
@@ -135,6 +137,11 @@ def classes
135137
PuppetX::Node_manager::Common.sort_hash(@property_hash[:classes])
136138
end
137139

140+
def data
141+
# Need to deep sort hashes so they be evaluated equally
142+
PuppetX::Node_manager::Common.sort_hash(@property_hash[:data])
143+
end
144+
138145
def rule
139146
@property_hash[:rule].nil? ? [''] : @property_hash[:rule]
140147
end
@@ -148,11 +155,11 @@ def rule
148155
gindex = $ngs.index { |i| i['name'] == value }
149156
@property_flush['attrs'][property.to_s] = $ngs[gindex]['id']
150157
end
151-
# These 2 attributes are additive, so need to submit nulls to remove unwanted values
152-
elsif [:variables, :classes].include?(property)
153-
@property_flush['attrs'][property.to_s] = add_nulls(@property_hash[property], value)
158+
# These 3 attributes are additive, so need to submit nulls to remove unwanted values
159+
elsif [:variables, :classes, :config_data].include?(property)
160+
@property_flush['attrs'][property.to_s] = add_nulls(@property_hash[friendly.to_sym], value)
154161
# For logging return to original intended value
155-
@resource[property] = value.select { |k,v| v != nil }
162+
@resource[friendly.to_sym] = value.select { |k,v| v != nil }
156163
else
157164
# The to_json function needs to recognize
158165
# booleans true/false, not symbols :true/false
@@ -198,7 +205,9 @@ def add_nulls(current, new)
198205

199206
allkeys.each do |k|
200207
if new[k].is_a?(Hash)
201-
newhash[k] = add_nulls(current[k], new[k])
208+
# Push forward an empty hash if nothing is there
209+
_current = current.is_a?(Hash) ? current[k] : {}
210+
newhash[k] = add_nulls(_current, new[k])
202211
else
203212
newhash[k] = new[k] || nil
204213
end

lib/puppet/type/node_group.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@
4646
PuppetX::Node_manager::Common.sort_hash(value)
4747
end
4848
end
49+
newproperty(:data) do
50+
desc 'Data applied to this group'
51+
#defaultto {}
52+
validate do |value|
53+
fail("Data must be supplied as a hash") unless value.is_a?(Hash)
54+
end
55+
# Need to deep sort hashes so they be evaluated equally
56+
munge do |value|
57+
PuppetX::Node_manager::Common.sort_hash(value)
58+
end
59+
end
4960
newproperty(:description) do
5061
desc 'Description of this group'
5162
end

lib/puppet/util/nc_https.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ def get_classified(name, expl = false, facts = {}, trusted = {})
137137
end
138138
end
139139

140+
def pin_node(node, group_id)
141+
data = { 'nodes' => node, }
142+
res = do_https("v1/groups/#{group_id}/pin", 'POST', data)
143+
require 'pry'; binding.pry
144+
if res.code.to_i != 204
145+
Puppet.debug("Response code: #{res.code}")
146+
Puppet.debug("Response message: #{res.body}")
147+
else
148+
JSON.parse(res.body)
149+
end
150+
end
151+
140152
def unpin_from_all(node)
141153
data = { 'nodes' => [node] }
142154
res = do_https('v1/commands/unpin-from-all', 'POST', data)

metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "WhatsARanjit-node_manager",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"author": "WhatsARanjit",
55
"summary": "Create and manage PE Console node groups as resources.",
66
"license": "Apache-2.0",
@@ -50,7 +50,7 @@
5050
"requirements": [
5151
{
5252
"name": "puppet",
53-
"version_requirement": ">= 3.7.1 < 5.0.0"
53+
"version_requirement": ">= 3.7.1 < 6.0.0"
5454
}
5555
],
5656
"description": "Node_manager module"

scripts/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Usage: ./node_group.sh [options] [UID]
6161
-v| --variables Variables to set in the group.
6262
Example: '{ "foo": "bar" }'
6363
64+
-a| --config_data Configuration data for the group.
65+
Example: '{ "vim": { "vim_package": "vim-common" } }'
66+
6467
-h| --help Display this help message.
6568
```
6669

scripts/node_group.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Usage: $0 [options] [UID]\n
2222
\t \t\t Example: '["or", ["=", "name", "node.whatsaranjit.com"]]'\n\n
2323
-v| --variables \t Variables to set in the group.\n
2424
\t \t\t Example: '{ "foo": "bar" }'\n\n
25+
-a| --config_data \t Configuration data for the group.\n
26+
\t \t\t Example: '{ "vim": { "vim_package": "vim-common" } }'\n\n
2527
-h| --help \t\t Display this help message.\n
2628
EOF`
2729
@@ -110,6 +112,11 @@ else
110112
DATA="${DATA} \"variables\": $VARIABLES,"
111113
shift
112114
;;
115+
-a|--config_data)
116+
CONFIG_DATA="$2"
117+
DATA="${DATA} \"config_data\": ${CONFIG_DATA},"
118+
shift
119+
;;
113120
*)
114121
(>&2 echo "Invalid options supplied!"); exit 1
115122
;;

0 commit comments

Comments
 (0)