initial commit
This commit just adds support for the ability to query classes, nodes, and groups out of the dashboard.
This commit is contained in:
5
lib/puppet/application/dashboard.rb
Normal file
5
lib/puppet/application/dashboard.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
require 'puppet/face'
|
||||||
|
require 'puppet/application/face_base'
|
||||||
|
|
||||||
|
class Puppet::Application::Dashboard < Puppet::Application::FaceBase
|
||||||
|
end
|
||||||
36
lib/puppet/dashboard/classifier.rb
Normal file
36
lib/puppet/dashboard/classifier.rb
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
require 'puppet'
|
||||||
|
require 'puppet/network/http_pool'
|
||||||
|
module Puppet::Dashboard
|
||||||
|
class Classifier
|
||||||
|
|
||||||
|
def self.connection(options)
|
||||||
|
@connection ||= Puppet::Dashboard::Classifier.new(options, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(options, use_ssl=false)
|
||||||
|
@http_connection = Puppet::Network::HttpPool.http_instance(options[:enc_server], options[:enc_port])
|
||||||
|
# Workaround for the fact that Dashboard is typically insecure.
|
||||||
|
@http_connection.use_ssl = use_ssl
|
||||||
|
@headers = { 'Content-Type' => 'application/json' }
|
||||||
|
end
|
||||||
|
|
||||||
|
# list expects a return of 200
|
||||||
|
def list(type, action)
|
||||||
|
response = @http_connection.get("/#{type}.json", @headers )
|
||||||
|
nodes = handle_json_response(response, action)
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_json_response(response, action, expected_code='200')
|
||||||
|
if response.code == expected_code
|
||||||
|
Puppet.notice "#{action} ... Done"
|
||||||
|
PSON.parse response.body
|
||||||
|
else
|
||||||
|
# I should probably raise an exception!
|
||||||
|
Puppet.warning "#{action} ... Failed"
|
||||||
|
Puppet.info("Body: #{response.body}")
|
||||||
|
Puppet.warning "Server responded with a #{response.code} status"
|
||||||
|
raise Puppet::Error, "Could not: #{action}, got #{response.code} expected #{expected_code}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
37
lib/puppet/face/dashboard.rb
Normal file
37
lib/puppet/face/dashboard.rb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
require 'puppet/face'
|
||||||
|
require 'puppet/dashboard/classifier'
|
||||||
|
Puppet::Face.define(:dashboard, '0.0.1') do
|
||||||
|
option '--enc-server=' do
|
||||||
|
summary 'The External Node Classifier URL.'
|
||||||
|
description <<-EOT
|
||||||
|
The URL of the External Node Classifier.
|
||||||
|
This currently only supports the Dashboard
|
||||||
|
as an external node classifier.
|
||||||
|
EOT
|
||||||
|
default_to do
|
||||||
|
Puppet[:server]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
option '--enc-port=' do
|
||||||
|
summary 'The External Node Classifier Port'
|
||||||
|
description <<-EOT
|
||||||
|
The port of the External Node Classifier.
|
||||||
|
This currently only supports the Dashboard
|
||||||
|
as an external node classifier.
|
||||||
|
EOT
|
||||||
|
default_to do
|
||||||
|
3000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
action 'list' do
|
||||||
|
summary 'list all of a certain type from the dashboard, this currently supports the ability to list: classes, nodes, and groups'
|
||||||
|
when_invoked do |type, options|
|
||||||
|
type_map = {'classes' => 'node_classes', 'nodes' => 'nodes', 'groups' => 'node_groups'}
|
||||||
|
connection = Puppet::Dashboard::Classifier.connection(options)
|
||||||
|
connection.list(type_map[type], "Listing #{type}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user