зеркало из https://github.com/microsoft/fog.git
add basic ssh command runner
This commit is contained in:
Родитель
5981bee1c8
Коммит
9cad16f71f
1
Gemfile
1
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'
|
||||
|
|
1
Rakefile
1
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"
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче