ruby-puppetdb 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dec863ab919696114a9da121aaec40fd31a90e05
4
- data.tar.gz: 0dd5e7af4d6e2cc1111cd29692d63aafd6d8e2e9
3
+ metadata.gz: 5569486583593818bed45ac2208b2a6a875ce35f
4
+ data.tar.gz: 7e13f8e92ef8f91b4e05643876947d397ca92d5d
5
5
  SHA512:
6
- metadata.gz: 02a0770ac9e9428807f2a4142d4d9adbf9ea934b89219176f5ddf7749105a1316fba9a554f297619d9a14c34ffe737f20a4a8980e84448872c3998fc44fe0207
7
- data.tar.gz: 8c5f1a6c02450204db7604007c5250c6a46701dc7d97c97dd60588cefdcb60d76b62df385b89d9e7142279a055b415512fa51ef2955134c01b4bc8ee2fb52e61
6
+ metadata.gz: 03e22ffda9c02509223899f74225ef062eb6533ebb105857806b6e78cee788f50ddd22c772ab9f273b17f93a5627990a5693c53991beecc8ba14fd38be21c71e
7
+ data.tar.gz: d10869a0c16d5774f5301c179e386ce5a4a632e1522b7dcea595335bb5cc8d5b68c6c91e99305e895df563ffdf0d0395cdc4206eb2df143cc81dd4980239da28
@@ -51,9 +51,22 @@ Puppet::Face.define(:query, '1.0.0') do
51
51
 
52
52
  arguments "<query>"
53
53
 
54
+ option '--node_info BOOLEAN' do
55
+ summary 'return full info about each node or just name'
56
+ description <<-EOT
57
+ If true the full information about each host is returned including fact, report and catalog timestamps.
58
+ EOT
59
+ default_to { false }
60
+ end
61
+
54
62
  when_invoked do |query, options|
55
63
  puppetdb = PuppetDB::Connection.new options[:puppetdb_host], options[:puppetdb_port]
56
- puppetdb.query(:nodes, puppetdb.parse_query(query, :nodes))
64
+ nodes = puppetdb.query(:nodes, puppetdb.parse_query(query, :nodes))
65
+ if options[:node_info]
66
+ nodes
67
+ else
68
+ nodes.collect { |node| node['name'] } unless options[:node_info]
69
+ end
57
70
  end
58
71
 
59
72
  end
@@ -2,9 +2,7 @@ require 'puppetdb'
2
2
 
3
3
  class PuppetDB::Connection
4
4
  require 'rubygems'
5
- require 'puppet'
6
5
  require 'puppetdb/parser'
7
- require 'puppet/network/http_pool'
8
6
  require 'uri'
9
7
  require 'json'
10
8
 
@@ -31,7 +29,11 @@ class PuppetDB::Connection
31
29
  # @param nodequery [Array] the query to find the nodes to fetch facts for
32
30
  # @return [Hash] a hash of hashes with facts for each node mathing query
33
31
  def facts(facts, nodequery, http=nil)
34
- q = ['and', ['in', 'certname', ['extract', 'certname', ['select-facts', nodequery]]], ['or', *facts.collect { |f| ['=', 'name', f]}]]
32
+ if facts.empty?
33
+ q = ['in', 'certname', ['extract', 'certname', ['select-facts', nodequery]]]
34
+ else
35
+ q = ['and', ['in', 'certname', ['extract', 'certname', ['select-facts', nodequery]]], ['or', *facts.collect { |f| ['=', 'name', f]}]]
36
+ end
35
37
  facts = {}
36
38
  query(:facts, q, http).each do |fact|
37
39
  if facts.include? fact['certname'] then
@@ -49,7 +51,10 @@ class PuppetDB::Connection
49
51
  # @param query [Array] query to execute
50
52
  # @return [Array] the results of the query
51
53
  def query(endpoint, query=nil, http=nil)
52
- http ||= Puppet::Network::HttpPool.http_instance(@host, @port, @use_ssl)
54
+ unless http then
55
+ require 'puppet/network/http_pool'
56
+ http = Puppet::Network::HttpPool.http_instance(@host, @port, @use_ssl)
57
+ end
53
58
  headers = { "Accept" => "application/json" }
54
59
 
55
60
  uri = "/v2/#{endpoint.to_s}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-puppetdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Bode
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json