Class: VagrantPlugins::RDP::Command
- Inherits:
-
Object
- Object
- VagrantPlugins::RDP::Command
- Defined in:
- lib/vagrant-rdp/command.rb
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
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. = "Usage: vagrant rdp [vm-name...]" opts.separator "" end argv = (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 "open -a \"/Applications/Microsoft Remote Desktop.app/Contents/MacOS/Microsoft Remote Desktop\" \"\#{rdp_file}\"\nsleep 5 #HACK\nrm \"\#{rdp_file}\"\n" 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 "screen mode id:i:0\ndesktopwidth:i:\#{vm.config.rdp.width}\ndesktopheight:i:\#{vm.config.rdp.height}\nuse multimon:i:1\nsession bpp:i:32\nfull address:s:localhost:\#{rdpport}\naudiomode:i:0\ndisable wallpaper:i:0\ndisable full window drag:i:0\ndisable menu anims:i:0\ndisable themes:i:0\nalternate shell:s:\nshell working directory:s:\nauthentication level:i:2\nconnect to console:i:0\ngatewayusagemethod:i:0\ndisable cursor setting:i:0\nallow font smoothing:i:1\nallow desktop composition:i:1\nbookmarktype:i:3\nuse redirection server name:i:0\n" } path end |