Class: VagrantWindows::Guest::Windows
- Inherits:
-
Object
- Object
- VagrantWindows::Guest::Windows
- Defined in:
- lib/vagrant-windows/guest/windows.rb
Overview
A general Vagrant system implementation for “windows”.
Contributed by Chris McClimans <[email protected]>
Instance Attribute Summary collapse
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
Instance Method Summary collapse
- #change_host_name(name) ⇒ Object
- #configure_networks(networks) ⇒ Object
-
#distro_dispatch ⇒ Object
TODO: I am sure that ciphering windows versions will be important at some point.
- #halt ⇒ Object
-
#initialize(machine) ⇒ Windows
constructor
A new instance of Windows.
- #mount_nfs(ip, folders) ⇒ Object
- #mount_shared_folder(name, guestpath, options) ⇒ Object
Constructor Details
#initialize(machine) ⇒ Windows
Returns a new instance of Windows.
10 11 12 13 14 |
# File 'lib/vagrant-windows/guest/windows.rb', line 10 def initialize(machine) super(machine) @machine = machine @logger = Log4r::Logger.new("vagrant_windows::guest::windows") end |
Instance Attribute Details
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
8 9 10 |
# File 'lib/vagrant-windows/guest/windows.rb', line 8 def machine @machine end |
Instance Method Details
#change_host_name(name) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/vagrant-windows/guest/windows.rb', line 16 def change_host_name(name) @logger.info("change host name to: #{name}") #### on windows, renaming a computer seems to require a reboot @machine.communicate.execute( "wmic computersystem where name=\"%COMPUTERNAME%\" call rename name=\"#{name}\"", :shell => :cmd) end |
#configure_networks(networks) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vagrant-windows/guest/windows.rb', line 68 def configure_networks(networks) @logger.info("configure_networks: #{networks.inspect}") driver_mac_address = @machine.provider.driver.read_mac_addresses.invert vm_interface_map = {} # NetConnectionStatus=2 -- connected wql = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus=2" @machine.communicate.session.wql(wql)[:win32_network_adapter].each do |nic| naked_mac = nic[:mac_address].gsub(':','') if driver_mac_address[naked_mac] vm_interface_map[driver_mac_address[naked_mac]] = { :name => nic[:net_connection_id], :mac_address => naked_mac, :index => nic[:interface_index] } end end networks.each do |network| netsh = "netsh interface ip set address \"#{vm_interface_map[network[:interface]+1][:name]}\" " if network[:type].to_sym == :static netsh = "#{netsh} static #{network[:ip]} #{network[:netmask]}" elsif network[:type].to_sym == :dhcp netsh = "#{netsh} dhcp" else raise WindowsError, "#{network[:type]} network type is not supported, try static or dhcp" end @machine.communicate.execute(netsh) end #netsh interface ip set address name="Local Area Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1 end |
#distro_dispatch ⇒ Object
TODO: I am sure that ciphering windows versions will be important at some point
25 26 27 28 |
# File 'lib/vagrant-windows/guest/windows.rb', line 25 def distro_dispatch @logger.info("distro_dispatch: windows") :windows end |
#halt ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vagrant-windows/guest/windows.rb', line 30 def halt @machine.communicate.execute("shutdown /s /t 1 /c \"Vagrant Halt\" /f /d p:4:1") # Wait until the VM's state is actually powered off. If this doesn't # occur within a reasonable amount of time (15 seconds by default), # then simply return and allow Vagrant to kill the machine. count = 0 while @machine.state != :poweroff count += 1 return if count >= @machine.config.windows.halt_timeout sleep @machine.config.windows.halt_check_interval end end |
#mount_nfs(ip, folders) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vagrant-windows/guest/windows.rb', line 52 def mount_nfs(ip, folders) raise NotImplementedError, "Mounting NFS Shares on windows is not implemented" # TODO: Maybe check for nfs support on the guest, since its often # not installed by default #folders.each do |name, opts| # # Expand the guestpath, so we can handle things like "~/vagrant" # real_guestpath = expanded_guest_path(opts[:guestpath]) # Do the actual creating and mounting # @machine.communicate.sudo("mkdir -p #{real_guestpath}") # @machine.communicate.sudo("mount -o vers=#{opts[:nfs_version]} #{ip}:'#{opts[:hostpath]}' #{real_guestpath}", # :error_class => LinuxError, # :error_key => :mount_nfs_fail) #end end |
#mount_shared_folder(name, guestpath, options) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/vagrant-windows/guest/windows.rb', line 45 def mount_shared_folder(name, guestpath, ) @logger.info("mount_shared_folder: #{name}") mount_script = VagrantWindows.load_script_template("mount_volume.ps1", :options => {:mount_point => guestpath, :name => name}) @machine.communicate.execute(mount_script, {:shell => :powershell}) end |