Class: Fog::HP::BlockStorage::Volume

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/hp/models/block_storage/volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume.



24
25
26
27
28
# File 'lib/fog/hp/models/block_storage/volume.rb', line 24

def initialize(attributes = {})
  # assign these attributes first to prevent race condition with new_record?
  self.image_id = attributes.delete(:image_id)
  super
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



22
23
24
# File 'lib/fog/hp/models/block_storage/volume.rb', line 22

def device
  @device
end

#server_idObject (readonly)

Returns the value of attribute server_id.



21
22
23
# File 'lib/fog/hp/models/block_storage/volume.rb', line 21

def server_id
  @server_id
end

Instance Method Details

#attach(new_server_id, device) ⇒ Object

volume can be attached to only one server at a time



57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/hp/models/block_storage/volume.rb', line 57

def attach(new_server_id, device)
  requires :id
  unless in_use?
    data = service.compute.attach_volume(new_server_id, id, device)
    merge_attributes(:attachments => attachments << data.body['volumeAttachment'])
    true
  else
    false
  end
end

#destroyObject



76
77
78
79
80
# File 'lib/fog/hp/models/block_storage/volume.rb', line 76

def destroy
  requires :id
  service.delete_volume(id)
  true
end

#detachObject



68
69
70
71
72
73
74
# File 'lib/fog/hp/models/block_storage/volume.rb', line 68

def detach
  requires :id
  if has_attachments?
    service.compute.detach_volume(server_id, id)
  end
  true
end

#has_attachments?Boolean

a volume can be attached to only one server at a time

Returns:

  • (Boolean)


44
45
46
# File 'lib/fog/hp/models/block_storage/volume.rb', line 44

def has_attachments?
  !(attachments.nil? || attachments.empty? || attachments[0].empty?)
end

#image_id=(new_image_id) ⇒ Object

used for creating bootable volumes



39
40
41
# File 'lib/fog/hp/models/block_storage/volume.rb', line 39

def image_id=(new_image_id)
  @image_id = new_image_id
end

#in_use?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/fog/hp/models/block_storage/volume.rb', line 48

def in_use?
  self.status == 'in-use'
end

#ready?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/fog/hp/models/block_storage/volume.rb', line 52

def ready?
  self.status == 'available'
end

#saveObject

Raises:

  • (Fog::Errors::Error)


82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fog/hp/models/block_storage/volume.rb', line 82

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  requires :name, :size
  options = {
    'metadata'          => ,
    'snapshot_id'       => snapshot_id,
    'imageRef'          => @image_id
  }
  options = options.reject {|key, value| value.nil?}
  data = service.create_volume(name, description, size, options)
  merge_attributes(data.body['volume'])
  true
end