Class: VagrantWindows::WindowsMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-windows/windows_machine.rb

Overview

Provides a wrapper around the Vagrant machine object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ WindowsMachine

Returns a new instance of WindowsMachine.

Parameters:

  • The (Machine)

    Vagrant machine object



17
18
19
20
# File 'lib/vagrant-windows/windows_machine.rb', line 17

def initialize(machine)
  @machine = machine
  @logger = Log4r::Logger.new("vagrant_windows::windows_machine")
end

Instance Attribute Details

#machineObject (readonly)

Returns the value of attribute machine.



6
7
8
# File 'lib/vagrant-windows/windows_machine.rb', line 6

def machine
  @machine
end

Class Method Details

.is_windows?(machine) ⇒ Boolean

Returns true if the specifed Vagrant machine is a Windows guest, otherwise false.

Parameters:

  • The (Machine)

    Vagrant machine object

Returns:

  • (Boolean)


12
13
14
# File 'lib/vagrant-windows/windows_machine.rb', line 12

def self.is_windows?(machine)
  machine.config.vm.guest.eql? :windows
end

Instance Method Details

#is_parallels?Boolean

Checks to see if the machine is using Parallels Desktop.

Returns:

  • (Boolean)


39
40
41
# File 'lib/vagrant-windows/windows_machine.rb', line 39

def is_parallels?()
  @machine.provider_name.to_s().start_with?('parallels')
end

#is_rebooting?Boolean

Checks to see if the machine is rebooting or has a scheduled reboot.

Returns:

  • (Boolean)

    True if rebooting



53
54
55
56
# File 'lib/vagrant-windows/windows_machine.rb', line 53

def is_rebooting?()
  reboot_detect_script = VagrantWindows.load_script('reboot_detect.ps1')
  @machine.communicate.execute(reboot_detect_script, :error_check => false) != 0
end

#is_virtualbox?Boolean

Checks to see if the machine is using Oracle VirtualBox.

Returns:

  • (Boolean)


46
47
48
# File 'lib/vagrant-windows/windows_machine.rb', line 46

def is_virtualbox?()
  @machine.provider_name.to_s().start_with?('virtualbox')
end

#is_vmware?Boolean

Checks to see if the machine is using VMWare Fusion or Workstation.

Returns:

  • (Boolean)


32
33
34
# File 'lib/vagrant-windows/windows_machine.rb', line 32

def is_vmware?()
  @machine.provider_name.to_s().start_with?('vmware')
end

#is_windows?Boolean

Returns true if this Vagrant machine is a Windows guest, otherwise false.

Returns:

  • (Boolean)


25
26
27
# File 'lib/vagrant-windows/windows_machine.rb', line 25

def is_windows?()
  WindowsMachine.is_windows?(@machine)
end

#read_forwarded_portsArray<Array>

Returns a list of forwarded ports for a VM. NOTE: Only the VBox provider currently supports this method

Returns:

  • (Array<Array>)


83
84
85
86
87
88
89
# File 'lib/vagrant-windows/windows_machine.rb', line 83

def read_forwarded_ports()
  if is_virtualbox?()
    @machine.provider.driver.read_forwarded_ports
  else
    []
  end
end

#read_mac_addressesHash

Reads the machine’s MAC addresses keyed by interface index. 2=>“08002757E68A”

Returns:

  • (Hash)


75
76
77
# File 'lib/vagrant-windows/windows_machine.rb', line 75

def read_mac_addresses()
  @machine.provider.driver.read_mac_addresses
end

#reinitialize_network_sharesObject

Re-establishes our symbolic links if they were created between now and a reboot Fixes issue #119



67
68
69
# File 'lib/vagrant-windows/windows_machine.rb', line 67

def reinitialize_network_shares()
  winrmshell.powershell('& net use a-non-existant-share')
end

#ssh_infoHash

Returns the SSH config for this machine.

Returns:

  • (Hash)


94
95
96
# File 'lib/vagrant-windows/windows_machine.rb', line 94

def ssh_info()
  @machine.ssh_info
end

#windows_configObject



98
99
100
# File 'lib/vagrant-windows/windows_machine.rb', line 98

def windows_config()
  @machine.config.windows
end

#winrm_configObject



102
103
104
# File 'lib/vagrant-windows/windows_machine.rb', line 102

def winrm_config()
  @machine.config.winrm
end

#winrmshellWinRMShell

Returns the active WinRMShell for the guest.

Returns:

  • (WinRMShell)


61
62
63
# File 'lib/vagrant-windows/windows_machine.rb', line 61

def winrmshell()
  @machine.communicate.winrmshell
end