Project

General

Profile

Download (1.89 KB) Statistics
| Branch: | Tag: | Revision:

foreman_pipeline / app / lib / actions / foreman_pipeline / job / redeploy.rb @ be52ca64

1
module Actions
2
  module ForemanPipeline
3
    module Job
4
      class Redeploy < Actions::EntryAction
5

    
6
        def plan(job)                 
7
          sequence do
8
            unique_hostname = "#{normalize_name job.name}-#{::Katello::Util::Model.uuid}"
9

    
10
            create_candlepin_key = plan_action(::Actions::Candlepin::ActivationKey::Create, :organization_label => job.content_view.organization.name) 
11
            create_key = plan_action(CreateActivationKey, :name => unique_hostname,
12
                                                          :organization_id => job.content_view.organization.id,
13
                                                          :environment_id => job.environment_id,
14
                                                          :content_view_id => job.content_view.id,
15
                                                          :cp_id => create_candlepin_key.output[:response][:id])
16

    
17
            create_host = plan_action(CreateHost, unique_hostname, job.hostgroup, job.compute_resource, { 
18
                           :org_id => job.content_view.organization.id,
19
                           :content_view_id => job.content_view.id,
20
                           :activation_key => create_key.output[:new_key],
21
                           :jenkins_instance_id => job.jenkins_instance_id})
22

    
23
            
24
            suspend_until = plan_action(SuspendUntilProvisioned, create_host.output[:host][:id])
25

    
26
            plan_self(:create_host => create_host.output[:host],
27
                      :installed_at => suspend_until.output[:installed_at],
28
                      :new_key => create_key.output[:new_key])
29
            
30
          end
31
        end
32

    
33
        def run
34
          output[:host] = input[:create_host]
35
          output[:activation_key] = input[:new_key]
36
        end
37

    
38
        private
39

    
40
        def normalize_name(repo_name)
41
          repo_name.gsub(/[^a-z0-9\-]/, '-')
42
        end
43

    
44
      end
45
    end
46
  end
47
end