Class: Aebus::Config::Volume
- Inherits:
-
Object
- Object
- Aebus::Config::Volume
- Defined in:
- lib/config/volume.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #backups_to_be_run(snapshots, current_time_utc) ⇒ Object
-
#initialize(current_time_utc, volume_id, config, default_backups) ⇒ Volume
constructor
A new instance of Volume.
- #last_backup ⇒ Object
- #next_backup ⇒ Object
- #purgeable_snapshot_ids(snapshots) ⇒ Object
- #recent_backup?(label, snapshots, last_deadline) ⇒ Boolean
Constructor Details
#initialize(current_time_utc, volume_id, config, default_backups) ⇒ Volume
57 58 59 60 61 62 63 64 65 |
# File 'lib/config/volume.rb', line 57 def initialize(current_time_utc, volume_id, config, default_backups) @config = config @id = volume_id @backups = default_backups ? default_backups.dup : Hash.new if (config && config["backups"]) then @backups.merge(BackupSchedule.parse_backups_config(current_time_utc,config["backups"])) end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
55 56 57 |
# File 'lib/config/volume.rb', line 55 def config @config end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
55 56 57 |
# File 'lib/config/volume.rb', line 55 def id @id end |
Instance Method Details
#backups_to_be_run(snapshots, current_time_utc) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/config/volume.rb', line 67 def backups_to_be_run(snapshots,current_time_utc) result = Array.new max_delay = 0 @backups.each_pair do |k,v| unless recent_backup?(k, snapshots, v.last_deadline) result << k max_delay = [max_delay, current_time_utc.to_i - v.last_deadline.to_i].max end end [max_delay, result] end |
#last_backup ⇒ Object
115 116 117 |
# File 'lib/config/volume.rb', line 115 def last_backup @backups.values.map{|backup| backup.last_deadline}.max end |
#next_backup ⇒ Object
119 120 121 |
# File 'lib/config/volume.rb', line 119 def next_backup @backups.values.map{|backup| backup.next_deadline}.min end |
#purgeable_snapshot_ids(snapshots) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/config/volume.rb', line 95 def purgeable_snapshot_ids(snapshots) return [] unless snapshots removables = snapshots.select{|snapshot| snapshot.aebus_removable_snapshot?} available_backups = @backups.each_with_object({}) { | (k, v) , h | h[k] = v.keep} removables.each do |snapshot| snapshot..each do |tag| if ((available_backups.include? tag) && (available_backups[tag] > 0)) then snapshot.keep = true available_backups[tag] -= 1 end end end removables.inject([]) do |acc, snapshot| acc << snapshot.id unless snapshot.keep? acc end end |
#recent_backup?(label, snapshots, last_deadline) ⇒ Boolean
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/config/volume.rb', line 82 def recent_backup?(label, snapshots, last_deadline) return false unless snapshots snapshots.each do |snapshot| if (snapshot.(label) && (snapshot.start_time > last_deadline)) return true end end false end |