Class: Chef::Knife::Cloud::ServerDeleteCommand
- Inherits:
-
Command
- Object
- Chef::Knife
- Command
- Chef::Knife::Cloud::ServerDeleteCommand
- Defined in:
- lib/chef/knife/cloud/server/delete_command.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
- #delete_from_chef(server_name) ⇒ Object
-
#destroy_item(klass, name, type_name) ⇒ Object
Extracted from Chef::Knife.delete_object, because it has a confirmation step built in…
- #execute_command ⇒ Object
Methods inherited from Command
Methods included from Helpers
#after_exec_command, #before_exec_command, #create_service_instance, #locate_config_value, #msg_pair, #pretty_key, #set_default_config, #validate!, #validate_params!
Instance Method Details
#delete_from_chef(server_name) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ 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.
52 53 54 55 56 57 58 59 60 |
# 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 = "#{e.}. Could not find a #{type_name} named #{name} to delete!" ui.warn() raise CloudExceptions::ServerDeleteError, end |
#execute_command ⇒ Object
29 30 31 32 33 34 |
# 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 |