Sha256: 10794161611ec8910f9f7ac553d2042e03294b477ebce9c32ff575e38fb1a0f9

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'rundock'
require 'open-uri'

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

    class << self
      def run(options)
        Logger.debug '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 run_tasks
      @scenario.run
    end

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

        options[:scenario] = options[:hostgroup] if options[:hostgroup]

        # parse scenario
        if options[:scenario] =~ %r{^(http|https)://}
          # read from http/https
          open(options[:scenario]) do |f|
            @scenario = Rundock::Builder::ScenarioBuilder.new(options, f).build
          end
        else
          File.open(options[:scenario]) 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.2 lib/rundock/runner.rb