Sha256: 94c117a33fed5a5689afa66ee6ad1a724ab00124ce6a88f8c60ace97e3c52e13

Contents?: true

Size: 1.76 KB

Versions: 31

Compression:

Stored size: 1.76 KB

Contents

class BuildCloud::EBSVolume

    include ::BuildCloud::Component

    @@objects = []

    def self.get_id_by_name( name )

        volume = self.search( :name => name ).first

        unless volume
            raise "Couldn't get an EBSVolume object for #{name} - is it defined?"
        end

        volume_fog = volume.read

        unless volume_fog
            raise "Couldn't get an EBSVolume fog object for #{name} - is it created?"
        end

        volume_fog.id

    end

    def initialize ( fog_interfaces, log, options = {} )

        @compute = fog_interfaces[:compute]
        @log     = log
        @options = options

        @log.debug( options.inspect )

        required_options(:name, :availability_zone, :size)

    end

    def create
        
        return if exists?

        @log.info( "Creating volume #{@options[:name]}" )

        options = @options.dup

        volume = @compute.volumes.new(options)
        volume.save

        attributes = {}
        attributes[:resource_id] = volume.id.to_s
        attributes[:key] = 'Name'
        attributes[:value] = @options[:name]
        volume_tag = @compute.tags.new( attributes )
        volume_tag.save

        @log.debug( volume.inspect )

        if @options[:instance_name]
            instance_id = BuildCloud::Instance.get_id_by_name( options[:instance_name] )
            attach_response = @compute.attach_volume(instance_id, volume.id, options[:device])
            @log.debug( attach_response.inspect )
        end

    end

    def read
        @compute.volumes.select { |v| v.tags['Name'] == @options[:name]}.first
    end

    alias_method :fog_object, :read

    def delete

        return unless exists?

        @log.info( "Deleting volume #{@options[:name]}" )

        fog_object.destroy

    end

end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
build-cloud-1.1.7 lib/build-cloud/ebsvolume.rb
build-cloud-1.1.6 lib/build-cloud/ebsvolume.rb
build-cloud-1.1.5 lib/build-cloud/ebsvolume.rb
build-cloud-1.1.4 lib/build-cloud/ebsvolume.rb
build-cloud-1.1.3 lib/build-cloud/ebsvolume.rb
build-cloud-1.1.2 lib/build-cloud/ebsvolume.rb
build-cloud-1.0.1 lib/build-cloud/ebsvolume.rb
build-cloud-1.1.1 lib/build-cloud/ebsvolume.rb
build-cloud-1.0.0 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.24 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.23 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.22 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.21 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.20 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.19 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.18 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.17 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.16 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.15 lib/build-cloud/ebsvolume.rb
build-cloud-0.0.14 lib/build-cloud/ebsvolume.rb