Sha256: e41b50abc7abeceac855db1d4fda0e1a97e331ce3dccc2d4e5206062d9724cb1

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'rundock'
require 'open-uri'

module Rundock
  class Runner
    ScenarioNotFoundError = Class.new(StandardError)

    class << self
      def run(options)
        Logger.info 'Starting Rundoc:'

        runner = self.new(options)
        runner.build(options)
        runner.run
      end
    end

    attr_reader :scenario

    def initialize(options)
      @options = options
    end

    def run
      @scenario.run
    end

    def build(options)
      if options['scenario_yaml'] || options['hostgroup_yaml']
        if options['scenario_yaml'] && !FileTest.exist?(options['scenario_yaml'])
          raise ScenarioNotFoundError, "'#{options['scenario_yaml']}' scenario file is not found."
        elsif options['hostgroup_yaml'] && !FileTest.exist?(options['hostgroup_yaml'])
          raise ScenarioNotFoundError, "'#{options['hostgroup_yaml']}' hostgroup file is not found."
        end

        options['scenario_yaml'] = options['hostgroup_yaml'] if options['hostgroup_yaml']

        # parse scenario
        if options['scenario_yaml'] =~ %r{^(http|https)://}
          # read from http/https
          open(options['scenario_yaml']) do |f|
            @scenario = Rundock::Builder::ScenarioBuilder.new(options, f).build
          end
        else
          File.open(options['scenario_yaml']) do |f|
            @scenario = Rundock::Builder::ScenarioBuilder.new(options, f).build
          end
        end
      else
        # do rundock ssh
        @scenario = Rundock::Builder::ScenarioBuilder.new(options, nil).build
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rundock-0.2.0 lib/rundock/runner.rb