Class: VMCMicro::Switcher::Windows

Inherits:
Base
  • Object
show all
Defined in:
lib/mcf-vmc-plugin/micro/switcher/windows.rb

Instance Method Summary collapse

Methods inherited from Base

#domain, #initialize, #ip, #nat?, #offline!, #offline?, #online!, #ready?, #reset_to_nat!, #running?, #set_host_dns!, #start!, #unset_host_dns!, #vmx

Constructor Details

This class inherits a constructor from VMCMicro::Switcher::Base

Instance Method Details

#adminrun(command, args = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mcf-vmc-plugin/micro/switcher/windows.rb', line 8

def adminrun(command, args=nil)
  if version > 5.2
    require 'win32ole'
    shell = WIN32OLE.new("Shell.Application")
    shell.ShellExecute(command, args, nil, "runas", 0)
  else
    # on older version this will try to run the command, and if you don't have
    # admin privilges it will tell you so and exit
    VMCMicro.run_command(command, args)
  end
end

#set_nameserver(domain, ip) ⇒ Object

TODO better method to figure out the interface name is to get the NAT ip and find the interface with the correct subnet



22
23
24
# File 'lib/mcf-vmc-plugin/micro/switcher/windows.rb', line 22

def set_nameserver(domain, ip)
  adminrun("netsh", "interface ip set dns \"VMware Network Adapter VMnet8\" static #{ip}")
end

#unset_nameserver(domain, ip) ⇒ Object



26
27
28
# File 'lib/mcf-vmc-plugin/micro/switcher/windows.rb', line 26

def unset_nameserver(domain, ip)
  adminrun("netsh", "interface ip set dns \"VMware Network Adapter VMnet8\" static none")
end

#versionObject



4
5
6
# File 'lib/mcf-vmc-plugin/micro/switcher/windows.rb', line 4

def version
  VMCMicro.run_command("cmd", "/c ver").to_s.scan(/\d+\.\d+/).first.to_f
end