Class: VagrantPlugins::WinAzure::Action::Rdp

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Rdp

Returns a new instance of Rdp.



15
16
17
18
19
# File 'lib/vagrant-azure/action/rdp.rb', line 15

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_azure::action::rdp')
  @rdp_file = 'machine.rdp'
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant-azure/action/rdp.rb', line 21

def call(env)
  if Vagrant::Util::Platform.windows?
    generate_rdp_file env[:machine]
    command = ['mstsc', @rdp_file]
    Vagrant::Util::Subprocess.execute(*command)
  elsif Vagrant::Util::Platform.darwin?
    generate_rdp_file env[:machine]
    command = ['open', @rdp_file]
    result = Vagrant::Util::Subprocess.execute(*command)

    if result.exit_code == 1
      raise result.stderr
    end
  else
    # TODO: Add support for RDP on *Nix systems
    raise 'Unsupported operating system for RDP operation.'
  end

  @app.call(env)
end

#generate_rdp_file(machine) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vagrant-azure/action/rdp.rb', line 42

def generate_rdp_file(machine)
  File.delete(@rdp_file) if File.exists?(@rdp_file)

  info = machine.provider.rdp_info

  rdp_options = {
    'drivestoredirect:s' => '*',
    'username:s' => machine.provider_config.vm_user,
    'prompt for credentials:i' => '1',
    'full address:s' => "#{info[:host]}:#{info[:port]}"
  }

  file = File.open(@rdp_file, 'w')
  rdp_options.each do |key, value|
    file.puts "#{key}:#{value}"
  end
  file.close
end