Browse files

Merge pull request #73 from cloudbees/master

Bunch O changes
  • Loading branch information...
2 parents 9eb01a5 + 86c8bf2 commit 18dac0cb0e977a315357f1fe0e19182452242a38 @rtyler committed Mar 29, 2013
Showing with 38 additions and 10 deletions.
  1. +1 −1 Gemfile
  2. +4 −0 bin/blimpy
  3. +9 −7 lib/blimpy/box.rb
  4. +24 −2 lib/blimpy/cli.rb
View
2 Gemfile
@@ -11,5 +11,5 @@ group :development do
gem 'aruba'
gem 'tempdir'
gem 'pry'
- gem 'debugger'
+ gem 'debugger' unless RUBY_VERSION =~ /1.8.+/
end
View
4 bin/blimpy
@@ -17,5 +17,9 @@ rescue LoadError
require 'blimpy/cli'
end
+# allow monkey-patching of Blimpy by the project (mainly to add more commands)
+blimprc = File.join(Dir.pwd,"Blimprc")
+Blimpy.load_file File.open(blimprc).read if File.exists? blimprc
+
Blimpy::CLI.start
exit 0
View
16 lib/blimpy/box.rb
@@ -13,7 +13,7 @@ class Box
attr_reader :allowed_regions, :region
attr_accessor :image_id, :flavor, :group, :ports
attr_accessor :dns, :internal_dns
- attr_accessor :name, :tags, :fleet_id, :username, :livery
+ attr_accessor :name, :tags, :fleet_id, :username, :ssh_port, :livery
def self.from_instance_id(an_id, data)
@@ -198,13 +198,9 @@ def run_command(*args)
end
def ssh_into(*args)
- # Support using #ssh_into within our own code as well to pass arguments
- # to the ssh(1) binary
- if args.empty?
- args = ARGV[2 .. -1]
- end
run_command('ssh', '-o', 'PasswordAuthentication=no',
'-o', 'StrictHostKeyChecking=no',
+ '-p', ssh_port||22.to_s,
'-l', username, dns, *args)
end
@@ -233,18 +229,24 @@ def wait_for_sshd
# after sshd(8) comes online
@exec_commands = false
+ $stdout.sync = true
+ need_nl = false
+
until @ssh_connected
# Run the `true` command and exit
@ssh_connected = ssh_into('-q', 'true')
+ # if SSH is killed (such as Ctrl+C), abort right away
+ raise Exception, "ssh was killed: #{$?.exitstatus}" if $?.exitstatus>128
unless @ssh_connected
if (Time.now.to_i - start) < 60
print '.'
+ need_nl = true
sleep 1
end
end
end
- puts
+ puts if need_nl
@exec_commands = use_exec
end
View
26 lib/blimpy/cli.rb
@@ -142,8 +142,31 @@ def ssh(name=nil, *args)
end
end
+ box.ssh_into *args
+ end
+
+ desc 'wait_for_ssh', 'Wait for SSHD to come online'
+ def wait_for_ssh(name=nil, *args)
+ unless name.nil?
+ box = box_by_name(name)
+ if box.nil?
+ puts "Could not find a blimp named \"#{name}\""
+ exit 1
+ end
+ else
+ blimps = current_blimps
+ unless blimps
+ puts "No Blimps running!"
+ exit 1
+ end
+
+ blimps.each do |blimp, data|
+ next unless data[:name]
+ box = box_by_name(data[:name])
+ end
+ end
+
box.wait_for_sshd
- box.ssh_into
end
desc 'scp BLIMP_NAME FILE_NAME', 'Securely copy FILE_NAME into the blimp'
@@ -154,7 +177,6 @@ def scp(name, filename, *args)
puts "Could not find a blimp named \"#{name}\""
exit 1
end
- box.wait_for_sshd
# Pass any extra commands along to the `scp` invocation
box.scp_file(filename, '', *ARGV[3..-1])
end

0 comments on commit 18dac0c

Please sign in to comment.