class BuildCloud::EBSVolume
Public Class Methods
get_id_by_name( name )
click to toggle source
# File lib/build-cloud/ebsvolume.rb, line 7 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
new( fog_interfaces, log, options = {} )
click to toggle source
# File lib/build-cloud/ebsvolume.rb, line 25 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
Public Instance Methods
create()
click to toggle source
# File lib/build-cloud/ebsvolume.rb, line 37 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
delete()
click to toggle source
# File lib/build-cloud/ebsvolume.rb, line 71 def delete return unless exists? @log.info( "Deleting volume #{@options[:name]}" ) fog_object.destroy end
read()
click to toggle source
# File lib/build-cloud/ebsvolume.rb, line 65 def read @compute.volumes.select { |v| v.tags['Name'] == @options[:name]}.first end
Also aliased as: fog_object