Class: Fog::Compute::AWS::Volume

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

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

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

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume.



22
23
24
25
26
# File 'lib/fog/aws/models/compute/volume.rb', line 22

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

Instance Method Details

#destroyObject



28
29
30
31
32
33
# File 'lib/fog/aws/models/compute/volume.rb', line 28

def destroy
  requires :id

  connection.delete_volume(id)
  true
end

#force_detachObject



89
90
91
# File 'lib/fog/aws/models/compute/volume.rb', line 89

def force_detach
  detach(true)
end

#ready?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/fog/aws/models/compute/volume.rb', line 35

def ready?
  state == 'available'
end

#saveObject

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fog/aws/models/compute/volume.rb', line 39

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
  requires :availability_zone
  requires_one :size, :snapshot_id

  data = connection.create_volume(availability_zone, size, snapshot_id).body
  new_attributes = data.reject {|key,value| key == 'requestId'}
  merge_attributes(new_attributes)

  if tags = self.tags
    # expect eventual consistency
    Fog.wait_for { self.reload rescue nil }
    for key, value in (self.tags = tags)
      connection.tags.create(
        :key          => key,
        :resource_id  => self.identity,
        :value        => value
      )
    end
  end

  if @server
    self.server = @server
  end
  true
end

#serverObject



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

def server
  requires :server_id
  connection.servers('instance-id' => server_id)
end

#server=(new_server) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/fog/aws/models/compute/volume.rb', line 71

def server=(new_server)
  if new_server
    attach(new_server)
  else
    detach
  end
end

#snapshot(description) ⇒ Object



84
85
86
87
# File 'lib/fog/aws/models/compute/volume.rb', line 84

def snapshot(description)
  requires :id
  connection.create_snapshot(id, description)
end

#snapshotsObject



79
80
81
82
# File 'lib/fog/aws/models/compute/volume.rb', line 79

def snapshots
  requires :id
  connection.snapshots(:volume => self)
end