Delete Chef client and node on cleanup

This fixes #1253 by shelling out to `knife` on cleanup, as per
@mitchellh's suggestion in #1255
This commit is contained in:
Nate Smith 2012-12-17 11:49:27 -05:00
parent 130a602e9b
commit 370d6b0c98
2 changed files with 17 additions and 0 deletions

View File

@ -18,6 +18,8 @@ module VagrantPlugins
attr_accessor :environment attr_accessor :environment
attr_accessor :encrypted_data_bag_secret_key_path attr_accessor :encrypted_data_bag_secret_key_path
attr_accessor :encrypted_data_bag_secret attr_accessor :encrypted_data_bag_secret
attr_accessor :delete_client
attr_accessor :delete_node
# Provide defaults in such a way that they won't override the instance # Provide defaults in such a way that they won't override the instance
# variable. This is so merging continues to work properly. # variable. This is so merging continues to work properly.
@ -26,6 +28,8 @@ module VagrantPlugins
def file_cache_path; @file_cache_path || "/srv/chef/file_store"; end def file_cache_path; @file_cache_path || "/srv/chef/file_store"; end
def file_backup_path; @file_backup_path || "/srv/chef/cache"; end def file_backup_path; @file_backup_path || "/srv/chef/cache"; end
def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end
def delete_client; @delete_client || true; end
def delete_node; @delete_node || true; end
def validate(env, errors) def validate(env, errors)
super super
@ -129,6 +133,18 @@ module VagrantPlugins
def guest_validation_key_path def guest_validation_key_path
File.join(config.provisioning_path, "validation.pem") File.join(config.provisioning_path, "validation.pem")
end end
def cleanup
delete_from_chef_server('client') if config.delete_client
delete_from_chef_server('node') if config.delete_node
end
def delete_from_chef_server(deletable)
node_name = (config.node_name || env[:vm].config.vm.host_name)
env[:ui].info I18n.t("vagrant.provisioners.chef.deleting_from_server",
:deletable => deletable)
Kernel.system("knife #{deletable} delete --yes #{node_name}")
end
end end
end end
end end

View File

@ -721,6 +721,7 @@ en:
server_validation_key_doesnt_exist: |- server_validation_key_doesnt_exist: |-
The validation key set for `config.chef.validation_key_path` does not exist! This The validation key set for `config.chef.validation_key_path` does not exist! This
file needs to exist so it can be uploaded to the virtual machine. file needs to exist so it can be uploaded to the virtual machine.
deleting_from_server: "Deleting %{deletable} from Chef server..."
puppet: puppet:
not_detected: |- not_detected: |-