class CollinsShell::Asset
Public Class Methods
Public Instance Methods
create()
click to toggle source
# File lib/collins_shell/asset.rb, line 24 def create call_collins get_collins_client, "create asset" do |client| asset = client.create!(options.tag, :generate_ipmi => options.ipmi, :status => options.status, :type => options.type, :ipmi_pool => options.ipmi_pool) print_find_results asset, nil end end
delete()
click to toggle source
# File lib/collins_shell/asset.rb, line 41 def delete call_collins get_collins_client, "delete asset" do |client| if client.delete!(options.tag, :reason => options.reason, :nuke => options.nuke) then say_success "deleted asset #{options.tag}" else say_error "deleting asset #{options.tag}", :exit => true end end end
delete_attribute(key)
click to toggle source
# File lib/collins_shell/asset.rb, line 199 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| "You are about to delete #{key} on #{assets.length} hosts. ARE YOU SURE?" end ] do |client,asset| client.delete_attribute!(asset, key) end end
find()
click to toggle source
# File lib/collins_shell/asset.rb, line 62 def find client = get_collins_client tags = options.tags || [:stuff] selector = get_selector options.selector, tags, options["size"], options.remote assets = client.find selector if options.details then assets.each do |asset| if not options.quiet then logs = [] if options.logs and not options.exec? then logs = client.logs(asset, :size => 5000, :SORT => "DESC").reverse end printer = CollinsShell::AssetPrinter.new asset, self, :separator => '*', :logs => logs, :detailed => !options.exec? puts printer end asset_exec asset, options.exec, options.confirm, options.threads end else if not options.quiet then print_find_results assets, options.tags, :header => options.header, :url => options.url end assets.each {|asset| asset_exec(asset, options.exec, options.confirm, options.threads)} end finalize_exec end
find_similar(tag)
click to toggle source
# File lib/collins_shell/asset.rb, line 97 def find_similar tag call_collins get_collins_client, "similar asset" do |client| as_asset = Collins::Asset.new(tag) assets = client.find_similar as_asset, options["size"], options["sort"], options.sort_type, options.only_unallocated if options.details then assets.each do |asset| printer = CollinsShell::AssetPrinter.new asset, self, :separator => '*' puts printer end else print_find_results assets, options.tags end end end
get(tag)
click to toggle source
# File lib/collins_shell/asset.rb, line 118 def get tag asset = asset_get tag, options if asset then if not options.quiet then logs = [] if options.logs and not options.exec? then logs = call_collins(get_collins_client, "logs") do |client| client.logs(asset, :size => 5000, :sort => "DESC").reverse end end printer = CollinsShell::AssetPrinter.new asset, self, :logs => logs, :detailed => !options.exec? puts printer end asset_exec asset, options.exec, options.confirm else say_error "No such asset #{tag}" end end
set_attribute(key, value)
click to toggle source
# File lib/collins_shell/asset.rb, line 143 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| "You are about to set #{key}=#{value} on #{assets.length} hosts. ARE YOU SURE?" end ] do |client,asset| if options.json then value = JSON.dump(eval(value)) end dimension = nil if options.dimension >= 0 then dimension = options.dimension end client.set_attribute!(asset, key, value, dimension) end end
set_attributes(*hash)
click to toggle source
# 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
set_status()
click to toggle source
# File lib/collins_shell/asset.rb, line 221 def set_status status = options.status state = options.state reason = options.reason if status.nil? && state.nil? then raise ::Collins::ExpectationFailedError.new("set_status requires either a status or a state") end 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| "You are about to set status to #{status} on #{assets.length} hosts. ARE YOU SURE?" end ] do |client,asset| client.set_status!(asset, :reason => reason, :status => status, :state => state) end end