-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[openstack] add volume transfer models/requests
- Loading branch information
Showing
13 changed files
with
2,134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'fog/core/model' | ||
|
||
module Fog | ||
module Volume | ||
class OpenStack | ||
class Transfer < Fog::Model | ||
identity :id | ||
|
||
attribute :auth_key, :aliases => 'authKey' | ||
attribute :created_at, :aliases => 'createdAt' | ||
attribute :name | ||
attribute :volume_id, :aliases => 'volumeId' | ||
|
||
def save | ||
requires :name, :volume_id | ||
data = service.create_transfer(volume_id, :name => name) | ||
merge_attributes(data.body['transfer']) | ||
true | ||
end | ||
|
||
def destroy | ||
requires :id | ||
service.delete_transfer(id) | ||
true | ||
end | ||
|
||
def initialize(attributes) | ||
# Old 'connection' is renamed as service and should be used instead | ||
prepare_service_value(attributes) | ||
super | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'fog/core/collection' | ||
require 'fog/openstack/models/volume/transfer' | ||
|
||
module Fog | ||
module Volume | ||
class OpenStack | ||
class Transfers < Fog::Collection | ||
model Fog::Volume::OpenStack::Transfer | ||
|
||
def all(options = {}) | ||
load(service.list_transfers_detailed(options).body['transfers']) | ||
end | ||
|
||
def summary(options = {}) | ||
load(service.list_transfers(options).body['transfers']) | ||
end | ||
|
||
def get(transfer_id) | ||
if transfer = service.get_transfer_details(transfer_id).body['transfer'] | ||
new(transfer) | ||
end | ||
rescue Fog::Volume::OpenStack::NotFound | ||
nil | ||
end | ||
alias_method :find_by_id, :get | ||
|
||
def accept(transfer_id, auth_key) | ||
# NOTE: This is NOT a method on the Transfer object, since the | ||
# receiver cannot see the transfer object in the get_transfer_details | ||
# or list_transfers(_detailed) requests. | ||
if transfer = service.accept_transfer(transfer_id, auth_key).body['transfer'] | ||
new(transfer) | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Fog | ||
module Volume | ||
class OpenStack | ||
# no Mock needed, test coverage in RSpec | ||
|
||
class Real | ||
def accept_transfer(transfer_id, auth_key) | ||
data = { | ||
'accept' => { | ||
'auth_key' => auth_key | ||
} | ||
} | ||
|
||
request( | ||
:body => Fog::JSON.encode(data), | ||
:expects => [200, 202], | ||
:method => 'POST', | ||
:path => "os-volume-transfer/#{transfer_id}/accept" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Fog | ||
module Volume | ||
class OpenStack | ||
# no Mock needed, test coverage in RSpec | ||
|
||
class Real | ||
def create_transfer(volume_id, options={}) | ||
data = { | ||
'transfer' => { | ||
'volume_id' => volume_id | ||
} | ||
} | ||
if options[:name] | ||
data['transfer']['name'] = options[:name] | ||
end | ||
|
||
request( | ||
:body => Fog::JSON.encode(data), | ||
:expects => [200, 202], | ||
:method => 'POST', | ||
:path => 'os-volume-transfer' | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Fog | ||
module Volume | ||
class OpenStack | ||
# no Mock needed, test coverage in RSpec | ||
|
||
class Real | ||
def delete_transfer(transfer_id) | ||
request( | ||
:expects => 202, | ||
:method => 'DELETE', | ||
:path => "os-volume-transfer/#{transfer_id}" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Fog | ||
module Volume | ||
class OpenStack | ||
# no Mock needed, test coverage in RSpec | ||
|
||
class Real | ||
def get_transfer_details(transfer_id) | ||
request( | ||
:expects => 200, | ||
:method => 'GET', | ||
:path => "os-volume-transfer/#{transfer_id}" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Fog | ||
module Volume | ||
class OpenStack | ||
# no Mock needed, test coverage in RSpec | ||
|
||
class Real | ||
def list_transfers(options = {}) | ||
request( | ||
:expects => 200, | ||
:method => 'GET', | ||
:path => 'os-volume-transfer', | ||
:query => options | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
lib/fog/openstack/requests/volume/list_transfers_detailed.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Fog | ||
module Volume | ||
class OpenStack | ||
# no Mock needed, test coverage in RSpec | ||
|
||
class Real | ||
def list_transfers_detailed(options = {}) | ||
request( | ||
:expects => 200, | ||
:method => 'GET', | ||
:path => 'os-volume-transfer/detail', | ||
:query => options | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.