Class: VagrantPlugins::VagrantWinRM::WinRMConfig

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::SafePuts
Defined in:
lib/vagrant-winrm/commands/winrm_config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



10
11
12
# File 'lib/vagrant-winrm/commands/winrm_config.rb', line 10

def self.synopsis
  'outputs winrm configuration to connect to the machine like ssh-config'
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant-winrm/commands/winrm_config.rb', line 14

def execute
  options = {}

  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant winrm-config [options] [name]'
    o.separator 'Options:'

    o.on('--host NAME', 'Name the host for the config') do |h|
      options[:host] = h
    end
  end

  # Parse the options and return if we don't have any target.
  argv = parse_options(opts)
  return unless argv

  with_target_vms(argv) do |machine|

    variables = {
      host_key: options[:host] || machine.name || 'vagrant',
      winrm_host: VagrantPlugins::CommunicatorWinRM::Helper.winrm_info(machine)[:host],
      winrm_port: VagrantPlugins::CommunicatorWinRM::Helper.winrm_info(machine)[:port],
      winrm_user: machine.config.winrm.username,
      winrm_password: machine.config.winrm.password,
      rdp_port: machine.config.rdp.port
    }

    # Render the template and output directly to STDOUT
    template = "#{VagrantPlugins::VagrantWinRM.source_root}/templates/winrm_config/config"
    safe_puts(Vagrant::Util::TemplateRenderer.render(template, variables))
    safe_puts
  end

  # Success, exit status 0
  0
end