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 Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#initialize, #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

This class inherits a constructor from Fog::Model

Instance Method Details

#attach(instance_id) ⇒ Object



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

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

#attached?Boolean

Returns:

  • (Boolean)


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

def attached?
  state == "Attached"
end

#created_atObject



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

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

#destroyObject



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

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

#detach(instance_id) ⇒ Object



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

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

#instanceObject



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

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

#locationObject



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

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)


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

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

#saveObject

Raises:



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

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



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

def state
  STATES[attributes[:state]]
end