Class: Actions::Staypuft::Host::Deploy

Inherits:
Base
  • Object
show all
Defined in:
app/lib/actions/staypuft/host/deploy.rb

Instance Method Summary collapse

Instance Method Details

#humanized_outputObject



47
48
49
50
# File 'app/lib/actions/staypuft/host/deploy.rb', line 47

def humanized_output
  task_output = self.task_output
  format '%s %s%%', task_output[:name], (task_output[:progress]*100).to_i
end

#plan(host) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/lib/actions/staypuft/host/deploy.rb', line 18

def plan(host)
  Type! host, ::Host::Base

  input.update host: { id: host.id, name: host.name }

  unless host.open_stack_deployed?
    sequence do
      plan_action Host::Build, host.id
      plan_action Host::WaitUntilInstalled, host.id
      plan_action Host::WaitUntilHostReady, host.id
    end
  else
    # it is already deployed
  end
end

#task_outputObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/lib/actions/staypuft/host/deploy.rb', line 34

def task_output
  steps    = planned_actions.inject([]) { |s, a| s + a.steps[1..2] }.compact
  progress = if steps.empty?
               1
             else
               total          = steps.map { |s| s.progress_done * s.progress_weight }.reduce(&:+)
               weighted_count = steps.map(&:progress_weight).reduce(&:+)
               total / weighted_count
             end

  input[:host].merge progress: progress
end