mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Adds #transfer and #convert methods to image
(DigitalOcean API 2.0 #3419)
This commit is contained in:
parent
d72ec11656
commit
20c42eb081
3 changed files with 96 additions and 0 deletions
|
@ -12,6 +12,14 @@ module Fog
|
|||
attribute :min_disk_size
|
||||
attribute :created_at
|
||||
end
|
||||
|
||||
def transfer
|
||||
perform_action :transfer_image
|
||||
end
|
||||
|
||||
def convert_to_snapshot
|
||||
perform_action :convert_image_to_snapshot
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def convert_to_snapshot(id)
|
||||
body = { :type => 'convert',}
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/images/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def convert_to_snapshot(id, name)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => 46592838,
|
||||
'status' => 'completed',
|
||||
'type' => 'convert_to_snapshot',
|
||||
'started_at' => '2015-03-24T19:02:47Z',
|
||||
'completed_at' => '2015-03-24T19:02:47Z',
|
||||
'resource_id' => 11060029,
|
||||
'resource_type' => 'image',
|
||||
'region' => null,
|
||||
'region_slug' => null
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/digitalocean/requests/compute_v2/transfer_image.rb
Normal file
44
lib/fog/digitalocean/requests/compute_v2/transfer_image.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def transfer_image(id, region)
|
||||
body = { :type => 'transfer', :region => region }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/images/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def transfer_image(id, name)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => 36805527,
|
||||
'status' => 'in-progress',
|
||||
'type' => 'transfer',
|
||||
'started_at' => '2014-11-14T16:42:45Z',
|
||||
'completed_at' => null,
|
||||
'resource_id' => 7938269,
|
||||
'resource_type' => 'image',
|
||||
'region' => 'nyc3',
|
||||
'region_slug' => 'nyc3'
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue