Skip to content
This repository
Browse code

Merge pull request #73 from cloudbees/master

Bunch O changes
  • Loading branch information...
commit 18dac0cb0e977a315357f1fe0e19182452242a38 2 parents 9eb01a5 + 86c8bf2
R. Tyler Croy authored
2  Gemfile
@@ -11,5 +11,5 @@ group :development do
11 11 gem 'aruba'
12 12 gem 'tempdir'
13 13 gem 'pry'
14   - gem 'debugger'
  14 + gem 'debugger' unless RUBY_VERSION =~ /1.8.+/
15 15 end
4 bin/blimpy
@@ -17,5 +17,9 @@ rescue LoadError
17 17 require 'blimpy/cli'
18 18 end
19 19
  20 +# allow monkey-patching of Blimpy by the project (mainly to add more commands)
  21 +blimprc = File.join(Dir.pwd,"Blimprc")
  22 +Blimpy.load_file File.open(blimprc).read if File.exists? blimprc
  23 +
20 24 Blimpy::CLI.start
21 25 exit 0
16 lib/blimpy/box.rb
@@ -13,7 +13,7 @@ class Box
13 13 attr_reader :allowed_regions, :region
14 14 attr_accessor :image_id, :flavor, :group, :ports
15 15 attr_accessor :dns, :internal_dns
16   - attr_accessor :name, :tags, :fleet_id, :username, :livery
  16 + attr_accessor :name, :tags, :fleet_id, :username, :ssh_port, :livery
17 17
18 18
19 19 def self.from_instance_id(an_id, data)
@@ -198,13 +198,9 @@ def run_command(*args)
198 198 end
199 199
200 200 def ssh_into(*args)
201   - # Support using #ssh_into within our own code as well to pass arguments
202   - # to the ssh(1) binary
203   - if args.empty?
204   - args = ARGV[2 .. -1]
205   - end
206 201 run_command('ssh', '-o', 'PasswordAuthentication=no',
207 202 '-o', 'StrictHostKeyChecking=no',
  203 + '-p', ssh_port||22.to_s,
208 204 '-l', username, dns, *args)
209 205 end
210 206
@@ -233,18 +229,24 @@ def wait_for_sshd
233 229 # after sshd(8) comes online
234 230 @exec_commands = false
235 231
  232 + $stdout.sync = true
  233 + need_nl = false
  234 +
236 235 until @ssh_connected
237 236 # Run the `true` command and exit
238 237 @ssh_connected = ssh_into('-q', 'true')
  238 + # if SSH is killed (such as Ctrl+C), abort right away
  239 + raise Exception, "ssh was killed: #{$?.exitstatus}" if $?.exitstatus>128
239 240
240 241 unless @ssh_connected
241 242 if (Time.now.to_i - start) < 60
242 243 print '.'
  244 + need_nl = true
243 245 sleep 1
244 246 end
245 247 end
246 248 end
247   - puts
  249 + puts if need_nl
248 250 @exec_commands = use_exec
249 251 end
250 252
26 lib/blimpy/cli.rb
@@ -142,8 +142,31 @@ def ssh(name=nil, *args)
142 142 end
143 143 end
144 144
  145 + box.ssh_into *args
  146 + end
  147 +
  148 + desc 'wait_for_ssh', 'Wait for SSHD to come online'
  149 + def wait_for_ssh(name=nil, *args)
  150 + unless name.nil?
  151 + box = box_by_name(name)
  152 + if box.nil?
  153 + puts "Could not find a blimp named \"#{name}\""
  154 + exit 1
  155 + end
  156 + else
  157 + blimps = current_blimps
  158 + unless blimps
  159 + puts "No Blimps running!"
  160 + exit 1
  161 + end
  162 +
  163 + blimps.each do |blimp, data|
  164 + next unless data[:name]
  165 + box = box_by_name(data[:name])
  166 + end
  167 + end
  168 +
145 169 box.wait_for_sshd
146   - box.ssh_into
147 170 end
148 171
149 172 desc 'scp BLIMP_NAME FILE_NAME', 'Securely copy FILE_NAME into the blimp'
@@ -154,7 +177,6 @@ def scp(name, filename, *args)
154 177 puts "Could not find a blimp named \"#{name}\""
155 178 exit 1
156 179 end
157   - box.wait_for_sshd
158 180 # Pass any extra commands along to the `scp` invocation
159 181 box.scp_file(filename, '', *ARGV[3..-1])
160 182 end

0 comments on commit 18dac0c

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