Class: Rundock::Builder::OperationBuilder

Inherits:
Base show all
Defined in:
lib/rundock/builder/operation_builder.rb

Constant Summary

Constants inherited from Base

Base::BuilderNotImplementedError

Instance Method Summary collapse

Methods inherited from Base

#build, #initialize

Constructor Details

This class inherits a constructor from Rundock::Builder::Base

Instance Method Details

#build_cliObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rundock/builder/operation_builder.rb', line 70

def build_cli
  scen = Scenario.new

  @options[:host].split(',').each do |host|
    backend = BackendBuilder.new(@options, host, nil).build
    node = Node.new(host, backend)
    node.hooks = HookBuilder.new(@options).build(['all'], nil)
    node.add_operation(
      build_cli_command_operation(
        @options[:command],
        Rundock::Attribute::NodeAttribute.new,
        @options
      )
    )
    scen.nodes.push(node)
  end

  scen
end

#build_first(scenario, targets, tasks, hooks) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
50
51
52
53
54
55
# File 'lib/rundock/builder/operation_builder.rb', line 4

def build_first(scenario, targets, tasks, hooks)
  parsing_node_attribute = nil
  scen = Scenario.new
  scen.tasks = tasks

  scenario.each do |sn|
    nodes = []
    operations = []
    hook_contents = []

    sn.deep_symbolize_keys.each do |sk, sv|
      if sk == :target
        target_builder = TargetBuilder.new(@options)
        target = target_builder.build(sv, targets)

        if target.is_a?(Node)
          nodes = Array(target)
          parsing_node_attribute = build_node_attribute(scen, sv, parsing_node_attribute, tasks, target_builder.parsed_node_options[sv.to_sym])
          operations = Array(build_cli_command_operation(@options[:command], parsing_node_attribute, @options)) if @options[:command]
        end
      elsif sk == :target_group
        target_builder = TargetBuilder.new(@options)
        nodes = target_builder.build_group(sv, targets)
        nodes.each do |n|
          if n.is_a?(Node)
            parsing_node_attribute = build_node_attribute(scen, n.name, parsing_node_attribute, tasks, target_builder.parsed_node_options[n.name.to_sym])
            operations = Array(build_cli_command_operation(@options[:command], parsing_node_attribute, @options)) if @options[:command]
          end
        end
      elsif sk == :hook
        hooks_builder = HookBuilder.new(@options)
        hook_contents = hooks_builder.build(Array(sv), hooks)
        parsing_node_attribute.hooks = hooks_builder.enable_hooks
      else
        ope = build_operations(sk, Array(sv), parsing_node_attribute, @options, false)
        operations << ope if ope
      end
    end

    nodes.each do |n|
      operations.each do |o|
        n.add_operation(o)
      end

      n.hooks = hook_contents
    end

    scen.nodes.concat(nodes)
  end

  scen
end

#build_task(tasks, backend, node_attribute) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rundock/builder/operation_builder.rb', line 57

def build_task(tasks, backend, node_attribute)
  node = Node.new(node_attribute.nodename, backend)
  scen = Scenario.new

  tasks.each do |k, v|
    ope = build_operations(k, Array(v), node_attribute, nil, true)
    node.add_operation(ope) if ope
  end

  scen.nodes.push(node) if node
  scen
end