Class: Vagrant::Systems::Linux
- Inherits:
-
Base
- Object
- Base
- Vagrant::Systems::Linux
show all
- Defined in:
- lib/vagrant/systems/linux.rb,
lib/vagrant/systems/linux/error.rb,
lib/vagrant/systems/linux/config.rb
Defined Under Namespace
Classes: LinuxConfig, LinuxError
Instance Attribute Summary
Attributes inherited from Base
#vm
Instance Method Summary
collapse
-
#distro_dispatch ⇒ Object
-
#halt ⇒ Object
-
#mount_folder(ssh, name, guestpath, owner, group, sleeptime = 5) ⇒ Object
------------------------------------------------------------------- "Private" methods which assist above methods -------------------------------------------------------------------.
-
#mount_nfs(ip, folders) ⇒ Object
-
#mount_shared_folder(ssh, name, guestpath, owner, group) ⇒ Object
Methods inherited from Base
#change_host_name, #enable_host_only_network, #initialize, #prepare_host_only_network
Instance Method Details
#distro_dispatch ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/vagrant/systems/linux.rb', line 7
def distro_dispatch
vm.ssh.execute do |ssh|
if ssh.test?("cat /etc/debian_version")
return :debian if ssh.test?("cat /proc/version | grep 'Debian'")
return :ubuntu if ssh.test?("cat /proc/version | grep 'Ubuntu'")
end
return :gentoo if ssh.test?("cat /etc/gentoo-release")
return :redhat if ssh.test?("cat /etc/redhat-release")
return :suse if ssh.test?("cat /etc/SuSE-release")
return :arch if ssh.test?("cat /etc/arch-release")
end
nil
end
|
#halt ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/vagrant/systems/linux.rb', line 24
def halt
vm.env.ui.info I18n.t("vagrant.systems.linux.attempting_halt")
vm.ssh.execute do |ssh|
ssh.exec!("sudo halt")
end
count = 0
while vm.vm.state != :powered_off
count += 1
return if count >= vm.env.config.linux.halt_timeout
sleep vm.env.config.linux.halt_check_interval
end
end
|
#mount_folder(ssh, name, guestpath, owner, group, sleeptime = 5) ⇒ Object
"Private" methods which assist above methods
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/vagrant/systems/linux.rb', line 62
def mount_folder(ssh, name, guestpath, owner, group, sleeptime=5)
options = "-o uid=`id -u #{owner}`,gid=`id -g #{group}`"
attempts = 0
while true
result = ssh.exec!("sudo mount -t vboxsf #{options} #{name} #{guestpath}") do |ch, type, data|
ch[:result] = !!(type == :stderr && data =~ /No such device/i)
end
break unless result
attempts += 1
raise LinuxError, :mount_fail if attempts >= 10
sleep sleeptime
end
end
|
#mount_nfs(ip, folders) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/vagrant/systems/linux.rb', line 48
def mount_nfs(ip, folders)
folders.each do |name, opts|
vm.ssh.execute do |ssh|
ssh.exec!("sudo mkdir -p #{opts[:guestpath]}")
ssh.exec!("sudo mount #{ip}:'#{opts[:hostpath]}' #{opts[:guestpath]}", :_error_class => LinuxError, :_key => :mount_nfs_fail)
end
end
end
|
#mount_shared_folder(ssh, name, guestpath, owner, group) ⇒ Object
42
43
44
45
46
|
# File 'lib/vagrant/systems/linux.rb', line 42
def mount_shared_folder(ssh, name, guestpath, owner, group)
ssh.exec!("sudo mkdir -p #{guestpath}")
mount_folder(ssh, name, guestpath, owner, group)
ssh.exec!("sudo chown `id -u #{owner}`:`id -g #{group}` #{guestpath}")
end
|