Class: Appshot::EBS_Volume
- Inherits:
-
Object
- Object
- Appshot::EBS_Volume
- Includes:
- Fog
- Defined in:
- lib/appshot/volume/ebs_volume.rb
Instance Attribute Summary collapse
-
#aws_access_key_id ⇒ Object
writeonly
Sets the attribute aws_access_key_id.
-
#aws_secret_access_key ⇒ Object
writeonly
Sets the attribute aws_secret_access_key.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#region ⇒ Object
Returns the value of attribute region.
-
#volume_id ⇒ Object
Returns the value of attribute volume_id.
Instance Method Summary collapse
- #day_offset(days) ⇒ Object
- #days_to_seconds(days) ⇒ Object
-
#initialize(opts = {}) ⇒ EBS_Volume
constructor
A new instance of EBS_Volume.
-
#prune_snapshots(volume_id, options = {}) ⇒ Object
def prune_snapshots(volume_id, snapshots_to_keep, not_after_time = Time.now).
- #snap(volume_id, description = "", options = {}) ⇒ Object
- #snapshots_for(volume_id) ⇒ Object
- #volumes ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ EBS_Volume
Returns a new instance of EBS_Volume.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/appshot/volume/ebs_volume.rb', line 12 def initialize(opts = {}) @provider = opts[:provider] || 'AWS' @region = opts[:region] || "us-east-1" @aws_access_key_id = opts[:aws_access_key_id] unless opts[:aws_access_key_id].nil? @aws_secret_access_key = opts[:aws_secret_access_key] unless opts[:aws_secret_access_key].nil? @fog = Fog::Compute.new(:provider => @provider, :region => @region, :aws_access_key_id => @aws_access_key_id, :aws_secret_access_key => @aws_secret_access_key, ) end |
Instance Attribute Details
#aws_access_key_id=(value) ⇒ Object (writeonly)
Sets the attribute aws_access_key_id
8 9 10 |
# File 'lib/appshot/volume/ebs_volume.rb', line 8 def aws_access_key_id=(value) @aws_access_key_id = value end |
#aws_secret_access_key=(value) ⇒ Object (writeonly)
Sets the attribute aws_secret_access_key
8 9 10 |
# File 'lib/appshot/volume/ebs_volume.rb', line 8 def aws_secret_access_key=(value) @aws_secret_access_key = value end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
9 10 11 |
# File 'lib/appshot/volume/ebs_volume.rb', line 9 def provider @provider end |
#region ⇒ Object
Returns the value of attribute region.
7 8 9 |
# File 'lib/appshot/volume/ebs_volume.rb', line 7 def region @region end |
#volume_id ⇒ Object
Returns the value of attribute volume_id.
7 8 9 |
# File 'lib/appshot/volume/ebs_volume.rb', line 7 def volume_id @volume_id end |
Instance Method Details
#day_offset(days) ⇒ Object
51 52 53 54 |
# File 'lib/appshot/volume/ebs_volume.rb', line 51 def day_offset(days) return days if days.nil? Time.now - (days * 86400) end |
#days_to_seconds(days) ⇒ Object
55 56 57 |
# File 'lib/appshot/volume/ebs_volume.rb', line 55 def days_to_seconds(days) days * 86400 end |
#prune_snapshots(volume_id, options = {}) ⇒ Object
def prune_snapshots(volume_id, snapshots_to_keep, not_after_time = Time.now)
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/appshot/volume/ebs_volume.rb', line 40 def prune_snapshots(volume_id, = {}) snapshots_to_keep = [:snapshots_to_keep] || 3 not_after_time = [:not_after_time] || Time.now snapshots = snapshots_for(volume_id) (snapshots.count - snapshots_to_keep).times do snapshots.first.destroy if snapshots.first.created_at < not_after_time snapshots.reload end end |
#snap(volume_id, description = "", options = {}) ⇒ Object
29 30 31 |
# File 'lib/appshot/volume/ebs_volume.rb', line 29 def snap(volume_id, description = "", = {}) @fog.snapshots.create({:volume_id => volume_id, :description => description}.merge()) end |
#snapshots_for(volume_id) ⇒ Object
33 34 35 36 37 |
# File 'lib/appshot/volume/ebs_volume.rb', line 33 def snapshots_for(volume_id) # for more info on Amazon EC2 filters (like "volume-id" below) please # refer to http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVolumes.html @fog.snapshots.all("volume-id" => volume_id) end |
#volumes ⇒ Object
25 26 27 |
# File 'lib/appshot/volume/ebs_volume.rb', line 25 def volumes @fog.volumes.all end |