Class: Fog::AWS::EC2::Volumes

Inherits:
Collection show all
Defined in:
lib/fog/aws/models/ec2/volumes.rb

Instance Method Summary collapse

Methods inherited from Collection

aliases, attribute, attributes, #attributes, #inspect, #merge_attributes

Constructor Details

#initialize(attributes) ⇒ Volumes

Returns a new instance of Volumes.



14
15
16
17
# File 'lib/fog/aws/models/ec2/volumes.rb', line 14

def initialize(attributes)
  @volume_id ||= []
  super
end

Instance Method Details

#all(volume_id = []) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/aws/models/ec2/volumes.rb', line 19

def all(volume_id = [])
  data = connection.describe_volumes(volume_id).body
  volumes = Fog::AWS::EC2::Volumes.new({
    :connection => connection,
    :volume_id  => volume_id
  }.merge!(attributes))
  data['volumeSet'].each do |volume|
    volumes << Fog::AWS::EC2::Volume.new({
      :connection => connection,
      :volumes    => self
    }.merge!(volume))
  end
  if instance_id
    volumes = volumes.select {|volume| volume.instance_id == instance_id}
  end
  volumes
end

#create(attributes = {}) ⇒ Object



37
38
39
40
41
# File 'lib/fog/aws/models/ec2/volumes.rb', line 37

def create(attributes = {})
  volume = new(attributes)
  volume.save
  volume
end

#get(volume_id) ⇒ Object



43
44
45
46
47
# File 'lib/fog/aws/models/ec2/volumes.rb', line 43

def get(volume_id)
  all(volume_id).first
rescue Fog::Errors::BadRequest
  nil
end

#new(attributes = {}) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/fog/aws/models/ec2/volumes.rb', line 49

def new(attributes = {})
  Fog::AWS::EC2::Volume.new(
    attributes.merge!(
      :connection => connection,
      :volumes    => self
    )
  )
end

#reloadObject



58
59
60
# File 'lib/fog/aws/models/ec2/volumes.rb', line 58

def reload
  all(volume_id)
end