Sha256: 4e4186715e48dca25c153ff32be0b820f0eae886c2c3531a0e86ed895f6d71b2

Contents?: true

Size: 1.85 KB

Versions: 12

Compression:

Stored size: 1.85 KB

Contents

require 'veewee/provider/core/helper/scancode'
require 'veewee/provider/core/helper/tcp'
require 'veewee/provider/core/helper/shell'

module Veewee
  module Provider
    module Virtualbox
      module BoxCommand
        def console_type(sequence)
          send_virtualbox_sequence(sequence)
        end

        def send_virtualbox_sequence(sequence)

          ui.info ""

          counter=0
          sequence.each { |s|
            counter=counter+1

            ui.info "Typing:[#{counter}]: "+s

            keycodes=Veewee::Provider::Core::Helper::Scancode.string_to_keycode(s)

            env.logger.info "Sending keycodes: #{keycodes}"

            # VBox seems to have issues with sending the scancodes as one big
            # .join()-ed string. It seems to get them out or order or ignore some.
            # A workaround is to send the scancodes one-by-one.
            codes=""
            for keycode in keycodes.split(' ') do
              unless keycode=="wait"
                send_keycode(keycode)
                sleep 0.01
              else
                sleep 1
              end
            end
            #sleep after each sequence (needs to be param)
            sleep 0.5
          }

          ui.info "Done typing."
          ui.info ""

        end

        def send_keycode(keycode)
          command= "#{@vboxcmd} controlvm \"#{name}\" keyboardputscancode #{keycode}"
          env.logger.debug "#{command}"
          sshresult=shell_exec("#{command}",{:mute => true})
          unless sshresult.stdout.index("E_ACCESSDENIED").nil?
            error= "There was an error typing the commands on the console"
            error+="Probably the VM did not get started."
            error+= ""
            error+= "#{sshresult.stdout}"
            raise Veewee::Error, error
          end
        end

      end #Module
    end #Module
  end #Module
end #Module

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
veewee-0.4.5.1 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.4.5 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.4.5.pre1 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.4.4 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.4.3 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.4.2 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.4.1 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.4.0 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.3.12 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.3.11 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.3.10 lib/veewee/provider/virtualbox/box/helper/console_type.rb
veewee-0.3.9 lib/veewee/provider/virtualbox/box/helper/console_type.rb