Skip to content

Commit

Permalink
closes #72
Browse files Browse the repository at this point in the history
This allows batch operations to specify a --size option. A --threads option
would also be nice, especially for things like power status.
  • Loading branch information
bmatheny committed Mar 19, 2013
1 parent 75b1132 commit d279c10
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion support/collins-shell/lib/collins_shell/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def delete
method_option :exec, :type => :string, :desc => 'Execute a command using the data from this asset. Use {{hostname}}, {{ipmi.password}}, etc for substitution'
method_option :header, :type => :boolean, :default => true, :desc => 'Display a tag header. Defaults to true'
method_option :logs, :type => :boolean, :default => false, :desc => 'Also display asset logs, only used with details (SLOW)'
method_option :size, :type => :numeric, :default => 50, :desc => 'Number of results to find. Defaults to 50'
method_option :tags, :type => :array, :desc => 'Tags to display of form: tag1 tag2 tag3. e.g. --tags=hostname tag backend_ip_address'
method_option :threads, :type => :numeric, :default => 1, :desc => 'Number of threads to use for --exec. Defaults to 1.'
method_option :url, :type => :boolean, :default => true, :desc => 'Display a URL along with tags or the default listing'
Expand Down Expand Up @@ -138,6 +137,7 @@ def set_attribute key, value
batch_selector_operation Hash[
:remote => options.remote,
:operation => "set_attribute",
:size => options["size"],
:success_message => proc {|asset| "Set attribute on #{asset.tag}"},
:error_message => proc{|asset| "Setting attribute on #{asset.tag}"},
:confirmation_message => proc do |assets|
Expand Down Expand Up @@ -174,6 +174,7 @@ def set_attributes *hash
batch_selector_operation Hash[
:remote => options.remote,
:operation => "set_attributes",
:size => options["size"],
:success_message => proc {|asset| "Set attributes on #{asset.tag}"},
:error_message => proc{|asset| "Setting attributes on #{asset.tag}"},
:confirmation_message => proc do |assets|
Expand All @@ -192,6 +193,7 @@ def delete_attribute key
batch_selector_operation Hash[
:remote => options.remote,
:operation => "delete_attribute",
:size => options["size"],
:success_message => proc {|asset| "Delete attribute on #{asset.tag}"},
:error_message => proc{|asset| "Delete attribute on #{asset.tag}"},
:confirmation_message => proc do |assets|
Expand Down Expand Up @@ -219,6 +221,7 @@ def set_status
batch_selector_operation Hash[
:remote => options.remote,
:operation => "set_status",
:size => options["size"],
:success_message => proc {|asset| "Set status to #{status} on #{asset.tag}"},
:error_message => proc{|asset| "Setting status on #{asset.tag}"},
:confirmation_message => proc do |assets|
Expand Down
3 changes: 2 additions & 1 deletion support/collins-shell/lib/collins_shell/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def use_tag_option required = false
def use_selector_option required = false
method_option :selector, :type => :hash, :required => required, :desc => 'Selector to query collins. Takes the form of --selector=key1:val1 key2:val2 etc'
method_option :remote, :type => :boolean, :default => false, :desc => 'Search all collins instances, including remote ones'
method_option :size, :type => :numeric, :default => 50, :desc => 'Number of results to find. Defaults to 50'
end

def selector_or_tag
Expand Down Expand Up @@ -91,7 +92,7 @@ def batch_selector_operation options = {}, &block
require_non_empty(success_message, "success_message not set")
require_non_empty(error_message, "error_message not set")
require_non_empty(operation, "operation not set")
selector = get_selector selector_or_tag, [], nil, options[:remote]
selector = get_selector selector_or_tag, [], options[:size], options[:remote]
call_collins get_collins_client, operation do |client|
assets = client.find selector
if assets.length > 1 then
Expand Down

0 comments on commit d279c10

Please sign in to comment.