Class: BuildCloud::EBSVolume
- Inherits:
-
Object
- Object
- BuildCloud::EBSVolume
- Includes:
- Component
- Defined in:
- lib/build-cloud/ebsvolume.rb
Constant Summary collapse
- @@objects =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ EBSVolume
constructor
A new instance of EBSVolume.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ EBSVolume
Returns a new instance of EBSVolume.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/build-cloud/ebsvolume.rb', line 25 def initialize ( fog_interfaces, log, = {} ) @compute = fog_interfaces[:compute] @log = log = @log.debug( .inspect ) (:name, :availability_zone, :size) end |
Class Method Details
.get_id_by_name(name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Method Details
#create ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/build-cloud/ebsvolume.rb', line 37 def create return if exists? @log.info( "Creating volume #{@options[:name]}" ) = .dup volume = @compute.volumes.new() volume.save attributes = {} attributes[:resource_id] = volume.id.to_s attributes[:key] = 'Name' attributes[:value] = [:name] volume_tag = @compute..new( attributes ) volume_tag.save @log.debug( volume.inspect ) if [:instance_name] instance_id = BuildCloud::Instance.get_id_by_name( [:instance_name] ) attach_response = @compute.attach_volume(instance_id, volume.id, [:device]) @log.debug( attach_response.inspect ) end end |
#delete ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/build-cloud/ebsvolume.rb', line 71 def delete return unless exists? @log.info( "Deleting volume #{@options[:name]}" ) fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
65 66 67 |
# File 'lib/build-cloud/ebsvolume.rb', line 65 def read @compute.volumes.select { |v| v.['Name'] == [:name]}.first end |