Showing with 101 additions and 13 deletions.
  1. +10 −0 CHANGELOG.md
  2. +46 −2 README.md
  3. +19 −6 lib/puppet/face/node_manager.rb
  4. +25 −4 lib/puppet/util/nc_https.rb
  5. +1 −1 metadata.json
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2019-06-20 - Release 0.7.2

### Summary

- `Update to allow get_nodes() without argument`

#### Bugfixes

- Unpin actions had an errant pry statement

## 2018-03-15 - Release 0.7.1

## Summary
Expand Down
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# node_manager [![Build Status](https://travis-ci.org/WhatsARanjit/prosvcs-node_manager.svg)](https://travis-ci.org/WhatsARanjit/prosvcs-node_manager)
# node_manager [![Build Status](https://travis-ci.org/WhatsARanjit/puppet-node_manager.svg?branch=master)](https://travis-ci.org/WhatsARanjit/puppet-node_manager)

#### Table of Contents

Expand All @@ -11,6 +11,7 @@
* [update_classes](#update_classes)
1. [Functions](#functions)
* [node_groups()](#node_groups)
* [get_nodes()](#get_nodes)
1. [Face](#face)
1. [Things to do](#things-to-do)
1. [Experimental](#experimental)
Expand Down Expand Up @@ -201,6 +202,49 @@ Retrieve all or one node_group and its data.

_Type:_ rvalue

### get_nodes()

Retrieve historical info about a node's check-ins and classification, if check-in storage is enabled.

`get_nodes(nodename)` will return:

```puppet
{
"name": "Deep Space 9",
"check_ins": [
{
"time": "2369-01-04T03:00:00Z",
"explanation": {
"53029cf7-2070-4539-87f5-9fc754a0f041": {
"value": true,
"form": [
"and",
{
"value": true,
"form": [">=", {"path": ["fact", "pressure hulls"], "value": "3"}, "1"]
},
{
"value": true,
"form": ["=", {"path": ["fact", "warp cores"], "value": "0"}, "0"]
},
{
"value": true,
"form": [">" {"path": ["fact", "docking ports"], "value": "18"}, "9"]
}
]
}
}
}
],
"transaction_uuid": "d3653a4a-4ebe-426e-a04d-dbebec00e97f"
}
```

`get_nodes()` (without the nodename argument) is deprecated, but is included for coverage of the API. It
will return the same structure, but for all nodes with their historical check-in information.

_Type:_ rvalue

## Face

The `node_manager` face allows you to interact with endpoints other than
Expand All @@ -225,7 +269,7 @@ ACTIONS:
environments Query environment sync status
groups List group information
pin Pin a node to a group
unpin Unpin a node from all groups
unpin Unpin a node from groups
See 'puppet man node_manager' or 'man puppet-node_manager' for full help.
```
Expand Down
25 changes: 19 additions & 6 deletions lib/puppet/face/node_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
when_invoked do |*args|
nodename = args.first
options = args.last
require 'pry'; binding.pry

if options[:node_group]
'Success' if classifier.pin_node(nodename, options[:node_group])
Expand All @@ -176,15 +175,29 @@
end

action :unpin do
summary 'Unpin a node from all groups'
summary 'Unpin a node from a group'
arguments 'nodename'

option '--all' do
summary 'Unpin a node from all groups'
default_to { false }
end

option '--node_group GROUP' do
summary 'Node group to unpin from'
default_to { '00000000-0000-4000-8000-000000000000' }
end

when_invoked do |nodename, options|
output << classifier.unpin_from_all(nodename)
if output.flatten.first['nodes'].empty?
'Found nothing to unpin.'
if options[:all]
output << classifier.unpin_from_all(nodename)
if output.flatten.first['nodes'].empty?
'Found nothing to unpin.'
else
PuppetX::Node_manager::Common.hashify_group_array(output.flatten.first['nodes'])
end
else
PuppetX::Node_manager::Common.hashify_group_array(output.flatten['nodes'].first)
'Success' if classifier.unpin_node(nodename, options[:node_group])
end
end

Expand Down
29 changes: 25 additions & 4 deletions lib/puppet/util/nc_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,22 @@ def get_classified(name, expl = false, facts = {}, trusted = {})
end

def pin_node(node, group_id)
data = { 'nodes' => node, }
data = { 'nodes' => [node], }
res = do_https("v1/groups/#{group_id}/pin", 'POST', data)
require 'pry'; binding.pry
if res.code.to_i != 204
error_msg(res)
else
JSON.parse(res.body)
(JSON.parse(res.body) if res.body) || true
end
end

def unpin_node(node, group_id)
data = { 'nodes' => [node], }
res = do_https("v1/groups/#{group_id}/unpin", 'POST', data)
if res.code.to_i != 204
error_msg(res)
else
(JSON.parse(res.body) if res.body) || true
end
end

Expand All @@ -146,7 +155,7 @@ def unpin_from_all(node)
if res.code.to_i != 200
error_msg(res)
else
JSON.parse(res.body)
(JSON.parse(res.body) if res.body) || true
end
end

Expand All @@ -155,6 +164,18 @@ def get_environments
JSON.parse(res.body)
end

def get_nodes(name)
url_array = [ 'v1/nodes' ]
url_array << name if name
res = do_https(url_array.join('/'), 'GET')
if res.code.to_i != 200
error_msg(res)
fail('Unable to get nodes history')
else
JSON.parse(res.body)
end
end

private

def do_https(endpoint, method = 'post', data = {})
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WhatsARanjit-node_manager",
"version": "0.7.1",
"version": "0.7.2",
"author": "WhatsARanjit",
"summary": "Create and manage PE Console node groups as resources.",
"license": "Apache-2.0",
Expand Down