Class: Guignol::Models::Volume
- Defined in:
- lib/guignol/models/volume.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary
Attributes inherited from Base
#connection, #name, #options, #subject
Instance Method Summary collapse
Methods inherited from Base
#exist?, #initialize, #state, #uuid
Constructor Details
This class inherits a constructor from Guignol::Models::Base
Instance Method Details
#attach(server_id) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/guignol/models/volume.rb', line 48 def attach(server_id) exist? or create subject.reload if subject.server_id == server_id if subject.device == [:dev] log "volume already attached" return else log "error: volume attached to device #{subject.device} instead of options[:dev]" raise Error.new('already attached') end end response = connection.attach_volume(server_id, subject.id, [:dev]) response.status == 200 or raise Error.new('failed to attach volume') return self end |
#availability_zone ⇒ Object
13 14 15 |
# File 'lib/guignol/models/volume.rb', line 13 def availability_zone subject && subject.availability_zone end |
#create ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/guignol/models/volume.rb', line 18 def create log "volume already exists" and return self if exist? log "creating volume" = Guignol::DefaultVolumeOptions.merge .slice(:availability_zone, :size, :snapshot, :delete_on_termination) set_subject connection.volumes.create() wait_for_state 'available' return self rescue Exception => e log "error while creating (#{e.class.name})" destroy raise end |
#destroy ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/guignol/models/volume.rb', line 35 def destroy return self unless exist? log "destroying volume" subject.destroy wait_for_state 'deleted' # FIXME: remove tags here set_subject nil return self end |