Sha256: c5dc83345e33fcc470c26d046524d928fe77c1aa8e05ec8e3bb7d662962bd9fa

Contents?: true

Size: 1.72 KB

Versions: 62

Compression:

Stored size: 1.72 KB

Contents

module Standup
  module EC2
    class Volume < Base
      def initialize id, info = false
        @id = id
        super info
      end

      info_reader :id, :attached_to

      def self.list reload = false
        if !class_variable_defined?(:@@list) || reload
          @@list = {}
          response = api.describe_volumes
          response.volumeSet.item.each do |item|
            instance = item.attachmentSet ? Instance.new(item.attachmentSet.item[0].instanceId) : nil
            @@list[item.volumeId] = Volume.new item.volumeId,
                                                :status => item.status.to_sym,
                                                :attached_to => instance
          end if response.volumeSet
        end
        @@list
      end

      def self.create size
        response = api.create_volume :size => size.to_s,
                                     :availability_zone => Settings.aws.availability_zone
        list[response.volumeId] = Volume.new response.volumeId
      end

      def destroy
        api.delete_volume :volume_id => @id
        list.delete @id
      end

      def attach_to instance, device
        api.attach_volume :volume_id => @id,
                          :instance_id => instance.id,
                          :device => device
        @attached_to = instance
      end

      def detach
        api.detach_volume :volume_id => @id,
                          :force => 'true'
        @attached_to = nil
      end

      def load_info
        response = api.describe_volumes :volume_id => @id
        item = response.volumeSet.item[0]
        @status = item.status.to_sym
        @attached_to = item.attachmentSet ? Instance.new(item.attachmentSet.item[0].instanceId) : nil
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
standup-0.5.3 lib/standup/ec2/volume.rb
standup-0.5.1 lib/standup/ec2/volume.rb
standup-0.5.0 lib/standup/ec2/volume.rb
standup-0.4.0 lib/standup/ec2/volume.rb
standup-0.3.37 lib/standup/ec2/volume.rb
standup-0.3.36 lib/standup/ec2/volume.rb
standup-0.3.35 lib/standup/ec2/volume.rb
standup-0.3.34 lib/standup/ec2/volume.rb
standup-0.3.33 lib/standup/ec2/volume.rb
standup-0.3.32 lib/standup/ec2/volume.rb
standup-0.3.31 lib/standup/ec2/volume.rb
standup-0.3.30 lib/standup/ec2/volume.rb
standup-0.3.29 lib/standup/ec2/volume.rb
standup-0.3.28 lib/standup/ec2/volume.rb
standup-0.3.27 lib/standup/ec2/volume.rb
standup-0.3.26 lib/standup/ec2/volume.rb
standup-0.3.25 lib/standup/ec2/volume.rb
standup-0.3.24 lib/standup/ec2/volume.rb
standup-0.3.23 lib/standup/ec2/volume.rb
standup-0.3.22 lib/standup/ec2/volume.rb