Class: Rundock::Builder::TargetBuilder

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

Constant Summary collapse

DEFAULT_TARGET_TYPE =
'host'

Constants inherited from Base

Base::BuilderNotImplementedError

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Instance Method Details

#build(target_name, target_info) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rundock/builder/target_builder.rb', line 6

def build(target_name, target_info)
  target_type = DEFAULT_TARGET_TYPE

  if target_info.nil? ||
     !target_info.key?(target_name.to_sym)
    target_info = { target_name.to_sym => {} }
    target_type = DEFAULT_TARGET_TYPE
  else
    target_type = if target_info[target_name.to_sym].key?(:target_type)
                    target_info[target_name.to_sym][:target_type]
                  else
                    DEFAULT_TARGET_TYPE
                  end
  end

  begin
    target = Rundock::TargetFactory.instance(target_type).create(target_name, target_info[target_name.to_sym])
  rescue Rundock::TargetFactory::TargetNotSupportedError
    Logger.error("target type not supported: #{target_type}")
  end

  target.create_nodes(target_info, @options)
end