lib/vagrant-windows/guest/windows.rb in vagrant-windows-1.0.3 vs lib/vagrant-windows/guest/windows.rb in vagrant-windows-1.2.0

- old
+ new

@@ -1,102 +1,71 @@ +require "vagrant" +require "vagrant-windows/guest/cap/change_host_name" +require "vagrant-windows/guest/cap/configure_networks" +require "vagrant-windows/guest/cap/halt" +require "vagrant-windows/guest/cap/mount_virtualbox_shared_folder" +require "vagrant-windows/guest/cap/mount_vmware_shared_folder" + module VagrantWindows module Guest - # A general Vagrant system implementation for "windows". - # - # Contributed by Chris McClimans <chris@hippiehacker.org> class Windows < Vagrant.plugin("2", :guest) + # Vagrant 1.1.x compatibibility methods + # Implement the 1.1.x methods and call through to the new 1.2.x capabilities + attr_reader :machine - def initialize(machine) - super(machine) + def initialize(machine = nil) + super(machine) unless machine == nil @machine = machine - @logger = Log4r::Logger.new("vagrant_windows::guest::windows") end - + 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) + VagrantWindows::Guest::Cap::ChangeHostName.change_host_name(@machine, name) end - - # TODO: I am sure that ciphering windows versions will be important at some point + def distro_dispatch - @logger.info("distro_dispatch: windows") :windows end - + 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 + VagrantWindows::Guest::Cap::Halt.halt(@machine) end - - def mount_shared_folder(name, guestpath, options) - @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}) + + def mount_virtualbox_shared_folder(name, guestpath, options) + VagrantWindows::Guest::Cap::MountVirtualBoxSharedFolder.mount_virtualbox_shared_folder( + @machine, name, guestpath, options) end - 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 + def mount_vmware_shared_folder(name, guestpath, options) + VagrantWindows::Guest::Cap::MountVMwareBoxSharedFolder.mount_vmware_shared_folder( + @machine, name, guestpath, options) end - + 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 + VagrantWindows::Guest::Cap::ConfigureNetworks.configure_networks(@machine, networks) + end + + + # Vagrant 1.2.x compatibibility methods + + def detect?(machine) - 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 + # uname -o | grep Solaris + # uname -s | grep 'Linux' + # uname -s | grep 'FreeBSD' + # cat /etc/redhat-release + # uname -s | grep 'OpenBSD' + # cat /etc/gentoo-release + # cat /proc/version | grep 'Debian' + # cat /etc/arch-release + # cat /proc/version | grep 'Ubuntu' + # cat /etc/SuSE-release + # cat /etc/pld-release + # grep 'Fedora release 1[678]' /etc/redhat-release + # see if the Windows directory is present + machine.communicate.test("test -d $Env:SystemRoot") end - end end end