File tree Expand file tree Collapse file tree
example-repository/cookbooks/CHEF-90/recipes Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,13 +89,17 @@ def resources(*args)
8989 @collection . resources ( *args )
9090 end
9191
92- def search ( type , query , &block )
92+ def search ( type , query , attributes = [ ] , &block )
9393 Chef ::Log . debug ( "Searching #{ type } index with #{ query } " )
9494 r = Chef ::REST . new ( Chef ::Config [ :search_url ] )
95- results = r . get_rest ( "search/#{ type } ?q=#{ query } " )
95+ results = r . get_rest ( "search/#{ type } ?q=#{ query } &a= #{ attributes . join ( ',' ) } " )
9696 Chef ::Log . debug ( "Searching #{ type } index with #{ query } returned #{ results . length } entries" )
97- results . each do |sr |
98- block . call ( sr )
97+ if block
98+ results . each do |sr |
99+ block . call ( sr )
100+ end
101+ else
102+ results
99103 end
100104 end
101105
Original file line number Diff line number Diff line change 1+ #
2+ # Cookbook Name:: CHEF-90
3+ # Recipe:: default
4+ #
5+ # Copyright 2009, Example Com
6+ #
7+ # Licensed under the Apache License, Version 2.0 (the "License");
8+ # you may not use this file except in compliance with the License.
9+ # You may obtain a copy of the License at
10+ #
11+ # http://www.apache.org/licenses/LICENSE-2.0
12+ #
13+ # Unless required by applicable law or agreed to in writing, software
14+ # distributed under the License is distributed on an "AS IS" BASIS,
15+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ # See the License for the specific language governing permissions and
17+ # limitations under the License.
18+ #
19+
20+ results = search ( :node , '*' , [ 'ipaddress' , 'hostname' ] )
21+ Chef ::Log . info ( results . inspect )
22+
23+ search ( :node , '*' , [ 'ipaddress' , 'hostname' ] ) do |n |
24+ Chef ::Log . info ( "#{ n [ 'ipaddress' ] } #{ n [ 'hostname' ] } " )
25+ end
26+
27+ Chef ::Log . info ( search ( :node , '*' ) . inspect )
You can’t perform that action at this time.
0 commit comments