Merge pull request #5750 from alh84001/feature/capability_guest_darwin_mount_smb
Capability to mount smb shares in darwin guests
This commit is contained in:
commit
6210f13338
|
@ -316,6 +316,10 @@ module Vagrant
|
||||||
error_key(:corrupt_machine_index)
|
error_key(:corrupt_machine_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class DarwinMountFailed < VagrantError
|
||||||
|
error_key(:darwin_mount_failed)
|
||||||
|
end
|
||||||
|
|
||||||
class DarwinNFSMountFailed < VagrantError
|
class DarwinNFSMountFailed < VagrantError
|
||||||
error_key(:darwin_nfs_mount_failed)
|
error_key(:darwin_nfs_mount_failed)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module GuestDarwin
|
||||||
|
module Cap
|
||||||
|
module ChooseAddressableIPAddr
|
||||||
|
def self.choose_addressable_ip_addr(machine, possible)
|
||||||
|
machine.communicate.tap do |comm|
|
||||||
|
possible.each do |ip|
|
||||||
|
command = "ping -c1 -t1 #{ip}"
|
||||||
|
if comm.test(command)
|
||||||
|
return ip
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
require "vagrant/util/retryable"
|
||||||
|
require "shellwords"
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module GuestDarwin
|
||||||
|
module Cap
|
||||||
|
class MountSMBSharedFolder
|
||||||
|
extend Vagrant::Util::Retryable
|
||||||
|
def self.mount_smb_shared_folder(machine, name, guestpath, options)
|
||||||
|
expanded_guest_path = machine.guest.capability(:shell_expand_guest_path, guestpath)
|
||||||
|
|
||||||
|
mount_point_owner = options[:owner];
|
||||||
|
if mount_point_owner
|
||||||
|
machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
|
||||||
|
machine.communicate.sudo("chown #{mount_point_owner} #{expanded_guest_path}")
|
||||||
|
else
|
||||||
|
# fallback to assumption that user has permission
|
||||||
|
# to create the specified mountpoint
|
||||||
|
machine.communicate.execute("mkdir -p #{expanded_guest_path}")
|
||||||
|
end
|
||||||
|
|
||||||
|
smb_password = Shellwords.shellescape(options[:smb_password])
|
||||||
|
mount_options = options[:mount_options];
|
||||||
|
mount_command = "mount -t smbfs " +
|
||||||
|
(mount_options ? "-o '#{mount_options.join(",")}' " : "") +
|
||||||
|
"'//#{options[:smb_username]}:#{smb_password}@#{options[:smb_host]}/#{name}' " +
|
||||||
|
"#{expanded_guest_path}"
|
||||||
|
retryable(on: Vagrant::Errors::DarwinMountFailed, tries: 10, sleep: 2) do
|
||||||
|
machine.communicate.execute(
|
||||||
|
mount_command,
|
||||||
|
error_class: Vagrant::Errors::DarwinMountFailed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,6 +16,11 @@ module VagrantPlugins
|
||||||
Cap::ChangeHostName
|
Cap::ChangeHostName
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guest_capability("darwin", "choose_addressable_ip_addr") do
|
||||||
|
require_relative "cap/choose_addressable_ip_addr"
|
||||||
|
Cap::ChooseAddressableIPAddr
|
||||||
|
end
|
||||||
|
|
||||||
guest_capability("darwin", "configure_networks") do
|
guest_capability("darwin", "configure_networks") do
|
||||||
require_relative "cap/configure_networks"
|
require_relative "cap/configure_networks"
|
||||||
Cap::ConfigureNetworks
|
Cap::ConfigureNetworks
|
||||||
|
@ -36,6 +41,11 @@ module VagrantPlugins
|
||||||
Cap::MountNFSFolder
|
Cap::MountNFSFolder
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guest_capability("darwin", "mount_smb_shared_folder") do
|
||||||
|
require_relative "cap/mount_smb_shared_folder"
|
||||||
|
Cap::MountSMBSharedFolder
|
||||||
|
end
|
||||||
|
|
||||||
guest_capability("darwin", "mount_vmware_shared_folder") do
|
guest_capability("darwin", "mount_vmware_shared_folder") do
|
||||||
require_relative "cap/mount_vmware_shared_folder"
|
require_relative "cap/mount_vmware_shared_folder"
|
||||||
Cap::MountVmwareSharedFolder
|
Cap::MountVmwareSharedFolder
|
||||||
|
|
Loading…
Reference in New Issue