create_snapshot(volume_id, options = {})
click to toggle source
def create_snapshot(volume_id, options = {})
data = {
'snapshot' => {
'volume_id' => volume_id
}
}
data['snapshot']['display_name'] = options[:display_name] unless options[:display_name].nil?
data['snapshot']['display_description'] = options[:display_description] unless options[:display_description].nil?
data['snapshot']['force'] = options[:force] unless options[:force].nil?
request(
:body => Fog::JSON.encode(data),
:expects => [200],
:method => 'POST',
:path => "snapshots"
)
end
create_volume(size, options = {})
click to toggle source
def create_volume(size, options = {})
data = {
'volume' => {
'size' => size
}
}
data['volume']['display_name'] = options[:display_name] unless options[:display_name].nil?
data['volume']['display_description'] = options[:display_description] unless options[:display_description].nil?
data['volume']['volume_type'] = options[:volume_type] unless options[:volume_type].nil?
data['volume']['availability_zone'] = options[:availability_zone] unless options[:availability_zone].nil?
request(
:body => Fog::JSON.encode(data),
:expects => [200],
:method => 'POST',
:path => "volumes"
)
end
delete_snapshot(snapshot_id)
click to toggle source
def delete_snapshot(snapshot_id)
request(
:expects => [202],
:method => 'DELETE',
:path => "snapshots/#{snapshot_id}"
)
end
delete_volume(volume_id)
click to toggle source
def delete_volume(volume_id)
request(
:expects => [202],
:method => 'DELETE',
:path => "volumes/#{volume_id}"
)
end
get_snapshot(snapshot_id)
click to toggle source
def get_snapshot(snapshot_id)
request(
:expects => [200],
:method => 'GET',
:path => "snapshots/#{snapshot_id}"
)
end
get_volume(volume_id)
click to toggle source
def get_volume(volume_id)
request(
:expects => [200],
:method => 'GET',
:path => "volumes/#{volume_id}"
)
end
get_volume_type(volume_type_id)
click to toggle source
def get_volume_type(volume_type_id)
request(
:expects => [200],
:method => 'GET',
:path => "types/#{volume_type_id}"
)
end
list_snapshots()
click to toggle source
def list_snapshots
request(
:expects => [200],
:method => 'GET',
:path => 'snapshots'
)
end
list_volume_types()
click to toggle source
def list_volume_types
request(
:expects => [200],
:method => 'GET',
:path => 'types'
)
end
list_volumes()
click to toggle source
def list_volumes
request(
:expects => [200],
:method => 'GET',
:path => 'volumes'
)
end
request(params)
click to toggle source
def request(params)
begin
response = @connection.request(params.merge!({
:headers => {
'Content-Type' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}"
}))
rescue Excon::Errors::NotFound => error
raise NotFound.slurp error
rescue Excon::Errors::BadRequest => error
raise BadRequest.slurp error
rescue Excon::Errors::InternalServerError => error
raise InternalServerError.slurp error
rescue Excon::Errors::HTTPStatusError => error
raise ServiceError.slurp error
end
unless response.body.empty?
response.body = Fog::JSON.decode(response.body)
end
response
end