Method: CollinsShell::Asset#set_attributes

Defined in:
lib/collins_shell/asset.rb

#set_attributes(*hash) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/collins_shell/asset.rb', line 169

def set_attributes *hash
  attributes = hash.inject({}) do |ret, e|
    k, v = e.split('=', 2)
    if k.nil? or v.nil? then
      k, v = e.split(':', 2)
      if k.nil? or v.nil? then
        raise ::CollinsShell::RequirementFailedError.new "Expected key=value (or key:value) format"
      end
    end
    ret[k] = v
    ret
  end
  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|
      "You are about to set #{attributes.inspect} on #{assets.length} hosts. ARE YOU SURE?"
    end
  ] do |client,asset|
    client.set_multi_attribute!(asset, attributes)
  end
end