mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
volume models and specs
This commit is contained in:
parent
01ab1e7d01
commit
b2c3ad554a
5 changed files with 175 additions and 4 deletions
|
@ -28,6 +28,8 @@ module Fog
|
|||
|
||||
load "fog/aws/models/ec2/address.rb"
|
||||
load "fog/aws/models/ec2/addresses.rb"
|
||||
load "fog/aws/models/ec2/volume.rb"
|
||||
load "fog/aws/models/ec2/volumes.rb"
|
||||
|
||||
load "fog/aws/parsers/ec2/allocate_address.rb"
|
||||
load "fog/aws/parsers/ec2/attach_volume.rb"
|
||||
|
|
|
@ -16,7 +16,7 @@ module Fog
|
|||
|
||||
def initialize(attributes = {})
|
||||
if attributes['attachmentSet']
|
||||
attributes.merge!(attributes.delete('attachmentSet'))
|
||||
attributes.merge!(attributes.delete('attachmentSet').first || {})
|
||||
end
|
||||
super
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ module Fog
|
|||
def save
|
||||
data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
|
||||
new_attributes = data.reject {|key,value| key == 'requestId'}
|
||||
update_attributes(new_attributes)
|
||||
merge_attributes(new_attributes)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -8,9 +8,14 @@ module Fog
|
|||
|
||||
class Volumes < Fog::Collection
|
||||
|
||||
attribute :volume_id
|
||||
|
||||
def all(volume_id = [])
|
||||
data = connection.describe_volumes(volume_id)
|
||||
volumes = Fog::AWS::EC2::Volumes.new(:connection => connection)
|
||||
data = connection.describe_volumes(volume_id).body
|
||||
volumes = Fog::AWS::EC2::Volumes.new(
|
||||
:connection => connection,
|
||||
:volume_id => volume_id
|
||||
)
|
||||
data['volumeSet'].each do |volume|
|
||||
volumes << Fog::AWS::EC2::Volume.new({
|
||||
:connection => connection,
|
||||
|
@ -26,6 +31,12 @@ module Fog
|
|||
volume
|
||||
end
|
||||
|
||||
def get(volume_id)
|
||||
all(volume_id).first
|
||||
rescue Fog::Errors::BadRequest
|
||||
nil
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
Fog::AWS::EC2::Volume.new(
|
||||
attributes.merge!(
|
||||
|
@ -35,6 +46,10 @@ module Fog
|
|||
)
|
||||
end
|
||||
|
||||
def reload
|
||||
all(volume_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
84
spec/aws/models/ec2/volume_spec.rb
Normal file
84
spec/aws/models/ec2/volume_spec.rb
Normal file
|
@ -0,0 +1,84 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'Fog::AWS::EC2::Volume' do
|
||||
|
||||
describe "#initialize" do
|
||||
|
||||
it "should remap attributes from parser" # do
|
||||
# volume = Fog::AWS::EC2::Volume.new(
|
||||
# 'instanceId' => 'i-00000000',
|
||||
# 'publicIp' => '0.0.0.0'
|
||||
# )
|
||||
# address.instance_id.should == 'i-00000000'
|
||||
# address.public_ip.should == '0.0.0.0'
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
describe "#volumes" do
|
||||
|
||||
it "should return a Fog::AWS::EC2::Volumes" do
|
||||
ec2.volumes.new.volumes.should be_a(Fog::AWS::EC2::Volumes)
|
||||
end
|
||||
|
||||
it "should be the volumes the volume is related to" do
|
||||
volumes = ec2.volumes
|
||||
volumes.new.volumes.should == volumes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
||||
it "should return true if the volume is deleted" do
|
||||
volume = ec2.volumes.create
|
||||
volume.destroy.should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
before(:each) do
|
||||
@volume = ec2.volumes.create
|
||||
@reloaded = @volume.reload
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::EC2::Volume" do
|
||||
@reloaded.should be_a(Fog::AWS::EC2::Volume)
|
||||
end
|
||||
|
||||
it "should reset attributes to remote state" do
|
||||
@volume.attributes.should == @reloaded.attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#save" do
|
||||
|
||||
before(:each) do
|
||||
@volume = ec2.volumes.new
|
||||
end
|
||||
|
||||
it "should return true when it succeeds" do
|
||||
@volume.save.should be_true
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should not exist in addresses before save" do
|
||||
@volume.volumes.get(@volume.volume_id).should be_nil
|
||||
end
|
||||
|
||||
it "should exist in buckets after save" do
|
||||
@volume.save
|
||||
@volume.volumes.get(@volume.volume_id).should_not be_nil
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
70
spec/aws/models/ec2/volumes_spec.rb
Normal file
70
spec/aws/models/ec2/volumes_spec.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'Fog::AWS::EC2::Volumes' do
|
||||
|
||||
describe "#all" do
|
||||
|
||||
it "should return a Fog::AWS::EC2::Volumes" do
|
||||
ec2.volumes.all.should be_a(Fog::AWS::EC2::Volumes)
|
||||
end
|
||||
|
||||
it "should include persisted volumes" do
|
||||
volume = ec2.volumes.create
|
||||
ec2.volumes.get(volume.volume_id).should_not be_nil
|
||||
volume.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
|
||||
before(:each) do
|
||||
@volume = ec2.volumes.create
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::EC2::Volume" do
|
||||
@volume.should be_a(Fog::AWS::EC2::Volume)
|
||||
end
|
||||
|
||||
it "should exist on ec2" do
|
||||
ec2.volumes.get(@volume.volume_id).should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#get" do
|
||||
|
||||
it "should return a Fog::AWS::EC2::Volume if a matching volume exists" do
|
||||
volume = ec2.volumes.create
|
||||
get = ec2.volumes.get(volume.volume_id)
|
||||
volume.attributes.should == get.attributes
|
||||
volume.destroy
|
||||
end
|
||||
|
||||
it "should return nil if no matching address exists" do
|
||||
ec2.volumes.get('vol-00000000').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#new" do
|
||||
|
||||
it "should return a Fog::AWS::EC2::Volume" do
|
||||
ec2.volumes.new.should be_a(Fog::AWS::EC2::Volume)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
it "should return a Fog::AWS::EC2::Volumes" do
|
||||
ec2.volumes.all.reload.should be_a(Fog::AWS::EC2::Volumes)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue