Sha256: abf173604dc208175c1739a8fa805f4fd2415acf142eb154c0ca3be0651da1aa

Contents?: true

Size: 1.87 KB

Versions: 4

Compression:

Stored size: 1.87 KB

Contents

module CloudProviders
  class ElasticBlockStore < Ec2Helper

    # instance methods
    attr_accessor :volumeId, :size, :snapshotId, :status, :attachments, :device, :availabilityZone, :instance_id
    attr_reader :createTime

    alias :volume_id :volumeId
    alias :snapshot_id :snapshotId
    alias :availability_zone :availabilityZone 
    alias :create_time :createTime

    def createTime(create_time)
      unless create_time.class==DateTime
        @create_time=(DateTime.new(create_time) rescue nil) 
      else
        @createTime=create_time
      end
    end
    def initialize(raw_response,init_opts={},&block)
      parse_raw_response(raw_response)
      super(volumeId,init_opts,&block)
    end

    def parse_raw_response(raw_response)
      @raw_respons = raw_response
      raw_response.each{|k,v| send k+"=", v if respond_to?(k+"=") }
      if raw_response.attachmentSet.respond_to?(:item)
        @attachments=raw_response.attachmentSet.item 
        @attachments.each{|attch| instance_id=attch.instanceId if attch.status=="attached"}
      end
    end

    def attached?(fn_instance_id=nil)
      return false unless @status=="in-use" or @status=="attaching"
      return true if fn_instance_id.nil?
      return true if fn_instance_id == instance_id
      return false
    end

    def available?
       @status=="available"
    end

    def attach(ec2_instance,device)
      ec2.attach_volume(:volume_id => volume_id, :instance_id => ec2_instance.instance_id, :device => device).return=="true"
    end

    def detach
      ec2.detach_volume(:volume_id => volume_id).return=="true"
    end

    def detach!
      ec2.detach_volume(:volume_id => volume_id, :force => true).return=="true"
    end

    def delete!
      ec2.delete(:volume_id => volume_id).return == "true"
    end

    def update!
      parse_raw_response ec2.describe_volumes(:volume_id => volume_id)
    end
  
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
poolparty-1.6.1 lib/cloud_providers/ec2/helpers/elastic_block_store.rb
poolparty-1.6.0 lib/cloud_providers/ec2/helpers/elastic_block_store.rb
poolparty-1.5.0 lib/cloud_providers/ec2/helpers/elastic_block_store.rb
poolparty-1.4.8 lib/cloud_providers/ec2/helpers/elastic_block_store.rb