Class: Chef::Knife::RackspaceServerDelete
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::RackspaceServerDelete
- Includes:
- RackspaceBase
- Defined in:
- lib/chef/knife/rackspace_server_delete.rb
Instance Method Summary collapse
-
#destroy_item(klass, name, type_name) ⇒ Object
Extracted from Chef::Knife.delete_object, because it has a confirmation step built in…
- #run ⇒ Object
Methods included from RackspaceBase
#auth_endpoint, #connection, #connection_params, included, #ip_address, #locate_config_value, #msg_pair, #public_dns_name, #region_warning_for_v1
Methods inherited from Chef::Knife
Instance Method Details
#destroy_item(klass, name, type_name) ⇒ Object
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.
51 52 53 54 55 56 57 58 59 |
# File 'lib/chef/knife/rackspace_server_delete.rb', line 51 def destroy_item(klass, name, type_name) begin 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 end |
#run ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/chef/knife/rackspace_server_delete.rb', line 61 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) 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 |