Skip to content

Commit a0db439

Browse files
author
petergmurphy
committed
Make node_group_unpin accept an array of certnames
1 parent 1431087 commit a0db439

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

REFERENCE.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
* [`infrastatus`](#infrastatus): Runs puppet infra status and returns the output
7575
* [`mkdir_p_file`](#mkdir_p_file): Create a file with the specified content at the specified location
7676
* [`mv`](#mv): Wrapper task for mv command
77-
* [`node_group_unpin`](#node_group_unpin): Unpins a node from a specified PE node group
77+
* [`node_group_unpin`](#node_group_unpin): Unpins nodes from a specified PE node group
7878
* [`os_identification`](#os_identification): Return the operating system runnin gon the target as a string
7979
* [`pe_install`](#pe_install): Install Puppet Enterprise from a tarball
8080
* [`pe_ldap_config`](#pe_ldap_config): Set the ldap config in the PE console
@@ -1327,23 +1327,23 @@ New path of file
13271327

13281328
### <a name="node_group_unpin"></a>`node_group_unpin`
13291329

1330-
Unpins a node from a specified PE node group
1330+
Unpins nodes from a specified PE node group
13311331

13321332
**Supports noop?** false
13331333

13341334
#### Parameters
13351335

1336-
##### `node_certname`
1336+
##### `node_certnames`
13371337

1338-
Data type: `String`
1338+
Data type: `Array[String]`
13391339

1340-
The certname of the node to unpin
1340+
The certnames of the nodes to unpin
13411341

13421342
##### `group_name`
13431343

13441344
Data type: `String`
13451345

1346-
The name of the node group to unpin the node from
1346+
The name of the node group to unpin the nodes from
13471347

13481348
### <a name="os_identification"></a>`os_identification`
13491349

plans/convert.pp

+4-6
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,10 @@
282282
283283
# Unpin legacy compilers from PE Master group
284284
if $legacy_compiler_targets {
285-
$legacy_compiler_targets.each |$target| {
286-
run_task('peadm::node_group_unpin', $primary_target,
287-
node_certname => $target.peadm::certname(),
288-
group_name => 'PE Master',
289-
)
290-
}
285+
run_task('peadm::node_group_unpin', $primary_target,
286+
node_certnames => $legacy_compiler_targets.map |$target| { $target.peadm::certname() },
287+
group_name => 'PE Master',
288+
)
291289
}
292290
}
293291
else {

spec/plans/convert_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
expect_task('peadm::cert_data').return_for_targets('primary' => trustedjson)
2222
expect_task('peadm::read_file').always_return({ 'content' => '2021.7.9' })
2323
expect_task('peadm::get_group_rules').return_for_targets('primary' => { '_output' => '{"rules": []}' })
24-
expect_task('peadm::node_group_unpin').with_targets('primary').with_params({ 'node_certname' => 'legacy_compiler', 'group_name' => 'PE Master' })
24+
expect_task('peadm::node_group_unpin').with_targets('primary').with_params({ 'node_certnames' => ['legacy_compiler'], 'group_name' => 'PE Master' })
2525
expect_task('peadm::check_legacy_compilers').with_targets('primary').with_params({ 'legacy_compilers' => 'legacy_compiler' }).return_for_targets('primary' => { '_output' => '' })
2626

2727
# For some reason, expect_plan() was not working??

tasks/node_group_unpin.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"description": "Unpins a node from a specified PE node group",
2+
"description": "Unpins nodes from a specified PE node group",
33
"parameters": {
4-
"node_certname": {
5-
"type": "String",
6-
"description": "The certname of the node to unpin"
4+
"node_certnames": {
5+
"type": "Array[String]",
6+
"description": "The certnames of the nodes to unpin"
77
},
88
"group_name": {
99
"type": "String",
10-
"description": "The name of the node group to unpin the node from"
10+
"description": "The name of the node group to unpin the nodes from"
1111
}
1212
},
1313
"input_method": "stdin",

tasks/node_group_unpin.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
class NodeGroupUnpin
1111
def initialize(params)
1212
@params = params
13-
raise "Missing required parameter 'node_certname'" unless @params['node_certname']
13+
raise "Missing required parameter 'node_certnames'" unless @params['node_certnames']
14+
raise "'node_certnames' must be an array" unless @params['node_certnames'].is_a?(Array)
1415
raise "Missing required parameter 'group_name'" unless @params['group_name']
1516
@auth = YAML.load_file('/etc/puppetlabs/puppet/classifier.yaml')
1617
rescue Errno::ENOENT
@@ -44,12 +45,12 @@ def groups
4445
end
4546
end
4647

47-
def unpin_node(group, node)
48+
def unpin_node(group, nodes)
4849
raise 'Invalid group object' unless group.is_a?(Hash) && group['id'] && group['name']
4950

5051
net = https_client
5152
begin
52-
data = { "nodes": [node] }.to_json
53+
data = { "nodes": nodes }.to_json
5354
url = "/classifier-api/v1/groups/#{group['id']}/unpin"
5455

5556
req = Net::HTTP::Post.new(url)
@@ -60,11 +61,11 @@ def unpin_node(group, node)
6061

6162
case res.code
6263
when '204'
63-
puts "Successfully unpinned node '#{node}' from group '#{group['name']}'"
64+
puts "Successfully unpinned nodes '#{nodes.join(', ')}' from group '#{group['name']}'"
6465
else
6566
begin
6667
error_body = JSON.parse(res.body.to_s)
67-
raise "Failed to unpin node: #{error_body['kind'] || error_body}"
68+
raise "Failed to unpin nodes: #{error_body['kind'] || error_body}"
6869
rescue JSON::ParserError
6970
raise "Invalid response from server (status #{res.code}): #{res.body}"
7071
end
@@ -98,11 +99,11 @@ def dig(name, *args)
9899

99100
def execute!
100101
group_name = @params['group_name']
101-
node_certname = @params['node_certname']
102+
node_certnames = @params['node_certnames']
102103
group = groups.dig(group_name)
103104
if group
104-
unpin_node(group, node_certname)
105-
puts "Unpinned #{node_certname} from #{group_name}"
105+
unpin_node(group, node_certnames)
106+
puts "Unpinned #{node_certnames.join(', ')} from #{group_name}"
106107
else
107108
puts "Group #{group_name} not found"
108109
end

0 commit comments

Comments
 (0)