Class: Fog::HP::BlockStorageV2::Volume

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

Instance Attribute Summary

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.



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

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

Instance Method Details

#attach(new_server_id, device) ⇒ Object

volume can be attached to only one server at a time



73
74
75
76
77
78
79
80
81
82
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 73

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

#backing_up?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 60

def backing_up?
  self.status == 'backing-up'
end

#destroyObject



92
93
94
95
96
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 92

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

#detachObject



84
85
86
87
88
89
90
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 84

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

#deviceObject

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



32
33
34
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 32

def device
  attachments[0]['device'] if has_attachments?
end

#has_attachments?Boolean

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

Returns:

  • (Boolean)


51
52
53
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 51

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

#image_idObject



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

def image_id
  @image_id = ['image_id'] if 
end

#image_id=(new_image_id) ⇒ Object

used for creating bootable volumes



42
43
44
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 42

def image_id=(new_image_id)
  @image_id = new_image_id
end

#in_use?Boolean Also known as: attached?

Returns:

  • (Boolean)


55
56
57
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 55

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

#ready?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 68

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

#restoring?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 64

def restoring?
  self.status == 'restoring-backup'
end

#saveObject



98
99
100
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 98

def save
  identity ? update : create
end

#server_idObject

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



37
38
39
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 37

def server_id
  attachments[0]['server_id'] if has_attachments?
end