2011-08-11 12:53:52 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Server < Fog::Model
|
|
|
|
|
2012-05-23 18:18:16 -04:00
|
|
|
def private_key=(key_data)
|
|
|
|
@private_key = key_data
|
|
|
|
end
|
|
|
|
|
2011-08-11 12:53:52 -04:00
|
|
|
def scp(local_path, remote_path, upload_options = {})
|
|
|
|
require 'net/scp'
|
|
|
|
requires :public_ip_address, :username
|
|
|
|
|
2012-06-21 17:56:12 -04:00
|
|
|
scp_options = {:port => ssh_port}
|
2011-08-11 12:53:52 -04:00
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
2011-12-09 08:14:53 -05:00
|
|
|
alias_method :scp_upload, :scp
|
|
|
|
|
|
|
|
def scp_download(remote_path, local_path, download_options = {})
|
|
|
|
require 'net/scp'
|
|
|
|
requires :public_ip_address, :username
|
|
|
|
|
2012-06-21 17:56:12 -04:00
|
|
|
scp_options = {:port => ssh_port}
|
2011-12-09 08:14:53 -05:00
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
2012-05-23 18:28:02 -04:00
|
|
|
def ssh(commands, options={}, &blk)
|
2011-08-11 12:53:52 -04:00
|
|
|
require 'net/ssh'
|
|
|
|
requires :public_ip_address, :username
|
|
|
|
|
|
|
|
options[:key_data] = [private_key] if private_key
|
2012-06-21 17:56:12 -04:00
|
|
|
options[:port] ||= ssh_port
|
2012-05-23 18:28:02 -04:00
|
|
|
Fog::SSH.new(public_ip_address, username, options).run(commands, &blk)
|
2011-08-11 12:53:52 -04:00
|
|
|
end
|
|
|
|
|
2012-06-21 17:56:12 -04:00
|
|
|
def ssh_port
|
|
|
|
22
|
|
|
|
end
|
|
|
|
|
2012-05-23 18:23:24 -04:00
|
|
|
def sshable?
|
2012-05-23 18:46:14 -04:00
|
|
|
ready? && !public_ip_address.nil? && !!Timeout::timeout(8) { ssh 'pwd' }
|
|
|
|
rescue SystemCallError, Net::SSH::AuthenticationFailed, Timeout::Error
|
|
|
|
false
|
2012-05-23 18:23:24 -04:00
|
|
|
end
|
|
|
|
|
2011-08-11 12:53:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|