From a238e067952f397a94e9ef3d70876852328556d5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 Aug 2012 16:57:17 -0700 Subject: [PATCH] Fix up the chef solo provisioner to work with new machine abstraction --- plugins/provisioners/chef/provisioner/base.rb | 22 +++++++++++-------- .../chef/provisioner/chef_solo.rb | 13 ++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plugins/provisioners/chef/provisioner/base.rb b/plugins/provisioners/chef/provisioner/base.rb index 313c0bdbf..14e81235f 100644 --- a/plugins/provisioners/chef/provisioner/base.rb +++ b/plugins/provisioners/chef/provisioner/base.rb @@ -20,10 +20,10 @@ module VagrantPlugins def verify_binary(binary) # 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) + env[:machine].communicate.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 @@ -34,8 +34,10 @@ module VagrantPlugins end def chown_provisioning_folder - env[:vm].channel.sudo("mkdir -p #{config.provisioning_path}") - env[:vm].channel.sudo("chown #{env[:vm].config.ssh.username} #{config.provisioning_path}") + env[:machine].communicate.tap do |comm| + comm.sudo("mkdir -p #{config.provisioning_path}") + comm.sudo("chown #{env[:machine].config.ssh.username} #{config.provisioning_path}") + end end def setup_config(template, filename, template_vars) @@ -57,8 +59,10 @@ module VagrantPlugins temp.close remote_file = File.join(config.provisioning_path, filename) - env[:vm].channel.sudo("rm #{remote_file}", :error_check => false) - env[:vm].channel.upload(temp.path, remote_file) + env[:machine].communicate.tap do |comm| + comm.sudo("rm #{remote_file}", :error_check => false) + comm.upload(temp.path, remote_file) + end end def setup_json @@ -73,7 +77,7 @@ module VagrantPlugins temp.write(json) temp.close - env[:vm].channel.upload(temp.path, File.join(config.provisioning_path, "dna.json")) + env[:machine].communicate.upload(temp.path, File.join(config.provisioning_path, "dna.json")) end class ChefError < Vagrant::Errors::VagrantError diff --git a/plugins/provisioners/chef/provisioner/chef_solo.rb b/plugins/provisioners/chef/provisioner/chef_solo.rb index 14ca4906a..33a21aa6e 100644 --- a/plugins/provisioners/chef/provisioner/chef_solo.rb +++ b/plugins/provisioners/chef/provisioner/chef_solo.rb @@ -155,16 +155,17 @@ module VagrantPlugins def share_folders(prefix, folders) folders.each do |type, local_path, remote_path| if type == :host - env[:vm].config.vm.share_folder("v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}", - remote_path, local_path, :nfs => config.nfs) + env[:machine].config.vm.share_folder( + "v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}", + remote_path, local_path, :nfs => config.nfs) end end end def upload_encrypted_data_bag_secret env[:ui].info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key") - env[:vm].channel.upload(encrypted_data_bag_secret_key_path, - config.encrypted_data_bag_secret) + env[:machine].communicate.upload(encrypted_data_bag_secret_key_path, + config.encrypted_data_bag_secret) end def setup_solo_config @@ -194,7 +195,7 @@ module VagrantPlugins env[:ui].info I18n.t("vagrant.provisioners.chef.running_solo_again") end - exit_status = env[:vm].channel.sudo(command, :error_check => false) do |type, data| + exit_status = env[:machine].communicate.sudo(command, :error_check => false) do |type, data| # Output the data with the proper color based on the stream. color = type == :stdout ? :green : :red @@ -214,7 +215,7 @@ module VagrantPlugins def verify_shared_folders(folders) folders.each do |folder| @logger.debug("Checking for shared folder: #{folder}") - if !env[:vm].channel.test("test -d #{folder}") + if !env[:machine].communicate.test("test -d #{folder}") raise ChefError, :missing_shared_folders end end