<=>(other)
click to toggle source
def <=>(other)
return -1 if other.type == 'standalone' && type != 'standalone'
return 1 if type == 'standalone' && other.type != 'standalone'
name <=> other.name
end
additional_gear_storage()
click to toggle source
def additional_gear_storage
attribute(:additional_gear_storage).to_i rescue 0
end
collocated_with()
click to toggle source
def collocated_with
Array(attribute(:collocated_with))
end
connection_info()
click to toggle source
def connection_info
info = property(:cart_data, :connection_url) || property(:cart_data, :job_url) || property(:cart_data, :monitoring_url)
info ? (info["value"] || '').rstrip : nil
end
delete()
click to toggle source
destroy()
click to toggle source
def destroy
debug "Deleting cartridge #{name}"
rest_method "DELETE"
end
display_name()
click to toggle source
def display_name
attribute(:display_name) || name
end
only_in_new?()
click to toggle source
def only_in_new?
type == 'standalone'
end
property(type, key)
click to toggle source
def property(type, key)
key, type = key.to_s, type.to_s
properties.select{ |p| p['type'] == type }.find{ |p| p['name'] == key }
end
reload()
click to toggle source
def reload
debug "Reloading cartridge #{name}"
rest_method "RESTART", :event => "reload"
end
restart()
click to toggle source
def restart
debug "Restarting cartridge #{name}"
rest_method "RESTART", :event => "restart"
end
scalable?()
click to toggle source
def scalable?
supported_scales_to != supported_scales_from
end
scaling()
click to toggle source
def scaling
{
:current_scale => current_scale,
:scales_from => scales_from,
:scales_to => scales_to,
:gear_profile => gear_profile,
} if scalable?
end
set_scales(values)
click to toggle source
def set_scales(values)
values.delete_if{|k,v| v.nil? }
debug "Setting scales = %s" % values.map{|k,v| "#{k}: #{v}"}.join(" ")
rest_method "UPDATE", values
end
set_storage(values)
click to toggle source
def set_storage(values)
debug "Setting additional storage: #{values[:additional_gear_storage]}GB"
rest_method "UPDATE", values
end
shares_gears?()
click to toggle source
def shares_gears?
Array(collocated_with).present?
end
start()
click to toggle source
def start
debug "Starting cartridge #{name}"
rest_method "START", :event => "start"
end
status()
click to toggle source
def status
debug "Getting cartridge #{name}'s status"
result = rest_method "GET", :include => "status_messages"
result.status_messages
end
stop()
click to toggle source
def stop
debug "Stopping cartridge #{name}"
rest_method "STOP", :event => "stop"
end
usage_rate()
click to toggle source
def usage_rate
rate = attribute(:usage_rate_usd)
if attribute(:usage_rates)
rate ||= attribute(:usage_rates).inject(0) { |total, rate| total + rate['usd'].to_f }
end
rate.to_f rescue 0.0
end
usage_rate?()
click to toggle source
def usage_rate?
rate = usage_rate
rate && rate > 0.0
end