Skip to content
Browse files

use private ip address when vpc is enabled

  • Loading branch information...
1 parent 0879ee1 commit cf31fa892daa60a6a9dfd45a55adbe852838f686 @aaronfeng aaronfeng committed
Showing with 32 additions and 6 deletions.
  1. +5 −1 lib/claws/command/ec2.rb
  2. +27 −5 spec/command/ec2_spec.rb
View
6 lib/claws/command/ec2.rb
@@ -33,7 +33,11 @@ def self.exec(options)
puts 'connecting to server...'
- system "ssh #{config.ssh.user}@#{instances[selection.to_i].dns_name}"
+ if instances[selection.to_i].vpc?
+ system "ssh #{config.ssh.user}@#{instances[selection.to_i].private_ip_address}"
+ else
+ system "ssh #{config.ssh.user}@#{instances[selection.to_i].dns_name}"
+ end
end
end
end
View
32 spec/command/ec2_spec.rb
@@ -52,7 +52,7 @@
context 'instance collections' do
it 'retrieves' do
Claws::Collection::EC2.should_receive(:new).and_return(
- double(Claws::Collection::EC2, :get =>
+ double(Claws::Collection::EC2, :get =>
[
double(AWS::EC2::Instance, :id => 'test', :status => 'running', :dns_name => 'test.com'),
]
@@ -117,10 +117,32 @@
)
end
+ context 'vpc' do
+ let(:instances) do
+ [
+ double(AWS::EC2::Instance, :id => 'test', :status => 'running', :private_ip_address => 'secret.com', :vpc? => true)
+ ]
+ end
+
+ it 'automatically connects to the server using private ip address' do
+ Claws::Collection::EC2.should_receive(:new).and_return(
+ double(Claws::Collection::EC2, :get => instances)
+ )
+
+ subject.should_receive(:puts).twice
+ subject.should_receive(:system).with('ssh test@secret.com').and_return(0)
+
+ capture_stdout {
+ subject.exec options
+ }
+ end
+
+ end
+
context 'single instance' do
let(:instances) do
[
- double(AWS::EC2::Instance, :id => 'test', :status => 'running', :dns_name => 'test.com')
+ double(AWS::EC2::Instance, :id => 'test', :status => 'running', :dns_name => 'test.com', :vpc? => false)
]
end
@@ -141,9 +163,9 @@
context 'multiple instances' do
let(:instances) do
[
- double(AWS::EC2::Instance, :id => 'test1', :status => 'running', :dns_name => 'test1.com'),
- double(AWS::EC2::Instance, :id => 'test2', :status => 'running', :dns_name => 'test2.com'),
- double(AWS::EC2::Instance, :id => 'test3', :status => 'running', :dns_name => 'test3.com'),
+ double(AWS::EC2::Instance, :id => 'test1', :status => 'running', :dns_name => 'test1.com', :vpc? => false),
+ double(AWS::EC2::Instance, :id => 'test2', :status => 'running', :dns_name => 'test2.com', :vpc? => false),
+ double(AWS::EC2::Instance, :id => 'test3', :status => 'running', :dns_name => 'test3.com', :vpc? => false),
]
end

0 comments on commit cf31fa8

Please sign in to comment.
Something went wrong with that request. Please try again.