vaguerent/plugins/guests/windows/cap/change_host_name.rb
Shawn Neal d4bd05883d Fixed issue 3987
Reboot the Windows guest after renaming the computer so changes take affect immediately before attempting to provision the box.

- Changed rename from wmic to netdom since netdom seems to work correctly in Windows 2008R2 and newer OSs.
- Fixed Windows guest error translations, the wrong namespace was specified in the yaml file.
2014-06-09 22:46:03 -07:00

28 lines
920 B
Ruby

module VagrantPlugins
module GuestWindows
module Cap
module ChangeHostName
def self.change_host_name(machine, name)
change_host_name_and_wait(machine, name, machine.config.vm.graceful_halt_timeout)
end
def self.change_host_name_and_wait(machine, name, sleep_timeout)
# If the configured name matches the current name, then bail
return if machine.communicate.test("if ($env:ComputerName -eq '#{name}') { exit 0 } exit 1")
# Rename and then reboot in one step
exit_code = machine.communicate.execute(
"netdom renamecomputer \"$Env:COMPUTERNAME\" /NewName:#{name} /Force /Reboot:0",
error_check: false)
raise Errors::RenameComputerFailed if exit_code != 0
# Don't continue until the machine has shutdown and rebooted
sleep(sleep_timeout)
end
end
end
end
end