mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
added basic scp support
This commit is contained in:
parent
ad40758c84
commit
8ccbd4917d
3 changed files with 76 additions and 0 deletions
|
@ -186,6 +186,14 @@ module Fog
|
|||
Fog::SSH.new(ip_address, username, options).run(commands)
|
||||
end
|
||||
|
||||
def scp(local_path, remote_path)
|
||||
requires :ip_address, :username
|
||||
|
||||
options = {}
|
||||
options[:key_data] = [private_key] if private_key
|
||||
Fog::SCP.new(ip_address, username, options).upload(local_path, remote_path)
|
||||
end
|
||||
|
||||
def start
|
||||
requires :id
|
||||
connection.start_instances(id)
|
||||
|
|
|
@ -27,5 +27,6 @@ require 'fog/core/mock'
|
|||
require 'fog/core/provider'
|
||||
require 'fog/core/service'
|
||||
require 'fog/core/ssh'
|
||||
require 'fog/core/scp'
|
||||
require 'fog/core/time'
|
||||
require 'fog/core/wait_for'
|
||||
|
|
67
lib/fog/core/scp.rb
Normal file
67
lib/fog/core/scp.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
module Fog
|
||||
module SCP
|
||||
|
||||
def self.new(address, username, options = {})
|
||||
if Fog.mocking?
|
||||
Fog::SCP::Mock.new(address, username, options)
|
||||
else
|
||||
Fog::SCP::Real.new(address, username, options)
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset_data(keys=Mock.data.keys)
|
||||
Mock.reset_data(keys)
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(address, username, options)
|
||||
@address = address
|
||||
@username = username
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run(commands)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
def initialize(address, username, options)
|
||||
require 'net/scp'
|
||||
|
||||
key_manager = Net::SSH::Authentication::KeyManager.new(nil, options)
|
||||
|
||||
unless options[:key_data] || options[:keys] || options[:password] || key_manager.agent
|
||||
raise ArgumentError.new(':key_data, :keys, :password or a loaded ssh-agent is required to initialize SSH')
|
||||
end
|
||||
|
||||
@address = address
|
||||
@username = username
|
||||
@options = { :paranoid => false }.merge(options)
|
||||
end
|
||||
|
||||
def upload(local_path, remote_path)
|
||||
begin
|
||||
Net::SCP.start(@address, @username, @options) do |scp|
|
||||
scp.upload!(local_path, remote_path) do |ch, name, sent, total|
|
||||
# TODO: handle progress display?
|
||||
end
|
||||
end
|
||||
rescue Exception => error
|
||||
raise error
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue