Object
# File lib/blimpy/box.rb, line 19 def self.from_instance_id(an_id, data) return if data[:type].nil? name = data[:type].to_sym return unless Blimpy::Boxes.const_defined? name klass = Blimpy::Boxes.const_get(name) server = klass.fog_server_for_instance(an_id, data) return if server.nil? box = klass.new(server) box.with_data(an_id, data) box end
# File lib/blimpy/box.rb, line 77 def bootstrap @exec_commands = false if @livery.nil? return end if @livery.respond_to? :new @livery = @livery.new end wait_for_sshd bootstrap_livery end
# File lib/blimpy/box.rb, line 222 def bootstrap_livery if @livery.kind_of? Symbol raise Blimpy::InvalidLiveryException, 'Symbol liveries are unsupported!' end @livery.setup_on(self) @livery.preflight(self) @livery.flight(self) @livery.postflight(self) end
# File lib/blimpy/box.rb, line 111 def destroy unless @server.nil? predestroy @server.destroy postdestroy File.unlink(state_file) end end
# File lib/blimpy/box.rb, line 272 def fog raise NotImplementedError, '#fog should be implemented by cloud-specific subclasses' end
# File lib/blimpy/box.rb, line 133 def immutable_attributes [:type] end
This is just here to make things more consistent from an API perspective
# File lib/blimpy/box.rb, line 92 def provision bootstrap end
# File lib/blimpy/box.rb, line 48 def region=(newRegion) unless (@allowed_regions.nil?) || (@allowed_regions.include?(newRegion)) raise InvalidRegionError end @region = newRegion end
# File lib/blimpy/box.rb, line 102 def resume unless @server.nil? @server.start end end
# File lib/blimpy/box.rb, line 192 def run_command(*args) if @exec_commands ::Kernel.exec(*args) else ::Kernel.system(*args) end end
# File lib/blimpy/box.rb, line 211 def scp_file(filename, directory='', *args) filename = File.expand_path(filename) run_command('scp', '-o', 'StrictHostKeyChecking=no', filename, "#{username}@#{dns}:#{directory}", *args) end
# File lib/blimpy/box.rb, line 217 def scp_files(directory, files) filename = File.expand_path(filename) run_command(*['scp', '-o', 'StrictHostKeyChecking=no']+files+["#{username}@#{dns}:#{directory}"]) end
# File lib/blimpy/box.rb, line 129 def serializable_attributes [:type, :name, :region, :dns, :internal_dns, :flavor, :tags] end
# File lib/blimpy/box.rb, line 200 def ssh_commands(*args) ['ssh', '-o', 'PasswordAuthentication=no', '-o', 'StrictHostKeyChecking=no', '-p', (ssh_port||22).to_s, '-l', username, dns, *args] end
# File lib/blimpy/box.rb, line 207 def ssh_into(*args) run_command(*ssh_commands(*args)) end
# File lib/blimpy/box.rb, line 66 def start ensure_state_folder prestart @server = create_host poststart write_state_file end
# File lib/blimpy/box.rb, line 147 def state_file if @server.nil? raise Exception, "I can't make a state file without a @server!" end File.join(state_folder, "#{@server.id}.blimp") end
# File lib/blimpy/box.rb, line 96 def stop unless @server.nil? @server.stop end end
# File lib/blimpy/box.rb, line 123 def type # We only really care about the class name as part of the Blimpy::Boxes # module self.class.to_s.split('::').last end
# File lib/blimpy/box.rb, line 59 def validate! raise NotImplementedError, '#validate! should be defined in a subclass of Blimpy::Box' end
# File lib/blimpy/box.rb, line 233 def wait_for_sshd return if @ssh_connected start = Time.now.to_i use_exec = @exec_commands # Even if we are supposed to use #exec here, we wait to disable it until # 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, don't repeat if $?.signaled? if $?.termsig==2 # if Ctrl+C, report what we were doing puts "Failed to connect. To try it yourself:\n#{ssh_commands('-v','true').join(' ')}" end raise Exception, "ssh was killed: #{$?}" end unless @ssh_connected if !need_nl p = ssh_port.nil? ? "" : ":#{ssh_port}" print ">> Connecting #{username}@#{name}#{p}" end if (Time.now.to_i - start) < 60 print '.' need_nl = true sleep 1 end end end puts if need_nl @exec_commands = use_exec end
# File lib/blimpy/box.rb, line 154 def wait_for_state(until_state, &block) if @server.nil? return end @server.wait_for do block.call state == until_state end end
Generated with the Darkfish Rdoc Generator 2.