Module: EasyE::Snapshotter
- Included in:
- EasyE
- Defined in:
- lib/easy_e/snapshotter.rb
Constant Summary collapse
- AWS_INSTANCE_ID_URL =
'http://169.254.169.254/latest/dynamic/instance-identity/document'
Instance Attribute Summary collapse
-
#compute ⇒ Object
lazy loaders.
- #instance_id ⇒ Object
-
#storage ⇒ Object
writeonly
Sets the attribute storage.
Instance Method Summary collapse
- #access_key ⇒ Object
- #attached_volumes ⇒ Object
- #credentials ⇒ Object
- #secret_key ⇒ Object
- #take_snapshots ⇒ Object
Instance Attribute Details
#compute ⇒ Object
lazy loaders
19 20 21 22 23 24 25 26 27 |
# File 'lib/easy_e/snapshotter.rb', line 19 def compute require 'fog/aws' Fog.mock! if [:mock] @compute ||= Fog::Compute.new({ :aws_access_key_id => access_key, :aws_secret_access_key => secret_key, :provider => "AWS" }) end |
#instance_id ⇒ Object
45 46 47 |
# File 'lib/easy_e/snapshotter.rb', line 45 def instance_id @instance_id ||= JSON.parse(HTTParty.get(AWS_INSTANCE_ID_URL))["instanceId"] end |
#storage=(value) ⇒ Object (writeonly)
Sets the attribute storage
7 8 9 |
# File 'lib/easy_e/snapshotter.rb', line 7 def storage=(value) @storage = value end |
Instance Method Details
#access_key ⇒ Object
33 34 35 |
# File 'lib/easy_e/snapshotter.rb', line 33 def access_key @access_key ||= if [:credentials_file] then credentials.first["Access Key Id"] else [:access_key] end end |
#attached_volumes ⇒ Object
29 30 31 |
# File 'lib/easy_e/snapshotter.rb', line 29 def attached_volumes @attached_volumes ||= compute.volumes.select { |vol| vol.server_id == instance_id } end |
#credentials ⇒ Object
41 42 43 |
# File 'lib/easy_e/snapshotter.rb', line 41 def credentials @credentials ||= CSV.parse(File.read([:credentials_file]), :headers => true) end |
#secret_key ⇒ Object
37 38 39 |
# File 'lib/easy_e/snapshotter.rb', line 37 def secret_key @secret_key ||= if [:credentials_file] then credentials.first["Secret Access Key"] else [:secret_key] end end |
#take_snapshots ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/easy_e/snapshotter.rb', line 8 def take_snapshots attached_volumes.collect do |vol| logger.debug "Snapping #{vol.volume_id}" snapshot = compute.snapshots.new snapshot.volume_id = vol.volume_id snapshot.save snapshot end end |