class Rundock::Builder::BackendBuilder

Attributes

parsed_options[RW]

Public Class Methods

new(options, nodename, node_info) click to toggle source
Calls superclass method
# File lib/rundock/builder/backend_builder.rb, line 6
def initialize(options, nodename, node_info)
  super(options)
  @nodename = nodename
  @node_info = node_info
end

Public Instance Methods

build() click to toggle source
# File lib/rundock/builder/backend_builder.rb, line 12
def build
  @parsed_options = build_options

  backend_type = parse_backend_type

  @parsed_options.merge!(@options)

  # update ssh options for node from node_info
  @parsed_options.merge!(@node_info[@nodename.to_sym][:ssh_opts])

  # add any attributes for host from node_info
  @parsed_options.merge!(@node_info[@nodename.to_sym])

  Backend.create(backend_type, @parsed_options)
end

Private Instance Methods

build_options() click to toggle source
# File lib/rundock/builder/backend_builder.rb, line 30
def build_options
  opts = {}

  if !@node_info ||
     !@node_info[@nodename.to_sym]
    @node_info = { @nodename.to_sym => {} }
  end
  @node_info[@nodename.to_sym][:ssh_opts] = {} unless @node_info[@nodename.to_sym][:ssh_opts]

  # replace default ssh options if exists
  @options.keys.select { |o| o.to_s =~ /(\w+)_ssh_default$/ }.each do |oo|
    # no use default ssh options if local
    # set unless scenario file and cli options specified and not localhost
    next if localhost?

    opt = oo.to_s.gsub(/_ssh_default/, '').to_sym
    @node_info[@nodename.to_sym][:ssh_opts][opt] = @options[oo] if !@node_info[@nodename.to_sym][:ssh_opts][opt] && !@options[opt]
  end

  # replace cli ssh options if exists
  %i[user key port ssh_config ask_password sudo].each { |o| @node_info[@nodename.to_sym][:ssh_opts][o] = @options[o] if @options[o] }

  opts[:host] = @nodename
  opts
end
localhost?() click to toggle source
# File lib/rundock/builder/backend_builder.rb, line 70
def localhost?
  @nodename =~ /localhost|127\.0\.0\.1/ ||
    @node_info[@nodename.to_sym][:host] =~ /localhost|127\.0\.0\.1/
end
parse_backend_type() click to toggle source
# File lib/rundock/builder/backend_builder.rb, line 56
def parse_backend_type
  backend_type = if localhost? &&
                    !@node_info[@nodename.to_sym][:ssh_opts][:port] &&
                    !@node_info[@nodename.to_sym][:ssh_opts][:user] &&
                    !@node_info[@nodename.to_sym][:ssh_opts][:ssh_config]
                   :local
                 else
                   :ssh

                 end

  backend_type
end