knife-preflight 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/preflight.rb +37 -70
- metadata +30 -49
data/lib/chef/knife/preflight.rb
CHANGED
@@ -58,86 +58,53 @@ module KnifePreflight
|
|
58
58
|
exit 1
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
result_count_nodes = perform_query(raw_query, 'node')
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
if !raw_query.include? "::"
|
66
|
-
node_query = "recipes:*#{escaped_query} OR recipes:*#{escaped_query}\\:\\:default"
|
67
|
-
ui.msg("Searching for nodes containing #{raw_query} OR #{raw_query}::default in their expanded run_list...\n")
|
68
|
-
elsif raw_query.include? "::default"
|
69
|
-
node_query = "recipes:*#{escaped_query} OR recipes:*#{escaped_query.gsub( "\\:\\:default","")}"
|
70
|
-
ui.msg("Searching for nodes containing #{raw_query} OR #{raw_query.gsub( "::default","")} in their expanded run_list...\n")
|
71
|
-
else
|
72
|
-
node_query = "recipes:*#{escaped_query}"
|
73
|
-
ui.msg("Searching for nodes containing #{raw_query} in their expanded run_list...\n")
|
74
|
-
end
|
75
|
-
query_nodes = URI.escape(node_query,
|
76
|
-
Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
77
|
-
|
78
|
-
result_items_nodes = []
|
79
|
-
result_count_nodes = 0
|
80
|
-
|
81
|
-
rows = config[:rows]
|
82
|
-
start = config[:start]
|
83
|
-
begin
|
84
|
-
q_nodes.search('node', query_nodes, config[:sort], start, rows) do |node_item|
|
85
|
-
formatted_item_node = format_for_display(node_item)
|
86
|
-
if formatted_item_node.respond_to?(:has_key?) && !formatted_item_node.has_key?('id')
|
87
|
-
formatted_item_node['id'] = node_item.has_key?('id') ? node_item['id'] : node_item.name
|
88
|
-
end
|
89
|
-
result_items_nodes << formatted_item_node
|
90
|
-
result_count_nodes += 1
|
91
|
-
end
|
92
|
-
rescue Net::HTTPServerException => e
|
93
|
-
msg = Chef::JSONCompat.from_json(e.response.body)["error"].first
|
94
|
-
ui.error("knife preflight failed: #{msg}")
|
95
|
-
exit 1
|
96
|
-
end
|
63
|
+
result_count_roles = perform_query(raw_query, 'role')
|
97
64
|
|
98
|
-
|
99
|
-
|
100
|
-
else
|
101
|
-
ui.msg "#{result_count_nodes} Nodes found"
|
102
|
-
ui.msg("\n")
|
103
|
-
result_items_nodes.each do |item|
|
104
|
-
output(item.name)
|
105
|
-
end
|
106
|
-
end
|
65
|
+
ui.msg("Found #{result_count_nodes} nodes and #{result_count_roles} roles using the specified search criteria")
|
66
|
+
end
|
107
67
|
|
108
|
-
|
109
|
-
|
68
|
+
def perform_query(raw_query, type='node')
|
69
|
+
q = Chef::Search::Query.new
|
110
70
|
|
71
|
+
# strip default if it exists to simplify logic
|
72
|
+
raw_query = raw_query.sub("::default", "")
|
73
|
+
escaped_query = raw_query.sub( "::", "\\:\\:")
|
111
74
|
|
112
|
-
q_roles = Chef::Search::Query.new
|
113
|
-
|
114
75
|
if !raw_query.include? "::"
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
76
|
+
if type == 'node'
|
77
|
+
search_query = "recipes:*#{escaped_query} OR recipes:*#{escaped_query}\\:\\:default"
|
78
|
+
search_query += " OR " + search_query.gsub("recipes", "last_seen_recipes")
|
79
|
+
else
|
80
|
+
search_query = "run_list:recipe\\[#{escaped_query}\\] OR run_list:recipe\\[#{escaped_query}\\:\\:default\\]"
|
81
|
+
end
|
82
|
+
ui.msg("Searching for #{type}s containing #{raw_query} OR #{raw_query}::default in their expanded run_list...\n")
|
120
83
|
else
|
121
|
-
|
122
|
-
|
84
|
+
if type == 'node'
|
85
|
+
search_query = "recipes:*#{escaped_query}"
|
86
|
+
search_query += " OR " + search_query.gsub("recipes", "last_seen_recipes")
|
87
|
+
else
|
88
|
+
search_query = "run_list:recipe\\[#{escaped_query}\\]"
|
89
|
+
end
|
90
|
+
ui.msg("Searching for #{type}s containing #{raw_query} in their expanded run_list...\n")
|
123
91
|
end
|
124
92
|
|
125
|
-
|
126
|
-
Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
93
|
+
query = URI.escape(search_query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
127
94
|
|
128
|
-
|
129
|
-
|
95
|
+
result_items = []
|
96
|
+
result_count = 0
|
130
97
|
|
131
98
|
rows = config[:rows]
|
132
99
|
start = config[:start]
|
133
100
|
begin
|
134
|
-
|
135
|
-
|
136
|
-
if
|
137
|
-
|
101
|
+
q.search(type, query, config[:sort], start, rows) do |item|
|
102
|
+
formatted_item = format_for_display(item)
|
103
|
+
if formatted_item.respond_to?(:has_key?) && !formatted_item.has_key?('id')
|
104
|
+
formatted_item['id'] = item.has_key?('id') ? item['id'] : item.name
|
138
105
|
end
|
139
|
-
|
140
|
-
|
106
|
+
result_items << formatted_item
|
107
|
+
result_count += 1
|
141
108
|
end
|
142
109
|
rescue Net::HTTPServerException => e
|
143
110
|
msg = Chef::JSONCompat.from_json(e.response.body)["error"].first
|
@@ -146,18 +113,18 @@ module KnifePreflight
|
|
146
113
|
end
|
147
114
|
|
148
115
|
if ui.interchange?
|
149
|
-
output({:results =>
|
116
|
+
output({:results => result_count, :rows => result_items})
|
150
117
|
else
|
151
|
-
ui.msg "#{
|
118
|
+
ui.msg "#{result_count} #{type.capitalize}s found"
|
152
119
|
ui.msg("\n")
|
153
|
-
|
154
|
-
output(
|
120
|
+
result_items.each do |item|
|
121
|
+
output(item.name)
|
155
122
|
end
|
156
123
|
end
|
157
124
|
|
158
125
|
ui.msg("\n")
|
159
126
|
ui.msg("\n")
|
160
|
-
|
127
|
+
return result_count
|
161
128
|
end
|
162
129
|
end
|
163
130
|
end
|
metadata
CHANGED
@@ -1,79 +1,60 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-preflight
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
version: 0.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Jon Cowie
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: chef
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70103950761040 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 10
|
31
|
-
- 4
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
32
21
|
version: 0.10.4
|
33
22
|
type: :runtime
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70103950761040
|
35
25
|
description: Knife plugin for checking what your cookbook changes will affect
|
36
26
|
email: jonlives@gmail.com
|
37
27
|
executables: []
|
38
|
-
|
39
28
|
extensions: []
|
40
|
-
|
41
|
-
extra_rdoc_files:
|
29
|
+
extra_rdoc_files:
|
42
30
|
- README.md
|
43
|
-
files:
|
31
|
+
files:
|
44
32
|
- README.md
|
45
33
|
- lib/chef/knife/preflight.rb
|
46
|
-
has_rdoc: true
|
47
34
|
homepage: https://github.com/jonlives/knife-preflight
|
48
35
|
licenses: []
|
49
|
-
|
50
36
|
post_install_message:
|
51
|
-
rdoc_options:
|
37
|
+
rdoc_options:
|
52
38
|
- --charset=UTF-8
|
53
|
-
require_paths:
|
39
|
+
require_paths:
|
54
40
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
42
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
62
|
-
version: "0"
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
48
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
71
53
|
requirements: []
|
72
|
-
|
73
54
|
rubyforge_project: knife-preflight
|
74
|
-
rubygems_version: 1.
|
55
|
+
rubygems_version: 1.8.10
|
75
56
|
signing_key:
|
76
57
|
specification_version: 2
|
77
58
|
summary: Knife plugin for checking what your cookbook changes will affect
|
78
59
|
test_files: []
|
79
|
-
|
60
|
+
has_rdoc:
|