diff --git a/lib/fog/cloudstack/models/compute/server.rb b/lib/fog/cloudstack/models/compute/server.rb index 0dbd278f0..709382b5a 100644 --- a/lib/fog/cloudstack/models/compute/server.rb +++ b/lib/fog/cloudstack/models/compute/server.rb @@ -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 diff --git a/lib/fog/compute/models/server.rb b/lib/fog/compute/models/server.rb index 7f5f172b1..546aaff77 100644 --- a/lib/fog/compute/models/server.rb +++ b/lib/fog/compute/models/server.rb @@ -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 diff --git a/tests/compute/models/server_tests.rb b/tests/compute/models/server_tests.rb index 151feee93..3161152ab 100644 --- a/tests/compute/models/server_tests.rb +++ b/tests/compute/models/server_tests.rb @@ -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 diff --git a/tests/helpers/compute/server_helper.rb b/tests/helpers/compute/server_helper.rb index a8cd1df45..3d37a965d 100644 --- a/tests/helpers/compute/server_helper.rb +++ b/tests/helpers/compute/server_helper.rb @@ -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 diff --git a/tests/helpers/compute/servers_helper.rb b/tests/helpers/compute/servers_helper.rb index 643a1233f..dfa6cadad 100644 --- a/tests/helpers/compute/servers_helper.rb +++ b/tests/helpers/compute/servers_helper.rb @@ -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