Class: Actions::Staypuft::Hostgroup::Deploy
- Inherits:
-
Base
- Object
- Base
- Actions::Staypuft::Hostgroup::Deploy
- Defined in:
- app/lib/actions/staypuft/hostgroup/deploy.rb
Instance Method Summary collapse
- #deploy_concurrently(hosts) ⇒ Object
- #deploy_leader_first(hosts) ⇒ Object
- #deploy_serially(hosts) ⇒ Object
- #humanized_input ⇒ Object
- #humanized_output(task_output = self.task_output) ⇒ Object
- #plan(hostgroup, hosts) ⇒ Object
- #task_output ⇒ Object
Instance Method Details
#deploy_concurrently(hosts) ⇒ Object
44 45 46 47 48 49 |
# File 'app/lib/actions/staypuft/hostgroup/deploy.rb', line 44 def deploy_concurrently(hosts) hosts.each do |host| # planned in concurrence plan_action Host::Deploy, host end end |
#deploy_leader_first(hosts) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/lib/actions/staypuft/hostgroup/deploy.rb', line 59 def deploy_leader_first(hosts) first_host = hosts.shift sequence do #deploy first host, then deploy remainder in parallel plan_action Host::Deploy, first_host unless first_host.nil? concurrence do hosts.each do |host| plan_action Host::Deploy, host end end end end |
#deploy_serially(hosts) ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/lib/actions/staypuft/hostgroup/deploy.rb', line 51 def deploy_serially(hosts) sequence do hosts.each do |host| plan_action Host::Deploy, host end end end |
#humanized_input ⇒ Object
72 73 74 |
# File 'app/lib/actions/staypuft/hostgroup/deploy.rb', line 72 def humanized_input input[:name] end |
#humanized_output(task_output = self.task_output) ⇒ Object
86 87 88 |
# File 'app/lib/actions/staypuft/hostgroup/deploy.rb', line 86 def humanized_output(task_output = self.task_output) format '%s %s%%', task_output[:name], (task_output[:progress]*100).to_i end |
#plan(hostgroup, hosts) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/lib/actions/staypuft/hostgroup/deploy.rb', line 20 def plan(hostgroup, hosts) Type! hostgroup, ::Hostgroup (Type! hosts, Array).all? { |v| Type! v, ::Host::Base } input.update id: hostgroup.id, name: hostgroup.name # hostgroup.hosts returns already converted hosts from Host::Discovered with build flag # set to false so they are not built when assigned to the hostgroup in wizard # run Hostgroup's Hosts filtered by hosts host_list = hostgroup.hosts & hosts orchestration_mode = hostgroup.role.orchestration unless hostgroup.role.nil? case orchestration_mode when ::Staypuft::Role::ORCHESTRATION_CONCURRENT deploy_concurrently(host_list) when ::Staypuft::Role::ORCHESTRATION_SERIAL deploy_serially(host_list) when ::Staypuft::Role::ORCHESTRATION_LEADER deploy_leader_first(host_list) else deploy_concurrently(host_list) end end |
#task_output ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'app/lib/actions/staypuft/hostgroup/deploy.rb', line 76 def task_output task_outputs = planned_actions.map(&:task_output) progress = if task_outputs.size == 0 1 else task_outputs.map { |to| to[:progress] }.reduce(&:+).to_f / task_outputs.size end { id: input[:id], name: input[:name], progress: progress, hosts: task_outputs } end |