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/openstack/requests/compute/boot_from_snapshot.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

module Fog
module Compute
class OpenStack
class Real
def boot_from_snapshot(name, image_ref, flavor_ref, options={})
data = {
'server' => {
'flavorRef' => flavor_ref,
'imageRef' => image_ref,
'name' => name
}
}
vanilla_options = ['metadata', 'accessIPv4', 'accessIPv6',
'availability_zone', 'user_data', 'block_device_mapping']
vanilla_options.select{|o| options[o]}.each do |key|
data['server'][key] = options[key]
end
if options['personality']
data['server']['personality'] = []
for file in options['personality']
data['server']['personality'] << {
'contents' => Base64.encode64(file['contents']),
'path' => file['path']
}
end
end
request(
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => '/os-volumes_boot.json'
)
end
end
end # class OpenStack
end # module Compute
end # module Fog