class Chef::Knife::Cloud::ServerDeleteCommand
Public Instance Methods
delete_from_chef(server_name)
click to toggle source
# File lib/chef/knife/cloud/server/delete_command.rb, line 36 def delete_from_chef(server_name) # delete the node from Chef if purge requested. if config[:purge] thing_to_delete = config[:chef_node_name] || server_name destroy_item(Chef::Node, thing_to_delete, "node") destroy_item(Chef::ApiClient, thing_to_delete, "client") else ui.warn("Corresponding node and client for the #{server_name} server were not deleted and remain registered with the Chef Server") end end
destroy_item(klass, name, type_name)
click to toggle source
Extracted from Chef::Knife.delete_object, because it has a confirmation step built in… By specifying the '–purge' flag (and also explicitly confirming the server destruction!) the user is already making their intent known. It is not necessary to make them confirm two more times.
# File lib/chef/knife/cloud/server/delete_command.rb, line 52 def destroy_item(klass, name, type_name) object = klass.load(name) object.destroy ui.warn("Deleted #{type_name} #{name}") rescue Net::HTTPServerException => e error_message = "#{e.message}. Could not find a #{type_name} named #{name} to delete!" ui.warn(error_message) raise CloudExceptions::ServerDeleteError, error_message end
execute_command()
click to toggle source
# File lib/chef/knife/cloud/server/delete_command.rb, line 29 def execute_command @name_args.each do |server_name| service.delete_server(server_name) delete_from_chef(server_name) end end