Convert everything to the new SSH API
This commit is contained in:
parent
7bdbec4229
commit
275ddae646
|
@ -43,11 +43,7 @@ module Vagrant
|
||||||
exit_status = 0
|
exit_status = 0
|
||||||
|
|
||||||
@logger.debug("Executing command: #{command}")
|
@logger.debug("Executing command: #{command}")
|
||||||
vm.ssh.execute do |ssh|
|
exit_status = vm.channel.execute(command) do |type, data|
|
||||||
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
|
# Determine the proper channel to send the output onto depending
|
||||||
# on the type of data we are receiving.
|
# on the type of data we are receiving.
|
||||||
channel = type == :stdout ? :out : :error
|
channel = type == :stdout ? :out : :error
|
||||||
|
@ -59,8 +55,6 @@ module Vagrant
|
||||||
:new_line => false,
|
:new_line => false,
|
||||||
:channel => channel)
|
:channel => channel)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Exit with the exit status we got from executing the command
|
# Exit with the exit status we got from executing the command
|
||||||
exit exit_status
|
exit exit_status
|
||||||
|
|
|
@ -31,13 +31,25 @@ module Vagrant
|
||||||
# @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc.
|
# @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc.
|
||||||
# @yieldparam [String] data Data for the given output.
|
# @yieldparam [String] data Data for the given output.
|
||||||
# @return [Integer] Exit code of the command.
|
# @return [Integer] Exit code of the command.
|
||||||
def execute(command)
|
def execute(command, opts=nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Execute a comand with super user privileges.
|
# Execute a comand with super user privileges.
|
||||||
#
|
#
|
||||||
# See #execute for parameter information.
|
# 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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,19 +36,37 @@ module Vagrant
|
||||||
return false
|
return false
|
||||||
end
|
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 via SSH and execute the command in the shell.
|
||||||
connect do |connection|
|
exit_status = connect do |connection|
|
||||||
shell_execute(connection, command, &block)
|
shell_execute(connection, command, opts[:sudo], &block)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sudo(command, &block)
|
# Check for any errors
|
||||||
# Connect ia SSH and execute the command with super-user
|
if opts[:error_check] && exit_status != 0
|
||||||
# privileges in a shell.
|
# The error classes expect the translation key to be _key,
|
||||||
connect do |connection|
|
# but that makes for an ugly configuration parameter, so we
|
||||||
shell_execute(connection, command, true, &block)
|
# set it here from `error_key`
|
||||||
|
error_opts = opts.merge(:_key => opts[:error_key])
|
||||||
|
raise opts[:error_class], error_opts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return the exit status
|
||||||
|
exit_status
|
||||||
|
end
|
||||||
|
|
||||||
|
def sudo(command, opts=nil, &block)
|
||||||
|
# Run `execute` but with the `sudo` option.
|
||||||
|
opts = { :sudo => true }.merge(opts || {})
|
||||||
|
execute(command, opts, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(from, to)
|
def upload(from, to)
|
||||||
|
|
|
@ -2,16 +2,15 @@ module Vagrant
|
||||||
module Guest
|
module Guest
|
||||||
class Arch < Linux
|
class Arch < Linux
|
||||||
def change_host_name(name)
|
def change_host_name(name)
|
||||||
vm.ssh.execute do |ssh|
|
|
||||||
# Only do this if the hostname is not already set
|
# Only do this if the hostname is not already set
|
||||||
if !ssh.test?("sudo hostname | grep '#{name}'")
|
if !vm.channel.test("sudo hostname | grep '#{name}'")
|
||||||
ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/rc.conf")
|
vm.channel.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/rc.conf")
|
||||||
ssh.exec!("sudo hostname #{name}")
|
vm.channel.sudo("hostname #{name}")
|
||||||
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
|
vm.channel.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: Convert these to the new format
|
||||||
def prepare_host_only_network(net_options=nil)
|
def prepare_host_only_network(net_options=nil)
|
||||||
vm.ssh.execute do |ssh|
|
vm.ssh.execute do |ssh|
|
||||||
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-HOSTONLY/,/^#VAGRANT-END-HOSTONLY/ d' /etc/rc.conf > /tmp/vagrant-network-interfaces")
|
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-HOSTONLY/,/^#VAGRANT-END-HOSTONLY/ d' /etc/rc.conf > /tmp/vagrant-network-interfaces")
|
||||||
|
|
|
@ -11,10 +11,8 @@ module Vagrant
|
||||||
def configure_networks(networks)
|
def configure_networks(networks)
|
||||||
# First, remove any previous network modifications
|
# First, remove any previous network modifications
|
||||||
# from the interface file.
|
# from the interface file.
|
||||||
vm.ssh.execute do |ssh|
|
vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
|
||||||
ssh.exec!("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'")
|
||||||
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Accumulate the configurations to add to the interfaces file as
|
# Accumulate the configurations to add to the interfaces file as
|
||||||
# well as what interfaces we're actually configuring since we use that
|
# 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
|
# Perform the careful dance necessary to reconfigure
|
||||||
# the network interfaces
|
# 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
|
# Bring down all the interfaces we're reconfiguring. By bringing down
|
||||||
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
||||||
# SSH never dies.
|
# SSH never dies.
|
||||||
interfaces.each do |interface|
|
interfaces.each do |interface|
|
||||||
ssh.exec!("sudo /sbin/ifdown eth#{interface} 2> /dev/null")
|
vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null")
|
||||||
end
|
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
|
# Bring back up each network interface, reconfigured
|
||||||
interfaces.each do |interface|
|
interfaces.each do |interface|
|
||||||
ssh.exec!("sudo /sbin/ifup eth#{interface}")
|
vm.channel.sudo("/sbin/ifup eth#{interface}")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_host_name(name)
|
def change_host_name(name)
|
||||||
vm.ssh.execute do |ssh|
|
if !vm.channel.test("sudo hostname | grep '#{name}'")
|
||||||
if !ssh.test?("sudo hostname | grep '#{name}'")
|
vm.channel.sudo("sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
||||||
ssh.exec!("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")
|
||||||
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
|
vm.channel.sudo("hostname -F /etc/hostname")
|
||||||
ssh.exec!("sudo hostname -F /etc/hostname")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,9 +25,7 @@ module Vagrant
|
||||||
|
|
||||||
def halt
|
def halt
|
||||||
vm.ui.info I18n.t("vagrant.guest.freebsd.attempting_halt")
|
vm.ui.info I18n.t("vagrant.guest.freebsd.attempting_halt")
|
||||||
vm.ssh.execute do |ssh|
|
vm.channel.sudo("shutdown -p now")
|
||||||
ssh.exec!("sudo shutdown -p now")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Wait until the VM's state is actually powered off. If this doesn't
|
# 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),
|
# occur within a reasonable amount of time (15 seconds by default),
|
||||||
|
@ -51,10 +49,8 @@ module Vagrant
|
||||||
|
|
||||||
def mount_nfs(ip, folders)
|
def mount_nfs(ip, folders)
|
||||||
folders.each do |name, opts|
|
folders.each do |name, opts|
|
||||||
vm.ssh.execute do |ssh|
|
vm.channel.sudo("mkdir -p #{opts[:guestpath]}")
|
||||||
ssh.exec!("sudo mkdir -p #{opts[:guestpath]}")
|
vm.channel.sudo("mount #{ip}:#{opts[:hostpath]} #{opts[:guestpath]}")
|
||||||
ssh.exec!("sudo mount #{ip}:#{opts[:hostpath]} #{opts[:guestpath]}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,15 @@ module Vagrant
|
||||||
module Guest
|
module Guest
|
||||||
class Linux < Base
|
class Linux < Base
|
||||||
def distro_dispatch
|
def distro_dispatch
|
||||||
if @vm.channel.execute("cat /etc/debian_version") == 0
|
if @vm.channel.test("cat /etc/debian_version")
|
||||||
return :debian if @vm.channel.execute("cat /proc/version | grep 'Debian'") == 0
|
return :debian if @vm.channel.test("cat /proc/version | grep 'Debian'")
|
||||||
return :ubuntu if @vm.channel.execute("cat /proc/version | grep 'Ubuntu'") == 0
|
return :ubuntu if @vm.channel.test("cat /proc/version | grep 'Ubuntu'")
|
||||||
end
|
end
|
||||||
|
|
||||||
return :gentoo if @vm.channel.execute("cat /etc/gentoo-release") == 0
|
return :gentoo if @vm.channel.test("cat /etc/gentoo-release")
|
||||||
return :redhat if @vm.channel.execute("cat /etc/redhat-release") == 0
|
return :redhat if @vm.channel.test("cat /etc/redhat-release")
|
||||||
return :suse if @vm.channel.execute("cat /etc/SuSE-release") == 0
|
return :suse if @vm.channel.test("cat /etc/SuSE-release")
|
||||||
return :arch if @vm.channel.execute("cat /etc/arch-release") == 0
|
return :arch if @vm.channel.test("cat /etc/arch-release")
|
||||||
|
|
||||||
# Can't detect the distro, assume vanilla linux
|
# Can't detect the distro, assume vanilla linux
|
||||||
nil
|
nil
|
||||||
|
@ -21,9 +21,7 @@ module Vagrant
|
||||||
|
|
||||||
def halt
|
def halt
|
||||||
vm.ui.info I18n.t("vagrant.guest.linux.attempting_halt")
|
vm.ui.info I18n.t("vagrant.guest.linux.attempting_halt")
|
||||||
vm.ssh.execute do |ssh|
|
vm.channel.sudo("shutdown -h now")
|
||||||
ssh.exec!("sudo shutdown -h now")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Wait until the VM's state is actually powered off. If this doesn't
|
# 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),
|
# 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
|
# TODO: Maybe check for nfs support on the guest, since its often
|
||||||
# not installed by default
|
# not installed by default
|
||||||
folders.each do |name, opts|
|
folders.each do |name, opts|
|
||||||
vm.ssh.execute do |ssh|
|
vm.channel.sudo("mkdir -p #{opts[:guestpath]}")
|
||||||
ssh.exec!("sudo mkdir -p #{opts[:guestpath]}")
|
vm.channel.sudo("mount #{ip}:'#{opts[:hostpath]}' #{opts[:guestpath]}",
|
||||||
ssh.exec!("sudo mount #{ip}:'#{opts[:hostpath]}' #{opts[:guestpath]}", :_error_class => LinuxError, :_key => :mount_nfs_fail)
|
:error_class => LinuxError,
|
||||||
end
|
:error_key => :mount_nfs_fail)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,59 +18,24 @@ module Vagrant
|
||||||
|
|
||||||
# Remove any previous vagrant configuration in this network interface's
|
# Remove any previous vagrant configuration in this network interface's
|
||||||
# configuration files.
|
# configuration files.
|
||||||
vm.ssh.execute do |ssh|
|
vm.channel.sudo("touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||||
ssh.exec!("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]}")
|
||||||
ssh.exec!("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]}")
|
||||||
ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}'")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Render and upload the network entry file to a deterministic
|
# Render and upload the network entry file to a deterministic
|
||||||
# temporary location.
|
# temporary location.
|
||||||
entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}",
|
entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}",
|
||||||
:options => network)
|
: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
|
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
|
# Bring down all the interfaces we're reconfiguring. By bringing down
|
||||||
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
||||||
# SSH never dies.
|
# SSH never dies.
|
||||||
interfaces.each do |interface|
|
interfaces.each do |interface|
|
||||||
ssh.exec!("sudo /sbin/ifdown eth#{interface} 2> /dev/null")
|
vm.channel.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}'")
|
vm.channel.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}")
|
||||||
# Bring back up each network interface, reconfigured
|
vm.channel.sudo("/sbin/ifup eth#{interface}")
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,13 +48,11 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_host_name(name)
|
def change_host_name(name)
|
||||||
vm.ssh.execute do |ssh|
|
|
||||||
# Only do this if the hostname is not already set
|
# Only do this if the hostname is not already set
|
||||||
if !ssh.test?("sudo hostname | grep '#{name}'")
|
if !vm.channel.test("sudo hostname | grep '#{name}'")
|
||||||
ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
|
vm.channel.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
|
||||||
ssh.exec!("sudo hostname #{name}")
|
vm.channel.sudo("hostname #{name}")
|
||||||
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
vm.channel.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,15 +45,13 @@ module Vagrant
|
||||||
|
|
||||||
def change_host_name(name)
|
def change_host_name(name)
|
||||||
su_cmd = vm.config.solaris.suexec_cmd
|
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
|
|
||||||
end
|
|
||||||
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
|
# There should be an exception raised if the line
|
||||||
#
|
#
|
||||||
|
@ -62,7 +60,7 @@ module Vagrant
|
||||||
# does not exist in /etc/user_attr. TODO
|
# does not exist in /etc/user_attr. TODO
|
||||||
def halt
|
def halt
|
||||||
vm.ui.info I18n.t("vagrant.guest.solaris.attempting_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
|
# 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),
|
# occur within a reasonable amount of time (15 seconds by default),
|
||||||
# then simply return and allow Vagrant to kill the machine.
|
# then simply return and allow Vagrant to kill the machine.
|
||||||
|
@ -70,7 +68,7 @@ module Vagrant
|
||||||
last_error = nil
|
last_error = nil
|
||||||
while vm.state != :poweroff
|
while vm.state != :poweroff
|
||||||
begin
|
begin
|
||||||
ssh.exec!("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff")
|
vm.channel.execute("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff")
|
||||||
rescue IOError => e
|
rescue IOError => e
|
||||||
# Save the last error; if it's not shutdown in a reasonable amount
|
# 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
|
# of attempts we will re-raise the error so it's not hidden for
|
||||||
|
@ -92,19 +90,18 @@ module Vagrant
|
||||||
# Still opportunities remaining; sleep and loop
|
# Still opportunities remaining; sleep and loop
|
||||||
sleep vm.config.solaris.halt_check_interval
|
sleep vm.config.solaris.halt_check_interval
|
||||||
end # while
|
end # while
|
||||||
end # do
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount_shared_folder(ssh, name, guestpath, owner, group)
|
def mount_shared_folder(name, guestpath, owner, group)
|
||||||
# Create the shared folder
|
# 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
|
# Mount the folder with the proper owner/group
|
||||||
options = "-o uid=`id -u #{owner}`,gid=`id -g #{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
|
# 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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,12 +4,10 @@ module Vagrant
|
||||||
module Guest
|
module Guest
|
||||||
class Ubuntu < Debian
|
class Ubuntu < Debian
|
||||||
def change_host_name(name)
|
def change_host_name(name)
|
||||||
vm.ssh.execute do |ssh|
|
if !vm.channel.test("sudo hostname | grep '#{name}'")
|
||||||
if !ssh.test?("sudo hostname | grep '#{name}'")
|
vm.channel.sudo("sed -i 's/.*$/#{name}/' /etc/hostname")
|
||||||
ssh.exec!("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")
|
||||||
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
vm.channel.sudo("service hostname start")
|
||||||
ssh.exec!("sudo service hostname start")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,12 +17,12 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_binary(binary)
|
def verify_binary(binary)
|
||||||
env[:vm].ssh.execute do |ssh|
|
|
||||||
# Checks for the existence of chef binary and error if it
|
# Checks for the existence of chef binary and error if it
|
||||||
# doesn't exist.
|
# doesn't exist.
|
||||||
ssh.sudo!("which #{binary}", :error_class => ChefError,
|
env[:vm].channel.sudo("which #{binary}",
|
||||||
:_key => :chef_not_detected, :binary => binary)
|
:error_class => ChefError,
|
||||||
end
|
:error_key => :chef_not_detected,
|
||||||
|
:binary => binary)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the path to the Chef binary, taking into account the
|
# Returns the path to the Chef binary, taking into account the
|
||||||
|
@ -33,10 +33,8 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def chown_provisioning_folder
|
def chown_provisioning_folder
|
||||||
env[:vm].ssh.execute do |ssh|
|
env[:vm].channel.sudo("mkdir -p #{config.provisioning_path}")
|
||||||
ssh.sudo!("mkdir -p #{config.provisioning_path}")
|
env[:vm].channel.sudo("chown #{env[:vm].config.ssh.username} #{config.provisioning_path}")
|
||||||
ssh.sudo!("chown #{env[:vm].config.ssh.username} #{config.provisioning_path}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_config(template, filename, template_vars)
|
def setup_config(template, filename, template_vars)
|
||||||
|
@ -51,7 +49,7 @@ module Vagrant
|
||||||
:no_proxy => config.no_proxy
|
:no_proxy => config.no_proxy
|
||||||
}.merge(template_vars))
|
}.merge(template_vars))
|
||||||
|
|
||||||
env[:vm].ssh.upload!(StringIO.new(config_file),
|
env[:vm].channel.upload(StringIO.new(config_file),
|
||||||
File.join(config.provisioning_path, filename))
|
File.join(config.provisioning_path, filename))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -74,7 +72,8 @@ module Vagrant
|
||||||
|
|
||||||
json = data.to_json
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -63,19 +63,18 @@ module Vagrant
|
||||||
env[:ui].info I18n.t("vagrant.provisioners.chef.client_key_folder")
|
env[:ui].info I18n.t("vagrant.provisioners.chef.client_key_folder")
|
||||||
path = Pathname.new(config.client_key_path)
|
path = Pathname.new(config.client_key_path)
|
||||||
|
|
||||||
env[:vm].ssh.execute do |ssh|
|
env[:vm].channel.sudo("mkdir -p #{path.dirname}")
|
||||||
ssh.sudo!("mkdir -p #{path.dirname}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload_validation_key
|
def upload_validation_key
|
||||||
env[:ui].info I18n.t("vagrant.provisioners.chef.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
|
end
|
||||||
|
|
||||||
def upload_encrypted_data_bag_secret
|
def upload_encrypted_data_bag_secret
|
||||||
env[:ui].info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
|
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
|
end
|
||||||
|
|
||||||
def setup_server_config
|
def setup_server_config
|
||||||
|
@ -97,11 +96,7 @@ module Vagrant
|
||||||
command = "#{command_env}#{chef_binary_path("chef-client")} -c #{config.provisioning_path}/client.rb -j #{config.provisioning_path}/dna.json"
|
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[:ui].info I18n.t("vagrant.provisioners.chef.running_client")
|
||||||
env[:vm].ssh.execute do |ssh|
|
vm.channel.sudo(command) do |type, data|
|
||||||
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.
|
# Output the data with the proper color based on the stream.
|
||||||
color = type == :stdout ? :green : :red
|
color = type == :stdout ? :green : :red
|
||||||
|
|
||||||
|
@ -110,8 +105,6 @@ module Vagrant
|
||||||
env[:ui].info(data.chomp, :color => color, :prefix => false)
|
env[:ui].info(data.chomp, :color => color, :prefix => false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def validation_key_path
|
def validation_key_path
|
||||||
File.expand_path(config.validation_key_path, env[:root_path])
|
File.expand_path(config.validation_key_path, env[:root_path])
|
||||||
|
|
|
@ -128,11 +128,7 @@ module Vagrant
|
||||||
command = "#{command_env}#{chef_binary_path("chef-solo")} -c #{config.provisioning_path}/solo.rb -j #{config.provisioning_path}/dna.json"
|
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[:ui].info I18n.t("vagrant.provisioners.chef.running_solo")
|
||||||
env[:vm].ssh.execute do |ssh|
|
env[:vm].channel.sudo(command) do |type, data|
|
||||||
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.
|
# Output the data with the proper color based on the stream.
|
||||||
color = type == :stdout ? :green : :red
|
color = type == :stdout ? :green : :red
|
||||||
|
|
||||||
|
@ -141,8 +137,6 @@ module Vagrant
|
||||||
env[:ui].info(data.chomp, :color => color, :prefix => false)
|
env[:ui].info(data.chomp, :color => color, :prefix => false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Extracts only the remote paths from a list of folders
|
# Extracts only the remote paths from a list of folders
|
||||||
def guest_paths(folders)
|
def guest_paths(folders)
|
||||||
|
|
|
@ -116,9 +116,10 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_binary(binary)
|
def verify_binary(binary)
|
||||||
env[:vm].ssh.execute do |ssh|
|
env[:vm].channel.sudo("which #{binary}",
|
||||||
ssh.sudo!("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary)
|
:error_class => PuppetError,
|
||||||
end
|
:error_key => :puppet_not_detected,
|
||||||
|
:binary => binary)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_puppet_client
|
def run_puppet_client
|
||||||
|
@ -127,16 +128,11 @@ module Vagrant
|
||||||
options << config.computed_manifest_file
|
options << config.computed_manifest_file
|
||||||
options = options.join(" ")
|
options = options.join(" ")
|
||||||
|
|
||||||
commands = ["cd #{manifests_guest_path}",
|
command = "cd #{manifests_guest_path} && puppet apply #{options}"
|
||||||
"puppet apply #{options}"]
|
|
||||||
|
|
||||||
env[:ui].info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => config.computed_manifest_file)
|
env[:ui].info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => config.computed_manifest_file)
|
||||||
|
|
||||||
env[:vm].ssh.execute do |ssh|
|
env[:vm].channel.sudo(command) do |type, data|
|
||||||
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.
|
# Output the data with the proper color based on the stream.
|
||||||
color = type == :stdout ? :green : :red
|
color = type == :stdout ? :green : :red
|
||||||
|
|
||||||
|
@ -148,6 +144,4 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,10 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_binary(binary)
|
def verify_binary(binary)
|
||||||
vm.ssh.execute do |ssh|
|
env[:vm].channel.sudo("which #{binary}",
|
||||||
ssh.sudo!("which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary)
|
:error_class => PuppetServerError,
|
||||||
end
|
:error_key => :puppetd_not_detected,
|
||||||
|
:binary => binary)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_puppetd_client
|
def run_puppetd_client
|
||||||
|
@ -38,18 +39,14 @@ module Vagrant
|
||||||
if config.puppet_node
|
if config.puppet_node
|
||||||
cn = config.puppet_node
|
cn = config.puppet_node
|
||||||
else
|
else
|
||||||
cn = env.config.vm.box
|
cn = env[:vm].config.vm.box
|
||||||
end
|
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")
|
env.ui.info I18n.t("vagrant.provisioners.puppet_server.running_puppetd")
|
||||||
|
env[:vm].channel.sudo(command) do |type, data|
|
||||||
vm.ssh.execute do |ssh|
|
env.ui.info(data)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,18 +75,14 @@ module Vagrant
|
||||||
def provision!
|
def provision!
|
||||||
args = ""
|
args = ""
|
||||||
args = " #{config.args}" if config.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|
|
with_script_file do |path|
|
||||||
# Upload the script to the VM
|
# 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
|
# Execute it with sudo
|
||||||
env[:vm].ssh.execute do |ssh|
|
env[:vm].channel.sudo(command) do |ch, type, data|
|
||||||
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.
|
# Output the data with the proper color based on the stream.
|
||||||
color = type == :stdout ? :green : :red
|
color = type == :stdout ? :green : :red
|
||||||
|
|
||||||
|
@ -99,5 +95,3 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue