Merge pull request #73 from cloudbees/master

Bunch O changes
This commit is contained in:
R. Tyler Croy 2013-03-29 14:37:48 -07:00
commit 18dac0cb0e
4 changed files with 38 additions and 10 deletions

View File

@ -11,5 +11,5 @@ group :development do
gem 'aruba'
gem 'tempdir'
gem 'pry'
gem 'debugger'
gem 'debugger' unless RUBY_VERSION =~ /1.8.+/
end

View File

@ -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 File

@ -13,7 +13,7 @@ module Blimpy
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 @@ module Blimpy
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 @@ module Blimpy
# 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 File

@ -142,8 +142,31 @@ end
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 @@ end
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