mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[core] Adds ssh_ip_address=
so users can override the ssh address per issue #2584
This commit is contained in:
parent
69e7b0aeaf
commit
9a31161c92
5 changed files with 34 additions and 9 deletions
|
@ -42,6 +42,9 @@ module Fog
|
|||
attr_accessor :network_ids, :disk_offering_id, :ip_address, :ip_to_network_list
|
||||
attr_writer :security_group_ids
|
||||
|
||||
alias_method :public_ip_address, :ip_address
|
||||
alias_method :public_ip_address=, :ip_address=
|
||||
|
||||
def addresses
|
||||
nics.map{|nic| Address.new(nic)}
|
||||
end
|
||||
|
|
|
@ -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, :ssh_options
|
||||
attr_writer :username, :private_key, :private_key_path, :public_key, :public_key_path, :ssh_port, :ssh_ip_address, :ssh_options
|
||||
|
||||
def username
|
||||
@username ||= 'root'
|
||||
|
@ -28,10 +28,20 @@ module Fog
|
|||
@public_key ||= public_key_path && File.read(public_key_path)
|
||||
end
|
||||
|
||||
# Port used for ssh/scp interactions with server.
|
||||
# @return [Integer] IP port
|
||||
# @note By default this returns 22
|
||||
def ssh_port
|
||||
@ssh_port ||= 22
|
||||
end
|
||||
|
||||
# IP Address used for ssh/scp interactions with server.
|
||||
# @return [String] IP Address
|
||||
# @note By default this returns the public_ip_address
|
||||
def ssh_ip_address
|
||||
@ssh_ip_address ||= public_ip_address
|
||||
end
|
||||
|
||||
def ssh_options
|
||||
@ssh_options ||= {}
|
||||
ssh_options = @ssh_options.merge({:port => ssh_port})
|
||||
|
@ -46,29 +56,29 @@ module Fog
|
|||
require 'net/scp'
|
||||
requires :public_ip_address, :username
|
||||
|
||||
Fog::SCP.new(public_ip_address, username, ssh_options).upload(local_path, remote_path, upload_options)
|
||||
Fog::SCP.new(ssh_ip_address, username, ssh_options).upload(local_path, remote_path, upload_options)
|
||||
end
|
||||
|
||||
alias_method :scp_upload, :scp
|
||||
|
||||
def scp_download(remote_path, local_path, download_options = {})
|
||||
require 'net/scp'
|
||||
requires :public_ip_address, :username
|
||||
requires :ssh_ip_address, :username
|
||||
|
||||
Fog::SCP.new(public_ip_address, username, ssh_options).download(remote_path, local_path, download_options)
|
||||
Fog::SCP.new(ssh_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
|
||||
requires :ssh_ip_address, :username
|
||||
|
||||
options = ssh_options.merge(options)
|
||||
|
||||
Fog::SSH.new(public_ip_address, username, options).run(commands, &blk)
|
||||
Fog::SSH.new(ssh_ip_address, username, options).run(commands, &blk)
|
||||
end
|
||||
|
||||
def sshable?(options={})
|
||||
ready? && !public_ip_address.nil? && !!Timeout::timeout(8) { ssh('pwd', options) }
|
||||
ready? && !ssh_ip_address.nil? && !!Timeout::timeout(8) { ssh('pwd', options) }
|
||||
rescue SystemCallError, Net::SSH::AuthenticationFailed, Net::SSH::Disconnect, Timeout::Error
|
||||
false
|
||||
end
|
||||
|
|
|
@ -11,14 +11,24 @@ for provider, config in compute_providers
|
|||
if Fog.mocking? && !config[:mocked]
|
||||
pending
|
||||
else
|
||||
responds_to(:boostrap)
|
||||
responds_to(:public_ip_address)
|
||||
responds_to(:scp)
|
||||
responds_to(:ssh)
|
||||
end
|
||||
|
||||
tests('ssh_ip_address') do
|
||||
tests('defaults to public_ip_address').returns(true) do
|
||||
@instance.ssh_ip_address == @instance.public_ip_address
|
||||
end
|
||||
tests('ssh_ip_address overrides default').returns(true) do
|
||||
ip_address = '5.5.5.5'
|
||||
# @instance.public_ip_address = '12.12.12.12'
|
||||
@instance.ssh_ip_address = ip_address
|
||||
@instance.ssh_ip_address == ip_address
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -10,6 +10,7 @@ def server_tests(connection, params = {}, mocks_implemented = true)
|
|||
end
|
||||
|
||||
responds_to([:ready?, :state])
|
||||
yield if block_given?
|
||||
|
||||
tests('#reboot').succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
|
|
|
@ -4,6 +4,7 @@ def servers_tests(connection, params = {}, mocks_implemented = true)
|
|||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@instance.wait_for { ready? }
|
||||
yield if block_given?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue