class Chef::Knife::RackspaceServerDelete
Public Instance Methods
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/rackspace_server_delete.rb, line 51 def destroy_item(klass, name, type_name) object = klass.load(name) object.destroy ui.warn("Deleted #{type_name} #{name}") rescue Net::HTTPServerException ui.warn("Could not find a #{type_name} named #{name} to delete!") end
run()
click to toggle source
# File lib/chef/knife/rackspace_server_delete.rb, line 59 def run @name_args.each do |instance_id| begin server = connection.servers.get(instance_id) msg_pair("Instance ID", server.id.to_s) msg_pair("Host ID", server.host_id) msg_pair("Name", server.name) msg_pair("Flavor", server.flavor.name) msg_pair("Image", server.image.name) if server.image msg_pair("Boot Image ID", server.boot_image_id) if server.boot_image_id msg_pair("Public IP Address", ip_address(server, "public")) msg_pair("Private IP Address", ip_address(server, "private")) puts "\n" confirm("Do you really want to delete this server") server.destroy ui.warn("Deleted server #{server.id}") if config[:purge] if version_one? thing_to_delete = config[:chef_node_name] || instance_id destroy_item(Chef::Node, thing_to_delete, "node") destroy_item(Chef::ApiClient, thing_to_delete, "client") else # v2 nodes may be named automatically 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") end else ui.warn("Corresponding node and client for the #{instance_id} server were not deleted and remain registered with the Chef Server") end rescue NoMethodError ui.error("Could not locate server '#{instance_id}'.") end end end