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