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

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

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume.



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

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.



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

def device
  @device
end

#server_idObject (readonly)

Returns the value of attribute server_id.



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

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



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

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



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

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

#detachObject



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

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)


46
47
48
# File 'lib/fog/hp/models/block_storage/volume.rb', line 46

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

#image_id=(new_image_id) ⇒ Object

used for creating bootable volumes



41
42
43
# File 'lib/fog/hp/models/block_storage/volume.rb', line 41

def image_id=(new_image_id)
  @image_id = new_image_id
end

#in_use?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fog/hp/models/block_storage/volume.rb', line 50

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

#ready?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/fog/hp/models/block_storage/volume.rb', line 54

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

#saveObject

Raises:



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

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