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

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume



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

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



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

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)


58
59
60
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 58

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

#destroyObject



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

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

#detachObject



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

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



30
31
32
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 30

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)


49
50
51
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 49

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

#image_idObject



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

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

#image_id=(new_image_id) ⇒ Object

used for creating bootable volumes



40
41
42
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 40

def image_id=(new_image_id)
  @image_id = new_image_id
end

#in_use?Boolean Also known as: attached?

Returns:

  • (Boolean)


53
54
55
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 53

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

#ready?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 66

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

#restoring?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 62

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

#saveObject



96
97
98
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 96

def save
  identity ? update : create
end

#server_idObject

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



35
36
37
# File 'lib/fog/hp/models/block_storage_v2/volume.rb', line 35

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