Class: Berta::ExpirationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/berta/expiration_manager.rb

Overview

Class for managing expiration dates on vms

Instance Method Summary collapse

Instance Method Details

#add_default_expiration(vm, exps) ⇒ Object

Adds default vm expiration into given array of expirations assuming that array of expirations are expirations of given vm. If vm already has default expiration nothing will be changed.

Parameters:

Returns:

  • Expirations with default expiration



36
37
38
39
40
41
# File 'lib/berta/expiration_manager.rb', line 36

def add_default_expiration(vm, exps)
  return [] if vm.default_expiration
  exps << Berta::Entities::Expiration.new(vm.next_expiration_id,
                                          Time.now.to_i + Berta::Settings.expiration_offset,
                                          Berta::Settings.expiration.action)
end

#remove_invalid_expirations(exps) ⇒ Array<Berta::Entities::Expiration>

Removes invalid expirations from array of expirations. Invalid expirations are expirations that are planned later than expiration offset value.

Parameters:

Returns:



25
26
27
# File 'lib/berta/expiration_manager.rb', line 25

def remove_invalid_expirations(exps)
  exps.keep_if(&:in_expiration_interval?)
end

#update_expirations(vms) ⇒ Object

Update all expirations on vm, removes invalid expirations and if needed will set default expiration date.

Parameters:



9
10
11
12
13
14
15
16
17
# File 'lib/berta/expiration_manager.rb', line 9

def update_expirations(vms)
  vms.each do |vm|
    begin
      vm.update_expirations(add_default_expiration(vm, remove_invalid_expirations(vm.expirations)))
    rescue Berta::Errors::BackendError => e
      logger.error "#{e.message}\n\tOn vm with id #{vm.handle['ID']}"
    end
  end
end