diff --git a/plugins/guests/windows/cap/choose_addressable_ip_addr.rb b/plugins/guests/windows/cap/choose_addressable_ip_addr.rb new file mode 100644 index 000000000..0403fc86c --- /dev/null +++ b/plugins/guests/windows/cap/choose_addressable_ip_addr.rb @@ -0,0 +1,17 @@ +module VagrantPlugins + module GuestWindows + module Cap + module ChooseAddressableIPAddr + def self.choose_addressable_ip_addr(machine, possible) + machine.communicate.tap do |comm| + possible.each do |ip| + return ip + end + end + + nil + end + end + end + end +end diff --git a/plugins/guests/windows/cap/mount_shared_folder.rb b/plugins/guests/windows/cap/mount_shared_folder.rb index 8f7866a1a..4329025f6 100644 --- a/plugins/guests/windows/cap/mount_shared_folder.rb +++ b/plugins/guests/windows/cap/mount_shared_folder.rb @@ -16,6 +16,11 @@ module VagrantPlugins mount_shared_folder(machine, name, guestpath, "\\\\psf\\") end + def self.mount_smb_shared_folder(machine, name, guestpath, options) + machine.communicate.execute("cmdkey /add:#{options[:smb_host]} /user:#{options[:smb_username]} /pass:#{options[:smb_password]}", {shell: :powershell, elevated: true}) + mount_shared_folder(machine, name, guestpath, "\\\\#{options[:smb_host]}\\") + end + protected def self.mount_shared_folder(machine, name, guestpath, vm_provider_unc_base) diff --git a/plugins/guests/windows/plugin.rb b/plugins/guests/windows/plugin.rb index fa1408314..fd70ae4a6 100644 --- a/plugins/guests/windows/plugin.rb +++ b/plugins/guests/windows/plugin.rb @@ -54,6 +54,16 @@ module VagrantPlugins Cap::Reboot end + guest_capability(:windows, :choose_addressable_ip_addr) do + require_relative "cap/choose_addressable_ip_addr" + Cap::ChooseAddressableIPAddr + end + + guest_capability(:windows, :mount_smb_shared_folder) do + require_relative "cap/mount_shared_folder" + Cap::MountSharedFolder + end + protected def self.init! diff --git a/plugins/synced_folders/smb/synced_folder.rb b/plugins/synced_folders/smb/synced_folder.rb index 2080efefc..8e700a183 100644 --- a/plugins/synced_folders/smb/synced_folder.rb +++ b/plugins/synced_folders/smb/synced_folder.rb @@ -150,29 +150,6 @@ module VagrantPlugins JSON.parse(r.stdout)["ip_addresses"] end - -=begin - def mount_shared_folders_to_windows - result = @env[:machine].provider.driver.execute('host_info.ps1', {}) - @smb_shared_folders.each do |id, data| - begin - options = { share_name: data[:share_name], - guest_path: data[:guestpath].gsub("/", "\\"), - guest_ip: ssh_info[:host], - username: ssh_info[:username], - host_ip: result["host_ip"], - password: @env[:machine].provider_config.guest.password, - host_share_username: @env[:machine].provider_config.host_share.username, - host_share_password: @env[:machine].provider_config.host_share.password} - @env[:ui].info("Linking #{data[:share_name]} to Guest at #{data[:guestpath]} ...") - @env[:machine].provider.driver.execute('mount_share.ps1', options) - rescue Error::SubprocessError => e - @env[:ui].info "Failed to link #{data[:share_name]} to Guest" - @env[:ui].info e.message - end - end - end -=end end end end diff --git a/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb b/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb index 93fe41799..bd443142b 100644 --- a/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb +++ b/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb @@ -79,4 +79,23 @@ describe "VagrantPlugins::GuestWindows::Cap::MountSharedFolder" do end end + describe "smb" do + + let(:described_class) do + VagrantPlugins::GuestWindows::Plugin.components.guest_capabilities[:windows].get(:mount_smb_shared_folder) + end + + describe ".mount_shared_folder" do + it "should call mount_volume script with correct args" do + expect(Vagrant::Util::TemplateRenderer).to receive(:render).with( + /.+scripts\/mount_volume.ps1/, options: { + mount_point: "guestpath", + share_name: "name", + vm_provider_unc_path: "\\\\host\\name", + }) + described_class.mount_smb_shared_folder(machine, 'name', 'guestpath', {:smb_username => "user", :smb_password => "pass", :smb_host => "host"}) + end + end + end + end