Sha256: a70fd06c8e9898b8ac87ef447bde035c484be2ac45fe9103e24b480beb12368f

Contents?: true

Size: 1.55 KB

Versions: 8

Compression:

Stored size: 1.55 KB

Contents

module Fog
  module AWS
    class EC2

      class Volume < Fog::Model

        attribute :attach_time,       'attachTime'
        attribute :availability_zone, 'availabilityZone'
        attribute :create_time,       'createTime'
        attribute :device
        attribute :instance_id,       'instanceId'
        attribute :size
        attribute :snapshot_id,       'snapshotId'
        attribute :status
        attribute :volume_id,         'volumeId'
        
        def initialize(attributes = {})
          if attributes['attachmentSet']
            attributes.merge!(attributes.delete('attachmentSet').first || {})
          end
          super
        end

        def destroy
          connection.delete_volume(@volume_id)
          true
        end

        def instance=(new_instance)
          @instance_id = new_instance.instance_id
          connection.attach_volume(@instance_id, @volume_id, @device)
        end

        def reload
          new_attributes = volumes.get(@volume_id).attributes
          merge_attributes(new_attributes)
        end

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

        def snapshots
          connection.snapshots(:volume_id => volume_id)
        end

        def volumes
          @volumes
        end

        private

        def volumes=(new_volumes)
          @volumes = new_volumes
        end

      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fog-0.0.22 lib/fog/aws/models/ec2/volume.rb
fog-0.0.21 lib/fog/aws/models/ec2/volume.rb
fog-0.0.20 lib/fog/aws/models/ec2/volume.rb
fog-0.0.19 lib/fog/aws/models/ec2/volume.rb
fog-0.0.18 lib/fog/aws/models/ec2/volume.rb
fog-0.0.17 lib/fog/aws/models/ec2/volume.rb
fog-0.0.16 lib/fog/aws/models/ec2/volume.rb
fog-0.0.15 lib/fog/aws/models/ec2/volume.rb