Class: Fog::Storage::IBM::Volume

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

Constant Summary collapse

STATES =
{
  0  => 'New',
  1  => 'Creating',
  2  => 'Deleting',
  3  => 'Deleted',
  4  => 'Detached',
  5  => 'Attached',
  6  => 'Failed',
  7  => 'Deletion pending',
  8  => 'Being cloned',
  9  => 'Cloning',
  10 => 'Attaching',
  11 => 'Detaching',
  12 => 'Copying',
  13 => 'Importing',
  14 => 'Transfer retrying',
}

Instance Method Summary collapse

Instance Method Details

#attach(instance_id) ⇒ Object



46
47
48
49
# File 'lib/fog/ibm/models/storage/volume.rb', line 46

def attach(instance_id)
  requires :id
  service.attach_volume(instance_id, id).body['success']
end

#attached?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fog/ibm/models/storage/volume.rb', line 42

def attached?
  state == "Attached"
end

#created_atObject



56
57
58
# File 'lib/fog/ibm/models/storage/volume.rb', line 56

def created_at
  Time.at(attributes[:created_at].to_f / 1000)
end

#destroyObject



60
61
62
63
64
# File 'lib/fog/ibm/models/storage/volume.rb', line 60

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

#detach(instance_id) ⇒ Object



51
52
53
54
# File 'lib/fog/ibm/models/storage/volume.rb', line 51

def detach(instance_id)
  requires :id
  service.detach_volume(instance_id, id).body['success']
end

#instanceObject



66
67
68
69
# File 'lib/fog/ibm/models/storage/volume.rb', line 66

def instance
  return nil if instance_id.nil? || instance_id == "0" || instance_id == ""
  Fog::Compute[:ibm].servers.get(instance_id)
end

#locationObject



71
72
73
74
# File 'lib/fog/ibm/models/storage/volume.rb', line 71

def location
  requires :location_id
  Fog::Compute[:ibm].locations.get(location_id)
end

#ready?Boolean

Are we ready to be attached to an instance?

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/fog/ibm/models/storage/volume.rb', line 77

def ready?
  # TODO: Not sure if this is the only state we should be matching.
  state == "Detached"
end

#saveObject

Raises:

  • (Fog::Errors::Error)


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

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  requires :name, :offering_id, :format, :location_id, :size
  data = service.create_volume(name, offering_id, format, location_id, size)
  merge_attributes(data.body)
  true
end

#stateObject



90
91
92
# File 'lib/fog/ibm/models/storage/volume.rb', line 90

def state
  STATES[attributes[:state]]
end