class Rundock::Builder::ScenarioBuilder

Constants

CommandArgNotFoundError

Public Class Methods

new(options, scenario_file_data) click to toggle source
Calls superclass method Rundock::Builder::Base::new
# File lib/rundock/builder/scenario_builder.rb, line 8
def initialize(options, scenario_file_data)
  super(options)
  @scenario_file = scenario_file_data
  @default_ssh_builder = DefaultSshBuilder.new(@options)
end

Public Instance Methods

build() click to toggle source
# File lib/rundock/builder/scenario_builder.rb, line 14
def build
  # parse default ssh file
  @options.merge!(@default_ssh_builder.build)

  # use host specified
  return build_scenario_with_cli if @options[:host]

  # use scenario file
  build_scenario_with_file
end
build_task(tasks, backend, target_attributes) click to toggle source
# File lib/rundock/builder/scenario_builder.rb, line 25
def build_task(tasks, backend, target_attributes)
  OperationBuilder.new(@options).build_task(tasks, backend, target_attributes)
end

Private Instance Methods

build_scenario_with_cli() click to toggle source
# File lib/rundock/builder/scenario_builder.rb, line 31
def build_scenario_with_cli
  raise CommandArgNotFoundError, %("--command or -c" option is not specified.) unless @options[:command]

  ope = OperationBuilder.new(@options)
  ope.build_cli
end
build_scenario_with_file() click to toggle source
# File lib/rundock/builder/scenario_builder.rb, line 38
def build_scenario_with_file
  if @scenario_file

    type = %i[main target_info tasks hooks]
    scenario_data = {}

    YAML.load_stream(@scenario_file).each_with_index do |data, idx|
      if idx == 0
        scenario_data[type[idx]] = data
      else
        scenario_data[type[idx]] = data.deep_symbolize_keys unless data.nil?
      end
    end
  end

  ope = OperationBuilder.new(@options)
  ope.build_first(
    scenario_data[:main],
    @options[:command] ? scenario_data[:target_info] : TargetGroupBuilder.new(@options).build(scenario_data[:target_info]),
    TaskBuilder.new(@options).build(scenario_data[:tasks]),
    scenario_data[:hooks]
  )
end