Skip to content
Browse files

Merge pull request #7 from aaronfeng/master

vpc
  • Loading branch information...
2 parents 4bbc20b + 3941a84 commit eb2ccbec925c46992c6a4f594569fb2821cfad97 @wbailey committed
Showing with 39 additions and 7 deletions.
  1. +12 −2 lib/claws/command/ec2.rb
  2. +27 −5 spec/command/ec2_spec.rb
View
14 lib/claws/command/ec2.rb
@@ -33,11 +33,21 @@ def self.exec(options)
puts 'connecting to server...'
- identity = config.ssh.identity.nil? ? '' : "-i #{config.ssh.identity} "
+ identity = config.ssh.identity.nil? ? '' : "-i #{config.ssh.identity}"
+ current_instance = instances[selection.to_i]
+ ssh_opts = {:identity => identity, :ssh_user => config.ssh.user}
- system "ssh #{identity}#{config.ssh.user}@#{instances[selection.to_i].dns_name}"
+ if instances[selection.to_i].vpc?
+ ssh(ssh_opts.merge(:host => current_instance.private_ip_address))
+ else
+ ssh(ssh_opts.merge(:host => current_instance.dns_name))
+ end
end
end
+
+ def self.ssh(opts={})
+ system "ssh #{opts[:identity]} #{opts[:ssh_user]}@#{opts[:host]}"
+ 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'),
]
@@ -119,10 +119,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 -i my_id 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
@@ -143,9 +165,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 eb2ccbe

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