1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/bluebox/requests/compute/create_block.rb
Sam Cooper 999ae4c54e use CGI.escape when encoding the POST body
URL.encode was not encoding the '+' characters within ssh keys
2012-11-06 11:27:46 -08:00

45 lines
1.3 KiB
Ruby

module Fog
module Compute
class Bluebox
class Real
# Create a new block
#
# ==== Parameters
# * product_id<~String> - ID of block product (size)
# * template_id<~String> - ID of block OS/build template
# * location_id<~String> - ID of deployment location
# * options<~Hash>:
# * password<~String> - Password for block
# or
# * public_key<~String> - SSH public key
# * username<~String> - Defaults to deploy
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
def create_block(product_id, template_id, location_id, options = {})
unless options.has_key?('password') || options.has_key?('public_key')
raise ArgumentError, 'Either password or public_key must be supplied'
end
query = {
'product' => product_id,
'template' => template_id,
'location' => location_id
}
request(
:expects => 200,
:method => 'POST',
:path => '/api/blocks.json',
:query => query,
:body => options.map {|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join('&')
)
end
end
end
end
end