knife-chef-inventory 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 891a467a33c1abb7858971a44f1fe4bf5a3ca027
4
- data.tar.gz: 821c5da2b406afddd996d41256c46987fd87408d
3
+ metadata.gz: f91812999c2632572f1862649d09185a48168365
4
+ data.tar.gz: 049e4042535631445f08bc3f76778a269b566b71
5
5
  SHA512:
6
- metadata.gz: bd37739b7bcd75d96a883690a91cfcfe555e6ef4fa2b5fd5ae9873e6491675ec44a206a44d2e7853759f0562f6b2f511a8bc9c3a7dc544973388041faa0b55f4
7
- data.tar.gz: f61c912efc5a9db935c6307e8a4a52434922637569327363e8fea9d1f366e19fc3303496e7448cb8076bddde4b6a6e19906b3cf63558a77bea3a36f6598c09cb
6
+ metadata.gz: 53026cc6ccf258fd7bd223a548cc9c9f9022c73e4bae4baa421aabc408edd73afb3c5744b8b26005b6c6266ff6d8a1bd5b9dc5756efc5fd6f4906bc2f24c83f2
7
+ data.tar.gz: ea2aebfd0fe1456a9802d874a9db92cc92f26b235e998ed47e4694c1d39ca73109e18e377b29b75744f108715c2b7e04afd22fc9cc7ae5ab33b56db4dd3c39c6
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.2.1](https://github.com/brentm5/knife-chef-inventory/tree/v0.2.1) (2016-08-19)
4
+ [Full Changelog](https://github.com/brentm5/knife-chef-inventory/compare/v0.2.0...v0.2.1)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Improve performance by switching to partial search [\#14](https://github.com/brentm5/knife-chef-inventory/pull/14) ([brentm5](https://github.com/brentm5))
9
+ - Fix issue where only first 1000 nodes get returned [\#13](https://github.com/brentm5/knife-chef-inventory/pull/13) ([brentm5](https://github.com/brentm5))
10
+ - Fix deprecation warnings for chef 13 when accessing nodes [\#10](https://github.com/brentm5/knife-chef-inventory/pull/10) ([brentm5](https://github.com/brentm5))
11
+
3
12
  ## [v0.2.0](https://github.com/brentm5/knife-chef-inventory/tree/v0.2.0) (2016-08-16)
4
13
  [Full Changelog](https://github.com/brentm5/knife-chef-inventory/compare/v0.1.0...v0.2.0)
5
14
 
@@ -12,16 +21,9 @@
12
21
 
13
22
  **Merged pull requests:**
14
23
 
15
- - Add changelog generator and cleanup naming [\#7](https://github.com/brentm5/knife-chef-inventory/pull/7) ([brentm5](https://github.com/brentm5))
16
24
  - Update banner for inventory\_cookbook.rb [\#6](https://github.com/brentm5/knife-chef-inventory/pull/6) ([afiune](https://github.com/afiune))
17
- - Add more information to readme [\#4](https://github.com/brentm5/knife-chef-inventory/pull/4) ([brentm5](https://github.com/brentm5))
18
- - Add more to the readme and fix travis [\#3](https://github.com/brentm5/knife-chef-inventory/pull/3) ([brentm5](https://github.com/brentm5))
19
25
 
20
26
  ## [v0.0.1](https://github.com/brentm5/knife-chef-inventory/tree/v0.0.1) (2016-05-12)
21
- **Merged pull requests:**
22
-
23
- - Update to be called knife-chef-inventory [\#2](https://github.com/brentm5/knife-chef-inventory/pull/2) ([brentm5](https://github.com/brentm5))
24
-
25
27
 
26
28
 
27
29
  \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_ruby_version = "~> 2.1"
21
21
 
22
- s.add_dependency "chef", "<= 12.11.18"
22
+ s.add_dependency "chef", "~> 12.11"
23
23
 
24
24
  s.add_development_dependency "bundler", "~> 1.6"
25
25
  s.add_development_dependency "rake", "~> 11.1"
@@ -1,9 +1,10 @@
1
- # frozen_string_literal: true
2
1
  require "chef/knife"
2
+ require "knife-chef-inventory/shared"
3
3
 
4
4
  class Chef
5
5
  class Knife
6
6
  class InventoryChefClient < Knife
7
+ include KnifeChefInventory::Shared
7
8
  banner "knife inventory chef_client"
8
9
 
9
10
  deps do
@@ -35,14 +36,21 @@ class Chef
35
36
  @client_version_nodes ||= search_nodes("chef_packages_chef_version:#{@client_version}")
36
37
  end
37
38
 
38
- def search_nodes(query)
39
- Chef::Search::Query.new.search(:node, query).first
39
+ def search_args
40
+ {
41
+ rows: max_results,
42
+ filter_result: {
43
+ name: ["name"],
44
+ chef_version: %w(chef_packages chef version),
45
+ ohai_time: ["ohai_time"]
46
+ }
47
+ }
40
48
  end
41
49
 
42
50
  def client_usage_per_version
43
51
  version_map = Hash.new(0)
44
52
  all_nodes.each do |node|
45
- version = node.chef_packages.chef.version
53
+ version = node["chef_version"]
46
54
 
47
55
  version_map[version] += 1
48
56
  end
@@ -61,14 +69,10 @@ class Chef
61
69
  ui.info "#{version} is used by #{client_usage} hosts" if client_usage > 0
62
70
  end
63
71
 
64
- def time_since(timestamp)
65
- (Time.now - Time.at(timestamp)).to_i / 60
66
- end
67
-
68
72
  def output_version_analysis
69
73
  ui.info "Client Versions being used"
70
- client_version_nodes.sort_by(&:ohai_time).each do |node|
71
- ui.info "#{node.name} - #{time_since(node.ohai_time)} Minutes"
74
+ client_version_nodes.sort_by { |node| node["ohai_time"] }.each do |node|
75
+ ui.info "#{node['name']} - #{time_since(node['ohai_time'])} Minutes"
72
76
  end
73
77
  end
74
78
 
@@ -1,9 +1,10 @@
1
- # frozen_string_literal: true
2
1
  require "chef/knife"
2
+ require "knife-chef-inventory/shared"
3
3
 
4
4
  class Chef
5
5
  class Knife
6
6
  class InventoryCookbook < Knife
7
+ include KnifeChefInventory::Shared
7
8
  banner "knife inventory cookbook COOKBOOK [VERSION] (options)"
8
9
 
9
10
  deps do
@@ -67,8 +68,15 @@ class Chef
67
68
  @environment_versions
68
69
  end
69
70
 
70
- def search_nodes(query)
71
- Chef::Search::Query.new.search(:node, query).first
71
+ def search_args
72
+ {
73
+ rows: max_results,
74
+ filter_result: {
75
+ name: ["name"],
76
+ cookbook_version: ["cookbooks", @cookbook_name, "version"],
77
+ ohai_time: ["ohai_time"]
78
+ }
79
+ }
72
80
  end
73
81
 
74
82
  def all_cookbook_versions
@@ -78,7 +86,7 @@ class Chef
78
86
  def cookbook_usage_per_version
79
87
  version_map = Hash.new(0)
80
88
  cookbook_nodes.each do |node|
81
- version = node.cookbooks[@cookbook_name].version
89
+ version = node["cookbook_version"]
82
90
 
83
91
  version_map[version] += 1
84
92
  end
@@ -104,14 +112,10 @@ class Chef
104
112
  end
105
113
  end
106
114
 
107
- def time_since(timestamp)
108
- (Time.now - Time.at(timestamp)).to_i / 60
109
- end
110
-
111
115
  def output_version_analysis
112
116
  ui.info "Cookbook Versions being used for #{@cookbook_name}"
113
- cookbook_version_nodes.sort_by(&:ohai_time).each do |node|
114
- ui.info "#{node.name} - #{time_since(node.ohai_time)} Minutes"
117
+ cookbook_version_nodes.sort_by { |node| node["ohai_time"] }.each do |node|
118
+ ui.info "#{node['name']} - #{time_since(node['ohai_time'])} Minutes"
115
119
  end
116
120
  end
117
121
 
@@ -0,0 +1,15 @@
1
+ module KnifeChefInventory
2
+ module Shared
3
+ def time_since(timestamp)
4
+ (Time.now - Time.at(timestamp)).to_i / 60
5
+ end
6
+
7
+ def search_nodes(query)
8
+ Chef::Search::Query.new.search(:node, query, search_args).first
9
+ end
10
+
11
+ def max_results
12
+ Chef::Node.list.count || 1000
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Knife
3
3
  module ChefInventory
4
- VERSION = "0.2.0".freeze
4
+ VERSION = "0.2.1".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-chef-inventory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Montague
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-16 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 12.11.18
19
+ version: '12.11'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "<="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 12.11.18
26
+ version: '12.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +99,7 @@ files:
99
99
  - knife-chef-inventory.gemspec
100
100
  - lib/chef/knife/inventory_chef_client.rb
101
101
  - lib/chef/knife/inventory_cookbook.rb
102
+ - lib/knife-chef-inventory/shared.rb
102
103
  - lib/knife-chef-inventory/version.rb
103
104
  - tasks/changelog.rake
104
105
  homepage: https://github.com/brentm5/knife-chef-inventory