From 9cad16f71f0a6febfe73fa7d3e96cb1965051be0 Mon Sep 17 00:00:00 2001 From: "geemus (Wesley Beary)" Date: Wed, 14 Apr 2010 20:32:56 -0700 Subject: [PATCH] add basic ssh command runner --- Gemfile | 1 + Rakefile | 1 + lib/fog.rb | 2 ++ lib/fog/ssh.rb | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 lib/fog/ssh.rb diff --git a/Gemfile b/Gemfile index 77a6e401f..996a243f5 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'excon', '>= 0.0.21' gem 'formatador', ">= 0.0.10" gem 'json', ">= 0" gem 'mime-types', ">= 0" +gem 'net-ssh', ">= 0" gem 'nokogiri', ">= 0" gem 'ruby-hmac', ">= 0" gem 'rspec', '>= 0' diff --git a/Rakefile b/Rakefile index c9f79cc7f..5dd5fa9e6 100644 --- a/Rakefile +++ b/Rakefile @@ -11,6 +11,7 @@ begin gem.add_dependency('formatador', '>=0.0.10') gem.add_dependency('json') gem.add_dependency('mime-types') + gem.add_dependency('net-ssh') gem.add_dependency('nokogiri') gem.add_dependency('ruby-hmac') gem.name = "fog" diff --git a/lib/fog.rb b/lib/fog.rb index fb8b8674d..d9ed387d8 100644 --- a/lib/fog.rb +++ b/lib/fog.rb @@ -8,6 +8,7 @@ require 'hmac-sha1' require 'hmac-sha2' require 'json' require 'mime/types' +require 'net/ssh' require 'nokogiri' require 'time' @@ -21,6 +22,7 @@ require 'fog/collection' require 'fog/connection' require 'fog/model' require 'fog/parser' +require 'fog/ssh' require 'fog/aws' require 'fog/rackspace' require 'fog/slicehost' diff --git a/lib/fog/ssh.rb b/lib/fog/ssh.rb new file mode 100644 index 000000000..6f1af30ca --- /dev/null +++ b/lib/fog/ssh.rb @@ -0,0 +1,31 @@ +module Fog + + class SSH + + def initialize(address, username, options = {}) + unless options[:keys] || options[:password] + raise ArgumentError.new(':keys or :password are required to initialize SSH') + end + @address = address + @username = username + @options = options.merge!(:paranoid => false) + end + + def run(commands) + commands = [*commands] + results = [] + Net::SSH.start(@address, @username, @options) do |ssh| + commands.each do |command| + result = { :command => command } + ssh.exec!("bash -lc #{command.inspect}") do |channel, stream, data| + result[stream] = data + end + results << result + end + end + results + end + + end + +end