Class: HP::Cloud::VolumeAttachments

Inherits:
FogCollection show all
Defined in:
lib/hpcloud/volume_attachments.rb

Instance Attribute Summary

Attributes inherited from FogCollection

#items, #name

Instance Method Summary collapse

Methods inherited from FogCollection

#empty?, #filter, #get, #get_array, #matches, #unique

Constructor Details

#initialize(server) ⇒ VolumeAttachments

Returns a new instance of VolumeAttachments.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hpcloud/volume_attachments.rb', line 28

def initialize(server)
  super("volume_attachment")
  @items = []
  volumes = Volumes.new
  begin
    rsp = @connection.compute.list_server_volumes(server.id.to_s)
  rescue Exception => e
    raise Exception.new("List server volumes call failed")
  end

  if rsp.nil? || rsp.body.nil? || rsp.body["volumeAttachments"].nil?
    raise Exception.new("List server volumes should include response body with volumeAttachments")
  end

  rsp.body["volumeAttachments"].each { |hsh|
    hsh["server"] = server.name
    vol = volumes.get(hsh["volumeId"].to_s)
    if vol.is_valid?
      hsh["name"] = vol.name
    end
    @items << hsh
  }
  return
end

Instance Method Details

#create(item = nil) ⇒ Object



53
54
55
# File 'lib/hpcloud/volume_attachments.rb', line 53

def create(item = nil)
  return VolumeAttachment.new(item)
end