Sha256: 8e6ec47b08accb586d2d63a6919fffd5ddb71d83fb5a8a00f991a8611971a5a9

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module VagrantPlugins
  module ProviderLocal
    module Command
      # This is used to start a VNC console to the guest
      class VNCConsole < Vagrant.plugin('2', :command)
        def execute
          options = {}
          opts = OptionParser.new do |o|
            o.banner = 'Usage: vagrant local console vnc [options]'
            o.on('--ip <host_ip>', 'Specify host IP to listen on') do |p|
              options[:ip] = p
            end
            o.on('--port <port>', 'Specify port to listen on') do |p|
              options[:port] = p
            end
            o.on('--detach <yes/no>', 'Run console server in background') do |p|
              options[:detach] = p
            end
            o.on('--kill <yes/no>', 'Kill the previous background console session') do |p|
              options[:kill] = p
            end
          end

          argv = parse_options(opts)
          return unless argv

          unless argv.length <= 4
            @env.ui.info(opts.help)
            return
          end

          options[:port] = nil unless options[:port] =~ /\d/
          with_target_vms(argv, provider: :local) do |machine|
            driver = machine.provider.driver
            detach = 'yes'
            detach = 'no' unless options[:detach] == 'yes'
            kill = 'yes'
            kill = 'no' unless options[:kill] == 'yes'
            exit = { detach: detach, kill: kill }
            driver.console(@env.ui, 'vnc', options[:ip], options[:port], exit)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-local-0.0.3 lib/vagrant-local/command/vnc_console.rb
vagrant-local-0.0.2 lib/vagrant-local/command/vnc_console.rb
vagrant-local-0.0.1 lib/vagrant-local/command/vnc_console.rb