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/aws/models/compute/volumes.rb

51 lines
1 KiB
Ruby
Raw Normal View History

2010-10-04 14:02:08 -07:00
require 'fog/core/collection'
2010-09-08 14:40:02 -07:00
require 'fog/aws/models/compute/volume'
2010-03-16 15:46:21 -07:00
2009-08-14 09:19:40 -07:00
module Fog
module AWS
2010-09-08 14:40:02 -07:00
class Compute
2009-08-14 09:19:40 -07:00
class Volumes < Fog::Collection
2009-09-23 21:23:54 -07:00
attribute :volume_id
2010-01-08 11:29:07 -08:00
attribute :server
2009-09-23 21:23:54 -07:00
2010-09-08 14:40:02 -07:00
model Fog::AWS::Compute::Volume
def initialize(attributes)
@volume_id ||= []
super
end
def all(volume_id = @volume_id)
2010-01-04 22:03:24 -08:00
@volume_id = volume_id
2009-09-23 21:23:54 -07:00
data = connection.describe_volumes(volume_id).body
load(data['volumeSet'])
2010-01-08 11:29:07 -08:00
if server
self.replace(self.select {|volume| volume.server_id == server.id})
2009-10-06 18:55:39 -07:00
end
2010-03-08 17:56:55 -08:00
self
2009-08-14 09:19:40 -07:00
end
2009-09-23 21:23:54 -07:00
def get(volume_id)
2009-10-22 20:46:15 -07:00
if volume_id
self.class.new(:connection => connection).all(volume_id).first
2009-10-22 20:46:15 -07:00
end
rescue Fog::Errors::NotFound
2009-09-23 21:23:54 -07:00
nil
end
2009-08-14 09:19:40 -07:00
def new(attributes = {})
2010-01-08 11:29:07 -08:00
if server
super({ :server => server }.merge!(attributes))
else
super
end
2009-09-23 21:23:54 -07:00
end
2009-08-14 09:19:40 -07:00
end
end
end
end