Merge pull request #4209 from mwrock/smb_sync
adding smb sync folder implementation for windows guests addressing #3699
This commit is contained in:
commit
220e4f23b2
|
@ -0,0 +1,20 @@
|
|||
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|
|
||||
command = "ping -n 1 -w 1 #{ip}"
|
||||
if comm.test(command)
|
||||
return ip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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)
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue