Permalink
Browse files

add search limiting

  • Loading branch information...
smith committed Jun 22, 2012
1 parent 56931f6 commit 20eb4a9872888e97542114496a0a8e605a307d2f
Showing with 8 additions and 5 deletions.
  1. +5 −2 README.md
  2. +3 −3 lib/capistrano/chef.rb
View
@@ -21,8 +21,9 @@ Using capistrano-chef, you can do this:
require 'capistrano/chef'
chef_role :web 'roles:web'
- chef_role :db, 'roles:database_master', :primary => true,
- :attribute => :private_ip
+ chef_role :db, 'roles:database_master', :primary => true,
+ :attribute => :private_ip,
+ :limit => 1
Use a Hash to get a specific network interface:
(the Hash must be in the form of { 'interface-name' => 'network-family-name' })
@@ -39,6 +40,8 @@ For a more deep and complex attribute search, use a Proc object:
This defines the same roles using Chef's [search feature](http://wiki.opscode.com/display/chef/Search). Nodes are searched using the given query. The node's `ipaddress` attribute is used by default, but other attributes can be specified in the options as shown in the examples above. The rest of the options are the same as those used by Capistrano.
+The `limit` attribute of the options hash will make it so only that the given number of items will be returned from a search.
+
## Data Bags
Chef [Data Bags](http://wiki.opscode.com/display/chef/Data+Bags) let you store arbitrary JSON data. A common pattern is to use an _apps_ data bag to store data about an application for use in configuration and deployment.
View
@@ -14,7 +14,7 @@ def self.configure_chef
# Do a search on the Chef server and return an attary of the requested
# matching attributes
- def self.search_chef_nodes(query = '*:*', arg = :ipaddress)
+ def self.search_chef_nodes(query = '*:*', arg = :ipaddress, limit = 1000)
search_proc = \
case arg
when Proc
@@ -30,7 +30,7 @@ def self.search_chef_nodes(query = '*:*', arg = :ipaddress)
else
raise ArgumentError, 'Search arguments must be Proc, Hash, Symbol, String.'
end
- Chef::Search::Query.new.search(:node, query)[0].map(&search_proc)
+ Chef::Search::Query.new.search(:node, query, 'X_CHEF_id_CHEF_X asc', 0, limit)[0].map(&search_proc)
end
def self.get_data_bag_item(id, data_bag = :apps)
@@ -43,7 +43,7 @@ def self.load_into(configuration)
configuration.set :capistrano_chef, self
configuration.load do
def chef_role(name, query = '*:*', options = {})
- role name, *(capistrano_chef.search_chef_nodes(query, options.delete(:attribute)) + [options])
+ role name, *(capistrano_chef.search_chef_nodes(query, options.delete(:attribute), options.delete(:limit)) + [options])
end
def set_from_data_bag(data_bag = :apps)

0 comments on commit 20eb4a9

Please sign in to comment.