Class: Actions::ForemanPipeline::Job::CreateHost

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/foreman_pipeline/job/create_host.rb

Instance Method Summary collapse

Instance Method Details

#plan(name, hostgroup, compute_resource, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/lib/actions/foreman_pipeline/job/create_host.rb', line 7

def plan(name, hostgroup, compute_resource, options = {})
  compute_attributes = hostgroup.compute_profile.compute_attributes
                        .where(compute_resource_id: compute_resource.id)
                        .first.vm_attrs

  plan_self name:               name,
            hostgroup_id:       hostgroup.id,
            compute_attributes: compute_attributes,
            options:            options
  input.update compute_resource_id: compute_resource.id if compute_resource
end

#runObject



19
20
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
# File 'app/lib/actions/foreman_pipeline/job/create_host.rb', line 19

def run
  hostgroup = Hostgroup.find(input[:hostgroup_id])
  location = Location.where(:name => "foreman_pipeline").first
  host = ::Host::Managed.new(
            name:                 input[:name],
            hostgroup:            hostgroup,
            build:                true,
            managed:              true,
            enabled:              true,
            environment:          hostgroup.environment,
            compute_resource_id:  input.fetch(:compute_resource_id),
            compute_attributes:   input[:compute_attributes],
            puppet_proxy:         hostgroup.puppet_proxy,
            puppet_ca_proxy:      hostgroup.puppet_ca_proxy,
            organization_id:      input[:options][:org_id],
            location:             location
          )

  organization_param
  keys_param
  host.apply_compute_profile(InterfaceMerge.new)
  host.save!
  jenkins_pubkey_param_for host
  host.power.start

  output.update host: { id: host.id,
                        name: host.name,
                        ip: host.ip,
                        mac: host.mac,
                        params: host.params }
end