Sha256: 75cd192109e7ceaa56aff3901a7e44dd112a79fd25ef69b403bc083cc73fd085

Contents?: true

Size: 1.55 KB

Versions: 25

Compression:

Stored size: 1.55 KB

Contents

require 'yaml'

module Rundock
  module Builder
    class ScenarioBuilder < Base
      CommandArgNotFoundError = Class.new(StandardError)

      def initialize(options, scenario_file_data)
        super(options)
        @scenario_file = scenario_file_data
        @default_ssh_builder = DefaultSshBuilder.new(@options)
      end

      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

      def build_task(tasks, backend, node_attributes)
        OperationBuilder.new(@options).build_task(tasks, backend, node_attributes)
      end

      private

      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

      def build_scenario_with_file
        if @scenario_file

          type = [:main, :node_info, :tasks]
          scenario_data = {}

          YAML.load_documents(@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], scenario_data[:node_info], scenario_data[:tasks])
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
rundock-0.2.6 lib/rundock/builder/scenario_builder.rb
rundock-0.2.5 lib/rundock/builder/scenario_builder.rb
rundock-0.2.4 lib/rundock/builder/scenario_builder.rb
rundock-0.2.3 lib/rundock/builder/scenario_builder.rb
rundock-0.2.2 lib/rundock/builder/scenario_builder.rb