Class: ForemanDeployments::Tasks::CreationTaskDefinition

Inherits:
BaseDefinition
  • Object
show all
Defined in:
app/lib/foreman_deployments/tasks/creation_task_definition.rb

Direct Known Subclasses

HostCreationTaskDefinition

Defined Under Namespace

Classes: Action

Instance Attribute Summary

Attributes inherited from BaseDefinition

#parameters, #planned, #task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDefinition

#accept, #configuration, #configure, #initialize, #merge_configuration, #plan, #to_hash

Constructor Details

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

Class Method Details

.build(parameters) ⇒ Object


58
59
60
61
62
63
64
65
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 58

def self.build(parameters)
  case parameters['class']
  when 'Host', 'Host::Managed'
    HostCreationTaskDefinition.new(parameters)
  else
    CreationTaskDefinition.new(parameters)
  end
end

.create_object(parameters) ⇒ Object


28
29
30
31
32
33
34
35
36
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 28

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

  object_type = object_type.constantize if object_type.is_a? String
  object = object_type.new

  set_parameters(object, object_params)
end

.create_output(obj, output_hash = {}) ⇒ Object


49
50
51
52
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 49

def self.create_output(obj, output_hash = {})
  output_hash['object'] = obj
  output_hash
end

.set_parameters(object, object_params) ⇒ Object


38
39
40
41
42
43
44
45
46
47
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 38

def self.set_parameters(object, object_params)
  object_params.each do |key, value|
    if object.respond_to?("#{key}=")
      object.send("#{key}=", value)
      # TODO: else, add warning message
    end
  end

  object
end

.tag_nameObject


54
55
56
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 54

def self.tag_name
  'CreateResource'
end

Instance Method Details

#dynflow_actionObject


24
25
26
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 24

def dynflow_action
  self.class::Action
end

#preliminary_outputObject


20
21
22
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 20

def preliminary_output
  self.class.create_output(self.class.create_object(parameters.configured))
end

#validateObject


12
13
14
15
16
17
18
# File 'app/lib/foreman_deployments/tasks/creation_task_definition.rb', line 12

def validate
  obj = self.class.create_object(parameters.configured)
  obj.valid?
  ForemanDeployments::Validation::ValidationResult.new(obj.errors.full_messages)
rescue ActiveRecord::ActiveRecordError => e
  ForemanDeployments::Validation::ValidationResult.new([e.message])
end