diff --git a/lib/vagrant/command/ssh.rb b/lib/vagrant/command/ssh.rb index 3c4b67df9..5cebabed8 100644 --- a/lib/vagrant/command/ssh.rb +++ b/lib/vagrant/command/ssh.rb @@ -43,23 +43,17 @@ module Vagrant exit_status = 0 @logger.debug("Executing command: #{command}") - vm.ssh.execute do |ssh| - ssh.exec!(command) do |channel, type, data| - if type == :exit_status - exit_status = data.to_i - else - # Determine the proper channel to send the output onto depending - # on the type of data we are receiving. - channel = type == :stdout ? :out : :error + exit_status = vm.channel.execute(command) do |type, data| + # Determine the proper channel to send the output onto depending + # on the type of data we are receiving. + channel = type == :stdout ? :out : :error - # Print the SSH output as it comes in, but don't prefix it and don't - # force a new line so that the output is properly preserved - vm.ui.info(data.to_s, - :prefix => false, - :new_line => false, - :channel => channel) - end - end + # Print the SSH output as it comes in, but don't prefix it and don't + # force a new line so that the output is properly preserved + vm.ui.info(data.to_s, + :prefix => false, + :new_line => false, + :channel => channel) end # Exit with the exit status we got from executing the command diff --git a/lib/vagrant/communication/base.rb b/lib/vagrant/communication/base.rb index c405f4930..182f637cb 100644 --- a/lib/vagrant/communication/base.rb +++ b/lib/vagrant/communication/base.rb @@ -31,13 +31,25 @@ module Vagrant # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. # @return [Integer] Exit code of the command. - def execute(command) + def execute(command, opts=nil) end # Execute a comand with super user privileges. # # See #execute for parameter information. - def sudo(command) + def sudo(command, opts=nil) + end + + # Executes a command and returns a boolean statement if it was successful + # or not. + # + # This is implemented by default as expecting `execute` to return 0. + def test(command, opts=nil) + # Disable error checking no matter what + opts = (opts || {}).merge(:error_check => false) + + # Successful if the exit status is 0 + execute(command, opts) == 0 end end end diff --git a/lib/vagrant/communication/ssh.rb b/lib/vagrant/communication/ssh.rb index 03f812295..a40f19035 100644 --- a/lib/vagrant/communication/ssh.rb +++ b/lib/vagrant/communication/ssh.rb @@ -36,19 +36,37 @@ module Vagrant return false end - def execute(command, &block) + def execute(command, opts=nil, &block) + opts = { + :error_check => true, + :error_class => Errors::VagrantError, + :error_key => :ssh_bad_exit_status, + :command => command, + :sudo => false + }.merge(opts || {}) + # Connect via SSH and execute the command in the shell. - connect do |connection| - shell_execute(connection, command, &block) + exit_status = connect do |connection| + shell_execute(connection, command, opts[:sudo], &block) end + + # Check for any errors + if opts[:error_check] && exit_status != 0 + # The error classes expect the translation key to be _key, + # but that makes for an ugly configuration parameter, so we + # set it here from `error_key` + error_opts = opts.merge(:_key => opts[:error_key]) + raise opts[:error_class], error_opts + end + + # Return the exit status + exit_status end - def sudo(command, &block) - # Connect ia SSH and execute the command with super-user - # privileges in a shell. - connect do |connection| - shell_execute(connection, command, true, &block) - end + def sudo(command, opts=nil, &block) + # Run `execute` but with the `sudo` option. + opts = { :sudo => true }.merge(opts || {}) + execute(command, opts, &block) end def upload(from, to) diff --git a/lib/vagrant/guest/arch.rb b/lib/vagrant/guest/arch.rb index 38ff8d25a..e0ece0f09 100644 --- a/lib/vagrant/guest/arch.rb +++ b/lib/vagrant/guest/arch.rb @@ -2,16 +2,15 @@ module Vagrant module Guest class Arch < Linux def change_host_name(name) - vm.ssh.execute do |ssh| - # Only do this if the hostname is not already set - if !ssh.test?("sudo hostname | grep '#{name}'") - ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/rc.conf") - ssh.exec!("sudo hostname #{name}") - ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts") - end + # Only do this if the hostname is not already set + if !vm.channel.test("sudo hostname | grep '#{name}'") + vm.channel.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/rc.conf") + vm.channel.sudo("hostname #{name}") + vm.channel.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts") end end + # TODO: Convert these to the new format def prepare_host_only_network(net_options=nil) vm.ssh.execute do |ssh| ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-HOSTONLY/,/^#VAGRANT-END-HOSTONLY/ d' /etc/rc.conf > /tmp/vagrant-network-interfaces") diff --git a/lib/vagrant/guest/debian.rb b/lib/vagrant/guest/debian.rb index 5f19c1e33..95dd437c6 100644 --- a/lib/vagrant/guest/debian.rb +++ b/lib/vagrant/guest/debian.rb @@ -11,10 +11,8 @@ module Vagrant def configure_networks(networks) # First, remove any previous network modifications # from the interface file. - vm.ssh.execute do |ssh| - ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'") - end + vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces") + vm.channel.sudo("su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'") # Accumulate the configurations to add to the interfaces file as # well as what interfaces we're actually configuring since we use that @@ -29,32 +27,28 @@ module Vagrant # Perform the careful dance necessary to reconfigure # the network interfaces - vm.ssh.upload!(StringIO.new(entries.join("\n")), "/tmp/vagrant-network-entry") + vm.channel.upload(StringIO.new(entries.join("\n")), "/tmp/vagrant-network-entry") - vm.ssh.execute do |ssh| - # Bring down all the interfaces we're reconfiguring. By bringing down - # each specifically, we avoid reconfiguring eth0 (the NAT interface) so - # SSH never dies. - interfaces.each do |interface| - ssh.exec!("sudo /sbin/ifdown eth#{interface} 2> /dev/null") - end + # Bring down all the interfaces we're reconfiguring. By bringing down + # each specifically, we avoid reconfiguring eth0 (the NAT interface) so + # SSH never dies. + interfaces.each do |interface| + vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null") + end - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'") + vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/network/interfaces") - # Bring back up each network interface, reconfigured - interfaces.each do |interface| - ssh.exec!("sudo /sbin/ifup eth#{interface}") - end + # Bring back up each network interface, reconfigured + interfaces.each do |interface| + vm.channel.sudo("/sbin/ifup eth#{interface}") end end def change_host_name(name) - vm.ssh.execute do |ssh| - if !ssh.test?("sudo hostname | grep '#{name}'") - ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") - ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname") - ssh.exec!("sudo hostname -F /etc/hostname") - end + if !vm.channel.test("sudo hostname | grep '#{name}'") + vm.channel.sudo("sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") + vm.channel.sudo("sed -i 's/.*$/#{name}/' /etc/hostname") + vm.channel.sudo("hostname -F /etc/hostname") end end end diff --git a/lib/vagrant/guest/freebsd.rb b/lib/vagrant/guest/freebsd.rb index fa9104ba3..2d597d14b 100644 --- a/lib/vagrant/guest/freebsd.rb +++ b/lib/vagrant/guest/freebsd.rb @@ -25,9 +25,7 @@ module Vagrant def halt vm.ui.info I18n.t("vagrant.guest.freebsd.attempting_halt") - vm.ssh.execute do |ssh| - ssh.exec!("sudo shutdown -p now") - end + vm.channel.sudo("shutdown -p now") # Wait until the VM's state is actually powered off. If this doesn't # occur within a reasonable amount of time (15 seconds by default), @@ -51,10 +49,8 @@ module Vagrant 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]}") - end + vm.channel.sudo("mkdir -p #{opts[:guestpath]}") + vm.channel.sudo("mount #{ip}:#{opts[:hostpath]} #{opts[:guestpath]}") end end diff --git a/lib/vagrant/guest/linux.rb b/lib/vagrant/guest/linux.rb index 4a4c593b3..573bdda9a 100644 --- a/lib/vagrant/guest/linux.rb +++ b/lib/vagrant/guest/linux.rb @@ -5,15 +5,15 @@ module Vagrant module Guest class Linux < Base def distro_dispatch - 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 + if @vm.channel.test("cat /etc/debian_version") + return :debian if @vm.channel.test("cat /proc/version | grep 'Debian'") + return :ubuntu if @vm.channel.test("cat /proc/version | grep 'Ubuntu'") 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 + return :gentoo if @vm.channel.test("cat /etc/gentoo-release") + return :redhat if @vm.channel.test("cat /etc/redhat-release") + return :suse if @vm.channel.test("cat /etc/SuSE-release") + return :arch if @vm.channel.test("cat /etc/arch-release") # Can't detect the distro, assume vanilla linux nil @@ -21,9 +21,7 @@ module Vagrant def halt vm.ui.info I18n.t("vagrant.guest.linux.attempting_halt") - vm.ssh.execute do |ssh| - ssh.exec!("sudo shutdown -h now") - end + vm.channel.sudo("shutdown -h now") # Wait until the VM's state is actually powered off. If this doesn't # occur within a reasonable amount of time (15 seconds by default), @@ -47,10 +45,10 @@ module Vagrant # TODO: Maybe check for nfs support on the guest, since its often # not installed by default 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 + vm.channel.sudo("mkdir -p #{opts[:guestpath]}") + vm.channel.sudo("mount #{ip}:'#{opts[:hostpath]}' #{opts[:guestpath]}", + :error_class => LinuxError, + :error_key => :mount_nfs_fail) end end diff --git a/lib/vagrant/guest/redhat.rb b/lib/vagrant/guest/redhat.rb index 901db3c1d..5be274b28 100644 --- a/lib/vagrant/guest/redhat.rb +++ b/lib/vagrant/guest/redhat.rb @@ -18,59 +18,24 @@ module Vagrant # Remove any previous vagrant configuration in this network interface's # configuration files. - vm.ssh.execute do |ssh| - ssh.exec!("sudo touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}") - ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}'") - end + vm.channel.sudo("touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}") + vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}") + vm.channel.sudo("cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}") # Render and upload the network entry file to a deterministic # temporary location. entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}", :options => network) - vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry_#{network[:interface]}") + vm.channel.upload(StringIO.new(entry), "/tmp/vagrant-network-entry_#{network[:interface]}") end - # Perform the careful dance necessary to reconfigure the network interfaces - vm.ssh.execute do |ssh| - # Bring down all the interfaces we're reconfiguring. By bringing down - # each specifically, we avoid reconfiguring eth0 (the NAT interface) so - # SSH never dies. - interfaces.each do |interface| - ssh.exec!("sudo /sbin/ifdown eth#{interface} 2> /dev/null") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}'") - # Bring back up each network interface, reconfigured - ssh.exec!("sudo /sbin/ifup eth#{interface}") - end - end - end - - def prepare_bridged_networks(networks) - # Remove any previous bridged network additions from the - # interface file. - vm.ssh.execute do |ssh| - networks.each do |network| - # Clear out any previous entries - ssh.exec!("sudo touch #{network_scripts_dir}/ifcfg-eth#{network[:adapter]}") - ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-BRIDGED/,/^#VAGRANT-END-BRIDGED/ d' #{network_scripts_dir}/ifcfg-eth#{network[:adapter]} > /tmp/vagrant-ifcfg-eth#{network[:adapter]}") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{network[:adapter]} > #{network_scripts_dir}/ifcfg-eth#{network[:adapter]}'") - end - end - end - - def enable_bridged_networks(networks) - entry = TemplateRenderer.render('guests/redhat/network_bridged', - :networks => networks) - - vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") - - vm.ssh.execute do |ssh| - networks.each do |network| - interface_up = ssh.test?("/sbin/ifconfig eth#{network[:adapter]} | grep 'inet addr:'") - ssh.exec!("sudo /sbin/ifdown eth#{network[:adapter]} 2> /dev/null") if interface_up - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> #{network_scripts_dir}/ifcfg-eth#{network[:adapter]}'") - ssh.exec!("sudo /sbin/ifup eth#{network[:adapter]}") - end + # Bring down all the interfaces we're reconfiguring. By bringing down + # each specifically, we avoid reconfiguring eth0 (the NAT interface) so + # SSH never dies. + interfaces.each do |interface| + vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null") + vm.channel.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}") + vm.channel.sudo("/sbin/ifup eth#{interface}") end end @@ -83,13 +48,11 @@ module Vagrant end def change_host_name(name) - vm.ssh.execute do |ssh| - # Only do this if the hostname is not already set - if !ssh.test?("sudo hostname | grep '#{name}'") - ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") - ssh.exec!("sudo hostname #{name}") - ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") - end + # Only do this if the hostname is not already set + if !vm.channel.test("sudo hostname | grep '#{name}'") + vm.channel.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") + vm.channel.sudo("hostname #{name}") + vm.channel.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") end end end diff --git a/lib/vagrant/guest/solaris.rb b/lib/vagrant/guest/solaris.rb index 596907b48..3e226a126 100644 --- a/lib/vagrant/guest/solaris.rb +++ b/lib/vagrant/guest/solaris.rb @@ -45,16 +45,14 @@ module Vagrant def change_host_name(name) su_cmd = vm.config.solaris.suexec_cmd - vm.ssh.execute do |ssh| - # Only do this if the hostname is not already set - if !ssh.test?("#{su_cmd} hostname | grep '#{name}'") - ssh.exec!("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"") - ssh.exec!("#{su_cmd} uname -S #{name}") - end + + # Only do this if the hostname is not already set + if !vm.channel.test("#{su_cmd} hostname | grep '#{name}'") + vm.channel.execute("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"") + vm.channel.execute("#{su_cmd} uname -S #{name}") end end - # There should be an exception raised if the line # # vagrant::::profiles=Primary Administrator @@ -62,49 +60,48 @@ module Vagrant # does not exist in /etc/user_attr. TODO def halt vm.ui.info I18n.t("vagrant.guest.solaris.attempting_halt") - vm.ssh.execute do |ssh| - # Wait until the VM's state is actually powered off. If this doesn't - # occur within a reasonable amount of time (15 seconds by default), - # then simply return and allow Vagrant to kill the machine. - count = 0 - last_error = nil - while vm.state != :poweroff - begin - ssh.exec!("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff") - rescue IOError => e - # Save the last error; if it's not shutdown in a reasonable amount - # of attempts we will re-raise the error so it's not hidden for - # all time - last_error = e - end - count += 1 - if count >= vm.config.solaris.halt_timeout - # Check for last error and re-raise it - if last_error != nil - raise last_error - else - # Otherwise, just return - return - end - end + # Wait until the VM's state is actually powered off. If this doesn't + # occur within a reasonable amount of time (15 seconds by default), + # then simply return and allow Vagrant to kill the machine. + count = 0 + last_error = nil + while vm.state != :poweroff + begin + vm.channel.execute("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff") + rescue IOError => e + # Save the last error; if it's not shutdown in a reasonable amount + # of attempts we will re-raise the error so it's not hidden for + # all time + last_error = e + end - # Still opportunities remaining; sleep and loop - sleep vm.config.solaris.halt_check_interval - end # while - end # do + count += 1 + if count >= vm.config.solaris.halt_timeout + # Check for last error and re-raise it + if last_error != nil + raise last_error + else + # Otherwise, just return + return + end + end + + # Still opportunities remaining; sleep and loop + sleep vm.config.solaris.halt_check_interval + end # while end - def mount_shared_folder(ssh, name, guestpath, owner, group) + def mount_shared_folder(name, guestpath, owner, group) # Create the shared folder - ssh.exec!("#{vm.config.solaris.suexec_cmd} mkdir -p #{guestpath}") + vm.channel.execute("#{vm.config.solaris.suexec_cmd} mkdir -p #{guestpath}") # Mount the folder with the proper owner/group options = "-o uid=`id -u #{owner}`,gid=`id -g #{group}`" - ssh.exec!("#{vm.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{options} #{name} #{guestpath}") + vm.channel.execute("#{vm.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{options} #{name} #{guestpath}") # chown the folder to the proper owner/group - ssh.exec!("#{vm.config.solaris.suexec_cmd} chown `id -u #{owner}`:`id -g #{group}` #{guestpath}") + vm.channel.execute("#{vm.config.solaris.suexec_cmd} chown `id -u #{owner}`:`id -g #{group}` #{guestpath}") end end end diff --git a/lib/vagrant/guest/ubuntu.rb b/lib/vagrant/guest/ubuntu.rb index 677eec9e3..3414a99e2 100644 --- a/lib/vagrant/guest/ubuntu.rb +++ b/lib/vagrant/guest/ubuntu.rb @@ -4,12 +4,10 @@ module Vagrant module Guest class Ubuntu < Debian def change_host_name(name) - vm.ssh.execute do |ssh| - if !ssh.test?("sudo hostname | grep '#{name}'") - ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname") - ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") - ssh.exec!("sudo service hostname start") - end + if !vm.channel.test("sudo hostname | grep '#{name}'") + vm.channel.sudo("sed -i 's/.*$/#{name}/' /etc/hostname") + vm.channel.sudo("sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") + vm.channel.sudo("service hostname start") end end end diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 03a780d7b..679c36163 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -17,12 +17,12 @@ module Vagrant end def verify_binary(binary) - env[:vm].ssh.execute do |ssh| - # Checks for the existence of chef binary and error if it - # doesn't exist. - ssh.sudo!("which #{binary}", :error_class => ChefError, - :_key => :chef_not_detected, :binary => binary) - end + # Checks for the existence of chef binary and error if it + # doesn't exist. + env[:vm].channel.sudo("which #{binary}", + :error_class => ChefError, + :error_key => :chef_not_detected, + :binary => binary) end # Returns the path to the Chef binary, taking into account the @@ -33,10 +33,8 @@ module Vagrant end def chown_provisioning_folder - env[:vm].ssh.execute do |ssh| - ssh.sudo!("mkdir -p #{config.provisioning_path}") - ssh.sudo!("chown #{env[:vm].config.ssh.username} #{config.provisioning_path}") - end + env[:vm].channel.sudo("mkdir -p #{config.provisioning_path}") + env[:vm].channel.sudo("chown #{env[:vm].config.ssh.username} #{config.provisioning_path}") end def setup_config(template, filename, template_vars) @@ -51,8 +49,8 @@ module Vagrant :no_proxy => config.no_proxy }.merge(template_vars)) - env[:vm].ssh.upload!(StringIO.new(config_file), - File.join(config.provisioning_path, filename)) + env[:vm].channel.upload(StringIO.new(config_file), + File.join(config.provisioning_path, filename)) end def setup_json @@ -74,7 +72,8 @@ module Vagrant json = data.to_json - env[:vm].ssh.upload!(StringIO.new(json), File.join(config.provisioning_path, "dna.json")) + env[:vm].channel.upload(StringIO.new(json), + File.join(config.provisioning_path, "dna.json")) end end diff --git a/lib/vagrant/provisioners/chef_client.rb b/lib/vagrant/provisioners/chef_client.rb index b198ef36b..f3661acf4 100644 --- a/lib/vagrant/provisioners/chef_client.rb +++ b/lib/vagrant/provisioners/chef_client.rb @@ -63,19 +63,18 @@ module Vagrant env[:ui].info I18n.t("vagrant.provisioners.chef.client_key_folder") path = Pathname.new(config.client_key_path) - env[:vm].ssh.execute do |ssh| - ssh.sudo!("mkdir -p #{path.dirname}") - end + env[:vm].channel.sudo("mkdir -p #{path.dirname}") end def upload_validation_key env[:ui].info I18n.t("vagrant.provisioners.chef.upload_validation_key") - env[:vm].ssh.upload!(validation_key_path, guest_validation_key_path) + env[:vm].channel.upload(validation_key_path, guest_validation_key_path) end def upload_encrypted_data_bag_secret env[:ui].info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key") - env[:vm].ssh.upload!(encrypted_data_bag_secret_key_path, config.encrypted_data_bag_secret) + env[:vm].channel.upload(encrypted_data_bag_secret_key_path, + config.encrypted_data_bag_secret) end def setup_server_config @@ -97,19 +96,13 @@ module Vagrant command = "#{command_env}#{chef_binary_path("chef-client")} -c #{config.provisioning_path}/client.rb -j #{config.provisioning_path}/dna.json" env[:ui].info I18n.t("vagrant.provisioners.chef.running_client") - env[:vm].ssh.execute do |ssh| - ssh.sudo!(command) do |channel, type, data| - if type == :exit_status - ssh.check_exit_status(data, command) - else - # Output the data with the proper color based on the stream. - color = type == :stdout ? :green : :red + vm.channel.sudo(command) do |type, data| + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red - # Note: Be sure to chomp the data to avoid the newlines that the - # Chef outputs. - env[:ui].info(data.chomp, :color => color, :prefix => false) - end - end + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 0cb2b2c77..ac0a72209 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -128,19 +128,13 @@ module Vagrant command = "#{command_env}#{chef_binary_path("chef-solo")} -c #{config.provisioning_path}/solo.rb -j #{config.provisioning_path}/dna.json" env[:ui].info I18n.t("vagrant.provisioners.chef.running_solo") - env[:vm].ssh.execute do |ssh| - ssh.sudo!(command) do |channel, type, data| - if type == :exit_status - ssh.check_exit_status(data, command) - else - # Output the data with the proper color based on the stream. - color = type == :stdout ? :green : :red + env[:vm].channel.sudo(command) do |type, data| + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red - # Note: Be sure to chomp the data to avoid the newlines that the - # Chef outputs. - env[:ui].info(data.chomp, :color => color, :prefix => false) - end - end + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end diff --git a/lib/vagrant/provisioners/puppet.rb b/lib/vagrant/provisioners/puppet.rb index 354073648..82b7d9ad0 100644 --- a/lib/vagrant/provisioners/puppet.rb +++ b/lib/vagrant/provisioners/puppet.rb @@ -116,9 +116,10 @@ module Vagrant end def verify_binary(binary) - env[:vm].ssh.execute do |ssh| - ssh.sudo!("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary) - end + env[:vm].channel.sudo("which #{binary}", + :error_class => PuppetError, + :error_key => :puppet_not_detected, + :binary => binary) end def run_puppet_client @@ -127,24 +128,17 @@ module Vagrant options << config.computed_manifest_file options = options.join(" ") - commands = ["cd #{manifests_guest_path}", - "puppet apply #{options}"] + command = "cd #{manifests_guest_path} && puppet apply #{options}" env[:ui].info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => config.computed_manifest_file) - env[:vm].ssh.execute do |ssh| - ssh.sudo! commands do |ch, type, data| - if type == :exit_status - ssh.check_exit_status(data, commands) - else - # Output the data with the proper color based on the stream. - color = type == :stdout ? :green : :red + env[:vm].channel.sudo(command) do |type, data| + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red - # Note: Be sure to chomp the data to avoid the newlines that the - # Chef outputs. - env[:ui].info(data.chomp, :color => color, :prefix => false) - end - end + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end end diff --git a/lib/vagrant/provisioners/puppet_server.rb b/lib/vagrant/provisioners/puppet_server.rb index 5dcf5b7c6..93c2f193e 100644 --- a/lib/vagrant/provisioners/puppet_server.rb +++ b/lib/vagrant/provisioners/puppet_server.rb @@ -27,9 +27,10 @@ module Vagrant end def verify_binary(binary) - vm.ssh.execute do |ssh| - ssh.sudo!("which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary) - end + env[:vm].channel.sudo("which #{binary}", + :error_class => PuppetServerError, + :error_key => :puppetd_not_detected, + :binary => binary) end def run_puppetd_client @@ -38,18 +39,14 @@ module Vagrant if config.puppet_node cn = config.puppet_node else - cn = env.config.vm.box + cn = env[:vm].config.vm.box end - commands = "puppetd #{options} --server #{config.puppet_server} --certname #{cn}" + command = "puppetd #{options} --server #{config.puppet_server} --certname #{cn}" env.ui.info I18n.t("vagrant.provisioners.puppet_server.running_puppetd") - - vm.ssh.execute do |ssh| - ssh.sudo!(commands) do |channel, type, data| - ssh.check_exit_status(data, commands) if type == :exit_status - env.ui.info(data) if type != :exit_status - end + env[:vm].channel.sudo(command) do |type, data| + env.ui.info(data) end end end diff --git a/lib/vagrant/provisioners/shell.rb b/lib/vagrant/provisioners/shell.rb index 74e0fff5d..8849453d0 100644 --- a/lib/vagrant/provisioners/shell.rb +++ b/lib/vagrant/provisioners/shell.rb @@ -75,26 +75,20 @@ module Vagrant def provision! args = "" args = " #{config.args}" if config.args - commands = ["chmod +x #{config.upload_path}", "#{config.upload_path}#{args}"] + command = "chmod +x #{config.upload_path} && #{config.upload_path}#{args}" with_script_file do |path| # Upload the script to the VM - env[:vm].ssh.upload!(path.to_s, config.upload_path) + env[:vm].channel.upload(path.to_s, config.upload_path) # Execute it with sudo - env[:vm].ssh.execute do |ssh| - ssh.sudo!(commands) do |ch, type, data| - if type == :exit_status - ssh.check_exit_status(data, commands) - else - # Output the data with the proper color based on the stream. - color = type == :stdout ? :green : :red + env[:vm].channel.sudo(command) do |ch, type, data| + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red - # Note: Be sure to chomp the data to avoid the newlines that the - # Chef outputs. - env[:ui].info(data.chomp, :color => color, :prefix => false) - end - end + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end end