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

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

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

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 Attributes::InstanceMethods

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

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#attach(instance_id) ⇒ Object



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

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

#attached?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fog/ibm/models/storage/volume.rb', line 40

def attached?
  status == "Attached"
end

#created_atObject



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

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

#destroyObject



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

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

#detach(instance_id) ⇒ Object



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

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

#instanceObject



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

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

#locationObject



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

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)


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

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

#saveObject

Raises:



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

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

#statusObject



88
89
90
# File 'lib/fog/ibm/models/storage/volume.rb', line 88

def status
  STATUS[attributes[:state].to_i]
end