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

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

Instance Method Summary (collapse)

Constructor Details

- (Volume) initialize(attributes = {})

Returns a new instance of Volume



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

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

Instance Method Details

- (Object) destroy



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

def destroy
  requires :id

  service.delete_volume(id)
  true
end

- (Object) force_detach



95
96
97
# File 'lib/fog/aws/models/compute/volume.rb', line 95

def force_detach
  detach(true)
end

- (Boolean) ready?

Returns:

  • (Boolean)


37
38
39
# File 'lib/fog/aws/models/compute/volume.rb', line 37

def ready?
  state == 'available'
end

- (Object) save

Raises:

  • (Fog::Errors::Error)


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

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

  if type == 'io1'
    requires :iops
  end

  data = service.create_volume(availability_zone, size, 'SnapshotId' => snapshot_id, 'VolumeType' => type, 'Iops' => iops).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)
      service.tags.create(
        :key          => key,
        :resource_id  => self.identity,
        :value        => value
      )
    end
  end

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

- (Object) server



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

def server
  requires :server_id
  service.servers.get(server_id)
end

- (Object) server=(new_server)



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

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

- (Object) snapshot(description)



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

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

- (Object) snapshots



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

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