mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
commit
8767ee1f30
1 changed files with 15 additions and 9 deletions
|
@ -4,7 +4,7 @@ module Fog
|
|||
module Compute
|
||||
class Server < Fog::Model
|
||||
|
||||
attr_writer :username, :private_key, :private_key_path, :public_key, :public_key_path, :ssh_port
|
||||
attr_writer :username, :private_key, :private_key_path, :public_key, :public_key_path, :ssh_port, :ssh_options
|
||||
|
||||
def username
|
||||
@username ||= 'root'
|
||||
|
@ -32,13 +32,21 @@ module Fog
|
|||
@ssh_port ||= 22
|
||||
end
|
||||
|
||||
def ssh_options
|
||||
@ssh_options ||= {}
|
||||
ssh_options = @ssh_options.merge({:port => ssh_port})
|
||||
if private_key
|
||||
ssh_options[:key_data] = [private_key]
|
||||
ssh_options[:auth_methods] = ["publickey"]
|
||||
end
|
||||
ssh_options
|
||||
end
|
||||
|
||||
def scp(local_path, remote_path, upload_options = {})
|
||||
require 'net/scp'
|
||||
requires :public_ip_address, :username
|
||||
|
||||
scp_options = {:port => ssh_port}
|
||||
scp_options[:key_data] = [private_key] if private_key
|
||||
Fog::SCP.new(public_ip_address, username, scp_options).upload(local_path, remote_path, upload_options)
|
||||
Fog::SCP.new(public_ip_address, username, ssh_options).upload(local_path, remote_path, upload_options)
|
||||
end
|
||||
|
||||
alias_method :scp_upload, :scp
|
||||
|
@ -47,17 +55,15 @@ module Fog
|
|||
require 'net/scp'
|
||||
requires :public_ip_address, :username
|
||||
|
||||
scp_options = {:port => ssh_port}
|
||||
scp_options[:key_data] = [private_key] if private_key
|
||||
Fog::SCP.new(public_ip_address, username, scp_options).download(remote_path, local_path, download_options)
|
||||
Fog::SCP.new(public_ip_address, username, ssh_options).download(remote_path, local_path, download_options)
|
||||
end
|
||||
|
||||
def ssh(commands, options={}, &blk)
|
||||
require 'net/ssh'
|
||||
requires :public_ip_address, :username
|
||||
|
||||
options[:key_data] = [private_key] if private_key
|
||||
options[:port] ||= ssh_port
|
||||
options = ssh_options.merge(options)
|
||||
|
||||
Fog::SSH.new(public_ip_address, username, options).run(commands, &blk)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue