adding smb sync folder implementation for windows guests addressing #3699

This commit is contained in:
Matt Wrock 2014-07-17 03:13:50 -07:00
parent b675be383b
commit e64f84491e
5 changed files with 51 additions and 23 deletions

View File

@ -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

View File

@ -16,6 +16,11 @@ module VagrantPlugins
mount_shared_folder(machine, name, guestpath, "\\\\psf\\") mount_shared_folder(machine, name, guestpath, "\\\\psf\\")
end 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 protected
def self.mount_shared_folder(machine, name, guestpath, vm_provider_unc_base) def self.mount_shared_folder(machine, name, guestpath, vm_provider_unc_base)

View File

@ -54,6 +54,16 @@ module VagrantPlugins
Cap::Reboot Cap::Reboot
end 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 protected
def self.init! def self.init!

View File

@ -150,29 +150,6 @@ module VagrantPlugins
JSON.parse(r.stdout)["ip_addresses"] JSON.parse(r.stdout)["ip_addresses"]
end 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 end
end end

View File

@ -79,4 +79,23 @@ describe "VagrantPlugins::GuestWindows::Cap::MountSharedFolder" do
end end
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 end