Class: Vagrant::Actions::VM::SharedFolders
- Inherits:
-
Base
- Object
- Base
- Vagrant::Actions::VM::SharedFolders
show all
- Defined in:
- lib/vagrant/actions/vm/shared_folders.rb
Instance Attribute Summary
Attributes inherited from Base
#runner
Instance Method Summary
collapse
Methods inherited from Base
#cleanup, #execute!, #follows, #initialize, #precedes, #prepare, #rescue
Methods included from Util
#error_and_exit, included, #logger, #wrap_output
Instance Method Details
#after_boot ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/vagrant/actions/vm/shared_folders.rb', line 17
def after_boot
logger.info "Mounting shared folders..."
@runner.env.ssh.execute do |ssh|
shared_folders.each do |name, hostpath, guestpath|
logger.info "-- #{name}: #{guestpath}"
ssh.exec!("sudo mkdir -p #{guestpath}")
mount_folder(ssh, name, guestpath)
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{guestpath}")
end
end
end
|
#before_boot ⇒ Object
12
13
14
15
|
# File 'lib/vagrant/actions/vm/shared_folders.rb', line 12
def before_boot
clear_shared_folders
create_metadata
end
|
#clear_shared_folders ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/vagrant/actions/vm/shared_folders.rb', line 30
def clear_shared_folders
logger.info "Clearing previously set shared folders..."
@runner.vm.shared_folders.each do |shared_folder|
shared_folder.destroy
end
@runner.reload!
end
|
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/vagrant/actions/vm/shared_folders.rb', line 40
def create_metadata
logger.info "Creating shared folders metadata..."
shared_folders.each do |name, hostpath, guestpath|
folder = VirtualBox::SharedFolder.new
folder.name = name
folder.hostpath = hostpath
@runner.vm.shared_folders << folder
end
@runner.vm.save(true)
end
|
#mount_folder(ssh, name, guestpath, sleeptime = 5) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/vagrant/actions/vm/shared_folders.rb', line 53
def mount_folder(ssh, name, guestpath, sleeptime=5)
perms = []
perms << "uid=#{@runner.env.config.vm.shared_folder_uid}"
perms << "gid=#{@runner.env.config.vm.shared_folder_gid}"
perms = " -o #{perms.join(",")}" if !perms.empty?
attempts = 0
while true
result = ssh.exec!("sudo mount -t vboxsf#{perms} #{name} #{guestpath}") do |ch, type, data|
ch[:result] = !!(type == :stderr && data =~ /No such device/i)
end
break unless result
attempts += 1
raise ActionException.new(:vm_mount_fail) if attempts >= 10
sleep sleeptime
end
end
|
#shared_folders ⇒ Object
5
6
7
8
9
10
|
# File 'lib/vagrant/actions/vm/shared_folders.rb', line 5
def shared_folders
@runner.env.config.vm.shared_folders.inject([]) do |acc, data|
name, value = data
acc << [name, File.expand_path(value[:hostpath]), value[:guestpath]]
end
end
|