Class: ForemanDeployments::Tasks::HostCreationTaskDefinition

Inherits:
CreationTaskDefinition show all
Defined in:
app/lib/foreman_deployments/tasks/host_creation_task_definition.rb

Defined Under Namespace

Classes: Action

Instance Attribute Summary

Attributes inherited from BaseDefinition

#parameters, #planned, #task_id

Class Method Summary collapse

Methods inherited from CreationTaskDefinition

build, create_output, #dynflow_action, #preliminary_output, set_parameters, tag_name, #validate

Methods inherited from BaseDefinition

#accept, build, #configuration, #configure, #dynflow_action, #initialize, #merge_configuration, #plan, #preliminary_output, tag_name, #to_hash, #validate

Constructor Details

This class inherits a constructor from ForemanDeployments::Tasks::BaseDefinition

Class Method Details

.create_object(parameters) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/lib/foreman_deployments/tasks/host_creation_task_definition.rb', line 12

def self.create_object(parameters)
  object_type = parameters['class']
  object_params = parameters['params']
  object_params['managed'] ||= true

  object_type = object_type.constantize if object_type.is_a? String

  initial_params = {
    :interfaces_attributes => object_params.delete('interfaces_attributes') || {}
  }

  object = object_type.new(initial_params)
  object = set_parameters(object, object_params)

  initialize_manged_host(object, object_params) if object.is_a? Host::Managed

  object
end

.initialize_manged_host(object, object_params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'app/lib/foreman_deployments/tasks/host_creation_task_definition.rb', line 31

def self.initialize_manged_host(object, object_params)
  object_params['build'] ||= true
  # Set compute attributes from a compute profile
  if object.compute_resource_id && object.compute_profile_id
    profile_attributes = object.compute_resource.compute_profile_attributes_for(object.compute_profile_id)
    object.compute_attributes = profile_attributes.merge(object.compute_attributes || {})
  end
  # Merge interfaces from a compute profile
  merge = InterfaceMerge.new
  merge.run(object.interfaces, object.compute_resource.try(:compute_profile_for, object.compute_profile_id))
end