Class: Actions::Staypuft::Hostgroup::OrderedDeploy
- Inherits:
-
Base
- Object
- Base
- Actions::Staypuft::Hostgroup::OrderedDeploy
- Defined in:
- app/lib/actions/staypuft/hostgroup/ordered_deploy.rb
Overview
deploys Hostgroups in given order
Instance Method Summary collapse
- #enable_puppet_agent(hosts) ⇒ Object
- #humanized_input ⇒ Object
- #humanized_output ⇒ Object
- #plan(hostgroups, hosts_to_deploy_filter, hosts_to_provision_filter) ⇒ Object
- #task_output ⇒ Object
Instance Method Details
#enable_puppet_agent(hosts) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/lib/actions/staypuft/hostgroup/ordered_deploy.rb', line 78 def enable_puppet_agent(hosts) lookup_key_runmode_id = Puppetclass. find_by_name('foreman::puppet::agent::service'). class_params. where(key: 'runmode'). first. tap { |v| v || raise('missing runmode LookupKey') }. id sequence do hosts.each do |host| # enable puppet agent plan_action(Actions::Staypuft::Host::Update, host, lookup_values_attributes: { nil => { lookup_key_id: lookup_key_runmode_id, value: 'service' } }) end end puppet_runs = sequence do hosts.map do |host| plan_action Actions::Staypuft::Host::PuppetRun, host end end concurrence do hosts.zip(puppet_runs).each do |host, puppet_run| sequence do plan_action Actions::Staypuft::Host::ReportWait, host.id, puppet_run.output[:executed_at] plan_action Actions::Staypuft::Host::AssertReportSuccess, host.id end end end end |
#humanized_input ⇒ Object
114 115 116 |
# File 'app/lib/actions/staypuft/hostgroup/ordered_deploy.rb', line 114 def humanized_input planned_actions.map(&:humanized_input).join(', ') end |
#humanized_output ⇒ Object
118 119 120 |
# File 'app/lib/actions/staypuft/hostgroup/ordered_deploy.rb', line 118 def humanized_output task_output.map { |hg| "#{hg[:name]} #{(hg[:progress]*100).to_i}%" }.join(', ') end |
#plan(hostgroups, hosts_to_deploy_filter, hosts_to_provision_filter) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/lib/actions/staypuft/hostgroup/ordered_deploy.rb', line 21 def plan(hostgroups, hosts_to_deploy_filter, hosts_to_provision_filter) hosts_to_deploy_filter ||= hostgroups. map(&:hosts). reduce(&:+). select { |h| !h.open_stack_deployed? } hosts_to_provision_filter ||= hosts_to_deploy_filter.select(&:managed?) (Type! hostgroups, Array).all? { |v| Type! v, ::Hostgroup } (Type! hosts_to_deploy_filter, Array).all? { |v| Type! v, ::Host::Base } sequence do hosts = hostgroups.map(&:hosts).reduce(&:+) hosts_to_provision = hosts & hosts_to_provision_filter hosts_to_deploy = hosts & hosts_to_deploy_filter hosts_to_provision.each { |host| plan_action Host::TriggerProvisioning, host } concurrence do hosts_to_provision.each { |host| plan_action Host::WaitUntilProvisioned, host } end input.update hostgroups: {} hostgroups.each do |hostgroup| input[:hostgroups].update hostgroup.id => { name: hostgroup.name, hosts: {} } hostgroup_hosts = (hostgroup.hosts & hosts_to_deploy_filter) # wait till all hosts are ready concurrence do hostgroup_hosts.each do |host| input[:hostgroups][hostgroup.id][:hosts].update host.id => host.name plan_action Host::WaitUntilReady, host plan_action Host::Update, host, :environment => nil end end # run puppet twice without checking for puppet success 2.times do concurrence do hostgroup_hosts.each do |host| plan_action Host::Deploy, host, false end end end # run puppet once and check it succeeded concurrence do hostgroup_hosts.each do |host| plan_action Host::Deploy, host end end end enable_puppet_agent hosts_to_deploy end end |
#task_output ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/lib/actions/staypuft/hostgroup/ordered_deploy.rb', line 122 def task_output steps = all_planned_actions.map { |a| a.steps[1..2] }.reduce(&:+).compact stets_by_hosts = steps.inject({}) do |hash, step| key = step.action(execution_plan).input[:host_id] hash[key] ||= [] hash[key] << step hash end progresses_by_host = stets_by_hosts.inject({}) do |hash, (host_id, steps)| progress = if steps.empty? 'done' else total = steps.map { |s| s.progress_done * s.progress_weight }.reduce(&:+) weighted_count = steps.map(&:progress_weight).reduce(&:+) total / weighted_count end hash.update host_id => progress end (input[:hostgroups] || []).map do |hostgroup_id, hostgroup| next if hostgroup[:hosts].size == 0 progress = hostgroup[:hosts].map { |id, _| progresses_by_host[id.to_i] }.sum.to_f / hostgroup[:hosts].size { id: hostgroup_id, name: hostgroup[:name], progress: progress, hosts: hostgroup[:hosts].map do |id, name| { id: id, name: name, progress: progresses_by_host[id.to_i] } end } end.compact end |