diff --git a/lib/vagrant/action/vm/boot.rb b/lib/vagrant/action/vm/boot.rb index 4dab62a1d..349934a8d 100644 --- a/lib/vagrant/action/vm/boot.rb +++ b/lib/vagrant/action/vm/boot.rb @@ -26,7 +26,7 @@ module Vagrant @env[:ui].info I18n.t("vagrant.actions.vm.boot.waiting") @env[:vm].config.ssh.max_tries.to_i.times do |i| - if @env[:vm].ssh.up? + if @env[:vm].channel.ready? @env[:ui].info I18n.t("vagrant.actions.vm.boot.ready") return true end diff --git a/lib/vagrant/action/vm/share_folders.rb b/lib/vagrant/action/vm/share_folders.rb index 6bfa9fbb1..98363da6d 100644 --- a/lib/vagrant/action/vm/share_folders.rb +++ b/lib/vagrant/action/vm/share_folders.rb @@ -49,36 +49,34 @@ module Vagrant def mount_shared_folders @env[:ui].info I18n.t("vagrant.actions.vm.share_folders.mounting") - @env["vm"].ssh.execute do |ssh| - # short guestpaths first, so we don't step on ourselves - folders = shared_folders.sort_by do |name, data| - if data[:guestpath] - data[:guestpath].length - else - # A long enough path to just do this at the end. - 10000 - end + # short guestpaths first, so we don't step on ourselves + folders = shared_folders.sort_by do |name, data| + if data[:guestpath] + data[:guestpath].length + else + # A long enough path to just do this at the end. + 10000 end + end - # Go through each folder and mount - folders.each do |name, data| - if data[:guestpath] - # Guest path specified, so mount the folder to specified point - @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", - :name => name, - :guest_path => data[:guestpath])) + # Go through each folder and mount + folders.each do |name, data| + if data[:guestpath] + # Guest path specified, so mount the folder to specified point + @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", + :name => name, + :guest_path => data[:guestpath])) - # Calculate the owner and group - owner = data[:owner] || @env[:vm].config.ssh.username - group = data[:group] || @env[:vm].config.ssh.username + # Calculate the owner and group + owner = data[:owner] || @env[:vm].config.ssh.username + group = data[:group] || @env[:vm].config.ssh.username - # Mount the actual folder - @env[:vm].guest.mount_shared_folder(ssh, name, data[:guestpath], owner, group) - else - # If no guest path is specified, then automounting is disabled - @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry", - :name => name)) - end + # Mount the actual folder + @env[:vm].guest.mount_shared_folder(name, data[:guestpath], owner, group) + else + # If no guest path is specified, then automounting is disabled + @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry", + :name => name)) end end end diff --git a/lib/vagrant/communication/ssh.rb b/lib/vagrant/communication/ssh.rb index 4c1997d98..03f812295 100644 --- a/lib/vagrant/communication/ssh.rb +++ b/lib/vagrant/communication/ssh.rb @@ -69,7 +69,7 @@ module Vagrant # Opens an SSH connection and yields it to a block. def connect - ssh_info = @vm.ssh_info + ssh_info = @vm.ssh.info # Build the options we'll use to initiate the connection via Net::SSH opts = { diff --git a/lib/vagrant/guest/base.rb b/lib/vagrant/guest/base.rb index 10ed53c17..4cde0658c 100644 --- a/lib/vagrant/guest/base.rb +++ b/lib/vagrant/guest/base.rb @@ -51,18 +51,17 @@ module Vagrant raise BaseError, :_key => :unsupported_halt end - # Mounts a shared folder. This method is called by the shared - # folder action with an open SSH session (passed in as `ssh`). + # Mounts a shared folder. + # # This method should create, mount, and properly set permissions # on the shared folder. This method should also properly # adhere to any configuration values such as `shared_folder_uid` # on `config.vm`. # - # @param [Object] ssh The Net::SSH session. # @param [String] name The name of the shared folder. # @param [String] guestpath The path on the machine which the user # wants the folder mounted. - def mount_shared_folder(ssh, name, guestpath, owner, group) + def mount_shared_folder(name, guestpath, owner, group) raise BaseError, :_key => :unsupported_shared_folder end diff --git a/lib/vagrant/guest/linux.rb b/lib/vagrant/guest/linux.rb index 8f81795bd..4a4c593b3 100644 --- a/lib/vagrant/guest/linux.rb +++ b/lib/vagrant/guest/linux.rb @@ -5,18 +5,16 @@ module Vagrant module Guest class Linux < Base 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") + if @vm.channel.execute("cat /etc/debian_version") == 0 + return :debian if @vm.channel.execute("cat /proc/version | grep 'Debian'") == 0 + return :ubuntu if @vm.channel.execute("cat /proc/version | grep 'Ubuntu'") == 0 end + return :gentoo if @vm.channel.execute("cat /etc/gentoo-release") == 0 + return :redhat if @vm.channel.execute("cat /etc/redhat-release") == 0 + return :suse if @vm.channel.execute("cat /etc/SuSE-release") == 0 + return :arch if @vm.channel.execute("cat /etc/arch-release") == 0 + # Can't detect the distro, assume vanilla linux nil end @@ -39,10 +37,10 @@ module Vagrant end end - 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}") + def mount_shared_folder(name, guestpath, owner, group) + @vm.channel.sudo("mkdir -p #{guestpath}") + mount_folder(name, guestpath, owner, group) + @vm.channel.sudo("chown `id -u #{owner}`:`id -g #{group}` #{guestpath}") end def mount_nfs(ip, folders) @@ -59,18 +57,18 @@ module Vagrant #------------------------------------------------------------------- # "Private" methods which assist above methods #------------------------------------------------------------------- - def mount_folder(ssh, name, guestpath, owner, group, sleeptime=5) + def mount_folder(name, guestpath, owner, group, sleeptime=5) # Determine the permission string to attach to the mount command 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| - # net/ssh returns the value in ch[:result] (based on looking at source) - ch[:result] = !!(type == :stderr && data =~ /No such device/i) + success = true + @vm.channel.sudo("mount -t vboxsf #{options} #{name} #{guestpath}") do |type, data| + success = false if type == :stderr && data =~ /No such device/i end - break unless result + break if success attempts += 1 raise LinuxError, :mount_fail if attempts >= 10 diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index e6ce82d50..d9f88a63f 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -54,6 +54,12 @@ module Vagrant end end + # Returns a channel object to communicate with the virtual + # machine. + def channel + @channel ||= Communication::SSH.new(self) + end + # Returns the guest for this VM, loading the distro of the system if # we can. def guest @@ -67,9 +73,8 @@ module Vagrant @guest end - # Access the {Vagrant::SSH} object associated with this VM. - # On the initial call, this will initialize the object. On - # subsequent calls it will reuse the existing object. + # Access the {Vagrant::SSH} object associated with this VM, which + # is used to get SSH credentials with the virtual machine. def ssh @ssh ||= SSH.new(self) end