Class: VagrantPlugins::SyncedFolderSMB::SyncedFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-windows-hyperv/monkey_patch/plugins/synced_folders/smb/synced_folders.rb

Instance Method Summary collapse

Instance Method Details

#enable(machine, folders, nfsopts) ⇒ Object

FIXME: This is a workaround to enable the guest VM to access the SMB share set in the host.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-windows-hyperv/monkey_patch/plugins/synced_folders/smb/synced_folders.rb', line 17

def enable(machine, folders, nfsopts)
  response = machine.provider.driver.get_host_ip
  host_ip = response["host_ip"]
  if machine.config.vm.guest == :windows
    folders.each do |id, data|
      machine.ui.output "#{data[:hostpath]} ==>"
      machine.ui.output "\\\\#{host_ip}\\#{data[:smb_id]}"
    end
  guest_startup_script(machine, folders, host_ip)
  else
    original_enable(machine, folders, nfsopts)
  end
end

#guest_startup_script(machine, folders, host_ip) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vagrant-windows-hyperv/monkey_patch/plugins/synced_folders/smb/synced_folders.rb', line 31

def guest_startup_script(machine, folders, host_ip)
  # Upload a startup script to VM,

  # This script will authenticate the Network share with the host, and

  # the guest can access the share path from a RDP session

  file = Tempfile.new(['vagrant-smb-auth', '.ps1'])
  begin
    folders.each do |id, data|
      smb_map_command = "New-SmbMapping"
      smb_map_command += " -RemotePath \\\\#{host_ip}\\#{data[:smb_id]}"
      smb_map_command += " -UserName #{@creds[:username]}"
      smb_map_command += " -Password #{@creds[:password]}"
      file.puts(smb_map_command)
    end
    file.fsync
    file.close
  ensure
    file.close
  end
  machine.provider.driver.upload(file.path.to_s, "c:\\tmp\\vagrant-smb-auth.ps1")
  # Invoke Remote Schedule task command in VM

  command = 'schtasks /create /sc ONLOGON /tn vagrant-smb-auth /tr \"powershell c:\tmp\vagrant-smb-auth.ps1\"'
  machine.provider.driver.run_remote_ps(command)
end

#original_enableObject



12
# File 'lib/vagrant-windows-hyperv/monkey_patch/plugins/synced_folders/smb/synced_folders.rb', line 12

alias_method :original_enable, :enable