Fix up the chef solo provisioner to work with new machine abstraction

This commit is contained in:
Mitchell Hashimoto 2012-08-21 16:57:17 -07:00
parent f193d69fbc
commit a238e06795
2 changed files with 20 additions and 15 deletions

View File

@ -20,10 +20,10 @@ module VagrantPlugins
def verify_binary(binary) def verify_binary(binary)
# 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.
env[:vm].channel.sudo("which #{binary}", env[:machine].communicate.sudo("which #{binary}",
:error_class => ChefError, :error_class => ChefError,
:error_key => :chef_not_detected, :error_key => :chef_not_detected,
:binary => binary) :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
@ -34,8 +34,10 @@ module VagrantPlugins
end end
def chown_provisioning_folder def chown_provisioning_folder
env[:vm].channel.sudo("mkdir -p #{config.provisioning_path}") env[:machine].communicate.tap do |comm|
env[:vm].channel.sudo("chown #{env[:vm].config.ssh.username} #{config.provisioning_path}") comm.sudo("mkdir -p #{config.provisioning_path}")
comm.sudo("chown #{env[:machine].config.ssh.username} #{config.provisioning_path}")
end
end end
def setup_config(template, filename, template_vars) def setup_config(template, filename, template_vars)
@ -57,8 +59,10 @@ module VagrantPlugins
temp.close temp.close
remote_file = File.join(config.provisioning_path, filename) remote_file = File.join(config.provisioning_path, filename)
env[:vm].channel.sudo("rm #{remote_file}", :error_check => false) env[:machine].communicate.tap do |comm|
env[:vm].channel.upload(temp.path, remote_file) comm.sudo("rm #{remote_file}", :error_check => false)
comm.upload(temp.path, remote_file)
end
end end
def setup_json def setup_json
@ -73,7 +77,7 @@ module VagrantPlugins
temp.write(json) temp.write(json)
temp.close 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 end
class ChefError < Vagrant::Errors::VagrantError class ChefError < Vagrant::Errors::VagrantError

View File

@ -155,16 +155,17 @@ module VagrantPlugins
def share_folders(prefix, folders) def share_folders(prefix, folders)
folders.each do |type, local_path, remote_path| folders.each do |type, local_path, remote_path|
if type == :host if type == :host
env[:vm].config.vm.share_folder("v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}", env[:machine].config.vm.share_folder(
remote_path, local_path, :nfs => config.nfs) "v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}",
remote_path, local_path, :nfs => config.nfs)
end end
end end
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].channel.upload(encrypted_data_bag_secret_key_path, env[:machine].communicate.upload(encrypted_data_bag_secret_key_path,
config.encrypted_data_bag_secret) config.encrypted_data_bag_secret)
end end
def setup_solo_config def setup_solo_config
@ -194,7 +195,7 @@ module VagrantPlugins
env[:ui].info I18n.t("vagrant.provisioners.chef.running_solo_again") env[:ui].info I18n.t("vagrant.provisioners.chef.running_solo_again")
end 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. # Output the data with the proper color based on the stream.
color = type == :stdout ? :green : :red color = type == :stdout ? :green : :red
@ -214,7 +215,7 @@ module VagrantPlugins
def verify_shared_folders(folders) def verify_shared_folders(folders)
folders.each do |folder| folders.each do |folder|
@logger.debug("Checking for shared folder: #{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 raise ChefError, :missing_shared_folders
end end
end end