Class: ChefAB::TimeIPBasedUpgrader

Inherits:
BaseUpgrader show all
Includes:
IPmetric
Defined in:
lib/chef-ab/time_ipbased_upgrader.rb

Instance Attribute Summary collapse

Attributes inherited from BaseUpgrader

#hash, #node_id

Instance Method Summary collapse

Methods included from IPmetric

#ip_metric

Methods inherited from BaseUpgrader

#execute

Constructor Details

#initialize(options) ⇒ TimeIPBasedUpgrader

Returns a new instance of TimeIPBasedUpgrader.



11
12
13
14
15
16
17
# File 'lib/chef-ab/time_ipbased_upgrader.rb', line 11

def initialize(options)
  options[:node_id] = ip_metric(options[:initial_ip], options[:node_id])
  super(options)
  @start_time = options[:start_time].to_i
  @period = options[:period]
  @end_time = 31 * @period + @start_time
end

Instance Attribute Details

#initial_ipObject

Returns the value of attribute initial_ip.



9
10
11
# File 'lib/chef-ab/time_ipbased_upgrader.rb', line 9

def initial_ip
  @initial_ip
end

#periodObject

Returns the value of attribute period.



8
9
10
# File 'lib/chef-ab/time_ipbased_upgrader.rb', line 8

def period
  @period
end

#start_timeObject

Returns the value of attribute start_time.



8
9
10
# File 'lib/chef-ab/time_ipbased_upgrader.rb', line 8

def start_time
  @start_time
end

Instance Method Details

#expected_activationObject



25
26
27
28
29
# File 'lib/chef-ab/time_ipbased_upgrader.rb', line 25

def expected_activation
  (@start_time..@end_time).to_a.bsearch do |fake_time|
    should_execute?(fake_time)
  end
end

#should_execute?(time = nil) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/chef-ab/time_ipbased_upgrader.rb', line 19

def should_execute?(time = nil)
  time ||= current_time
  threshold    = (time - start_time) / @period + 1
  super(threshold)
end