lib/jamie.rb in jamie-0.1.0.alpha19 vs lib/jamie.rb in jamie-0.1.0.alpha20
- old
+ new
@@ -29,12 +29,12 @@
require 'net/scp'
require 'net/ssh'
require 'pathname'
require 'socket'
require 'stringio'
-require 'yaml'
require 'vendor/hash_recursive_merge'
+require 'yaml'
require 'jamie/version'
module Jamie
@@ -658,10 +658,24 @@
self
ensure
destroy if destroy_mode == :always
end
+ # Logs in to this instance by invoking a system command, provided by the
+ # instance's driver. This could be an SSH command, telnet, or serial
+ # console session.
+ #
+ # **Note** This method calls exec and will not return.
+ #
+ # @see Driver::Base#login_command
+ def login
+ command, *args = driver.login_command(load_state)
+
+ debug("Login command: #{command} #{args.join(' ')}")
+ Kernel.exec(command, *args)
+ end
+
private
def validate_options(opts)
%w(suite platform driver jr logger).each do |k|
raise ArgumentError, "Attribute '#{k}' is required." if opts[k].nil?
@@ -1026,11 +1040,11 @@
include ShellOut
include Logging
attr_writer :instance
- def initialize(config)
+ def initialize(config = {})
@config = config
self.class.defaults.each do |attr, value|
@config[attr] = value unless @config[attr]
end
end
@@ -1071,10 +1085,20 @@
#
# @param state [Hash] mutable instance and driver state
# @raise [ActionFailed] if the action could not be completed
def destroy(state) ; end
+ # Returns the shell command array that will log into an instance.
+ #
+ # @param state [Hash] mutable instance and driver state
+ # @return [Array] an array of command line tokens to be used in a
+ # fork/exec
+ # @raise [ActionFailed] if the action could not be completed
+ def login_command(state)
+ raise ActionFailed, "Remote login is not supported in this driver."
+ end
+
protected
attr_reader :config, :instance
def logger
@@ -1143,9 +1167,18 @@
end
end
def destroy(state)
raise NotImplementedError, "#destroy must be implemented by subclass."
+ end
+
+ def login_command(state)
+ args = %W{ -o UserKnownHostsFile=/dev/null }
+ args += %W{ -o StrictHostKeyChecking=no }
+ args += %W{ -i #{config['ssh_key']}} if config['ssh_key']
+ args += %W{ #{config['username']}@#{state['hostname']}}
+
+ ["ssh", *args]
end
protected
def build_ssh_args(state)