Class: Appshot::EBS_Volume

Inherits:
Object
  • Object
show all
Includes:
Fog
Defined in:
lib/appshot/volume/ebs_volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute aws_access_key_id to.



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

Parameters:

  • value

    the value to set the attribute aws_secret_access_key to.



8
9
10
# File 'lib/appshot/volume/ebs_volume.rb', line 8

def aws_secret_access_key=(value)
  @aws_secret_access_key = value
end

#providerObject (readonly)

Returns the value of attribute provider.



9
10
11
# File 'lib/appshot/volume/ebs_volume.rb', line 9

def provider
  @provider
end

#regionObject

Returns the value of attribute region.



7
8
9
# File 'lib/appshot/volume/ebs_volume.rb', line 7

def region
  @region
end

#volume_idObject

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, options = {})
  snapshots_to_keep  = options[:snapshots_to_keep] || 3
  not_after_time     = options[: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 = "", options = {})
  @fog.snapshots.create({:volume_id => volume_id, :description => description}.merge(options))
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

#volumesObject



25
26
27
# File 'lib/appshot/volume/ebs_volume.rb', line 25

def volumes
  @fog.volumes.all
end