Class: VagrantPlugins::RDP::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-rdp/command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vagrant-rdp/command.rb', line 7

def execute
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: vagrant rdp [vm-name...]"

    opts.separator ""
  end

  argv = parse_options(opts)
  return -1 if !argv

  with_target_vms(argv) do |vm|
    @logger.info("Launching remote desktop session to: #{vm.name}")
    rdp_connect(vm)
  end

  return 0
end

#rdp_connect(vm) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vagrant-rdp/command.rb', line 25

def rdp_connect(vm)
  rdpport = nil
  vm.provider.driver.read_forwarded_ports.each do |_, _, hostport, guestport|
    rdpport = hostport if guestport == 3389
  end

  Tempfile.open('vagrant-rdp-shell-') do |tf|
    rdp_file = rdp_file(vm, rdpport)

    tf.puts <<EOS
open -a "/Applications/Microsoft Remote Desktop.app/Contents/MacOS/Microsoft Remote Desktop" "#{rdp_file}"
sleep 5 #HACK
rm "#{rdp_file}"
EOS
    tf.close

    # Spawn remote desktop and detach it so we can move on.
    pid = spawn("/bin/bash", tf.path)
    Process.detach(pid)
  end
end

#rdp_file(vm, rdpport) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vagrant-rdp/command.rb', line 47

def rdp_file(vm, rdpport)
  path = nil

  Tempfile.open([ "vagrant-rdp-", ".rdp" ], vm.data_dir) { |fp|
    path = fp.path
    fp.unlink
  }

  File.open(path, "w") { |io|
    io.puts <<EOF
screen mode id:i:0
desktopwidth:i:#{vm.config.rdp.width}
desktopheight:i:#{vm.config.rdp.height}
use multimon:i:1
session bpp:i:32
full address:s:localhost:#{rdpport}
audiomode:i:0
disable wallpaper:i:0
disable full window drag:i:0
disable menu anims:i:0
disable themes:i:0
alternate shell:s:
shell working directory:s:
authentication level:i:2
connect to console:i:0
gatewayusagemethod:i:0
disable cursor setting:i:0
allow font smoothing:i:1
allow desktop composition:i:1
bookmarktype:i:3
use redirection server name:i:0
EOF
  }

  path
end