# File lib/cimi/helpers/cimi_helper.rb, line 19 def current_content_type case request.content_type when 'application/json' then :json when 'text/xml', 'application/xml' then :xml else raise Deltacloud::Exceptions.exception_from_status( 406, translate_error_code(406)[:message] ) end end
# File lib/cimi/helpers/cimi_helper.rb, line 74 def deltacloud_create_method_for(cimi_entity) case cimi_entity when "machine" then "create_instance" when "machine_configuration" then "create_hardware_profile" when "machine_image" then "create_image" when "volume" then "create_storage_volume" when "volume_image" then "create_storage_snapshot" else "create_#{cimi_entity}" end end
# File lib/cimi/helpers/cimi_helper.rb, line 31 def expand?(collection) params['$expand'] == '*' || (params['$expand'] || '').split(',').include?(collection.to_s) end
e.g. convert volume to GB for deltacloud driver
# File lib/cimi/helpers/cimi_helper.rb, line 66 def from_kibibyte(value, unit="GB") case unit when "GB" then ((value.to_f)/1024/1024) when "MB" then ((value.to_f)/1024) else nil end end
Set status to 201 and a Location header
# File lib/cimi/helpers/cimi_helper.rb, line 42 def headers_for_create(resource) status 201 headers 'Location' => resource.id end
# File lib/cimi/helpers/cimi_helper.rb, line 47 def href_id(href, entity) split_on = self.send(:"#{entity.to_s}_url") href.split("#{split_on}/").last end
# File lib/cimi/helpers/cimi_helper.rb, line 36 def no_content_with_status(code=200) body '' status code end
# File lib/cimi/helpers/cimi_helper.rb, line 52 def to_kibibyte(value, unit) #value may be a string. convert to_f value = value.to_f # not to_i because e.g. 0.5 GB case unit when "GB" (value*1024*1024).to_i when "MB" (value*1024).to_i else nil # should probably be exploding something here... end end