2009-08-14 09:19:40 -07:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
2009-10-09 22:54:17 -07:00
|
|
|
def volumes(attributes = {})
|
|
|
|
Fog::AWS::EC2::Volumes.new({
|
|
|
|
:connection => self
|
|
|
|
}.merge!(attributes))
|
2009-08-14 09:19:40 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
class Volumes < Fog::Collection
|
|
|
|
|
2009-09-23 21:23:54 -07:00
|
|
|
attribute :volume_id
|
2009-10-20 19:39:57 -07:00
|
|
|
attribute :instance
|
2009-09-23 21:23:54 -07:00
|
|
|
|
2009-09-27 21:31:15 -07:00
|
|
|
def initialize(attributes)
|
|
|
|
@volume_id ||= []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-08-19 09:11:26 -07:00
|
|
|
def all(volume_id = [])
|
2009-09-23 21:23:54 -07:00
|
|
|
data = connection.describe_volumes(volume_id).body
|
2009-09-26 19:42:08 -07:00
|
|
|
volumes = Fog::AWS::EC2::Volumes.new({
|
2009-09-27 21:31:15 -07:00
|
|
|
:connection => connection,
|
|
|
|
:volume_id => volume_id
|
2009-09-26 19:42:08 -07:00
|
|
|
}.merge!(attributes))
|
2009-08-14 09:19:40 -07:00
|
|
|
data['volumeSet'].each do |volume|
|
|
|
|
volumes << Fog::AWS::EC2::Volume.new({
|
2009-09-19 12:21:31 -07:00
|
|
|
:connection => connection,
|
|
|
|
:volumes => self
|
2009-08-14 09:19:40 -07:00
|
|
|
}.merge!(volume))
|
|
|
|
end
|
2009-10-20 19:39:57 -07:00
|
|
|
if instance
|
|
|
|
volumes = volumes.select {|volume| volume.instance_id == instance.id}
|
2009-10-06 18:55:39 -07:00
|
|
|
end
|
2009-08-14 09:19:40 -07:00
|
|
|
volumes
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(attributes = {})
|
|
|
|
volume = new(attributes)
|
|
|
|
volume.save
|
|
|
|
volume
|
|
|
|
end
|
|
|
|
|
2009-09-23 21:23:54 -07:00
|
|
|
def get(volume_id)
|
|
|
|
all(volume_id).first
|
|
|
|
rescue Fog::Errors::BadRequest
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2009-08-14 09:19:40 -07:00
|
|
|
def new(attributes = {})
|
2009-10-20 19:39:57 -07:00
|
|
|
volume = Fog::AWS::EC2::Volume.new(
|
2009-09-20 09:21:03 -07:00
|
|
|
attributes.merge!(
|
2009-10-20 19:39:57 -07:00
|
|
|
:connection => connection,
|
|
|
|
:instance => instance,
|
|
|
|
:volumes => self
|
2009-09-20 09:21:03 -07:00
|
|
|
)
|
|
|
|
)
|
2009-08-14 09:19:40 -07:00
|
|
|
end
|
|
|
|
|
2009-09-23 21:23:54 -07:00
|
|
|
def reload
|
|
|
|
all(volume_id)
|
|
|
|
end
|
|
|
|
|
2009-08-14 09:19:40 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|