Class: Chef::Knife::GlesysServerDelete
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::GlesysServerDelete
- Includes:
- GlesysBase
- Defined in:
- lib/chef/knife/glesys_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 GlesysBase
#color_state, #connection, included, #locate_config_value, #msg_pair, #validate!
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.
45 46 47 48 49 50 51 52 53 |
# File 'lib/chef/knife/glesys_server_delete.rb', line 45 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
55 56 57 58 59 60 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 100 101 102 103 104 105 106 |
# File 'lib/chef/knife/glesys_server_delete.rb', line 55 def run @name_args.each do |server_id| server = connection.servers.get(server_id) puts "\n" msg_pair("Server ID", server.serverid) state = case server.state.to_s.downcase when 'shutting-down','terminated','stopping','stopped' then ui.color(server.state, :red) when 'pending' then ui.color(server.state, :yellow) else ui.color(server.state, :green) end msg_pair("State", ui.color(state,:bold)) msg_pair("Hostname", server.hostname) msg_pair("Description", server.description) if server.respond_to? :description # When fog supports description puts "\n" msg_pair("IPv4", server.iplist.select{|i| i["version"] == 4}.collect{|i| i["ipaddress"]}.join(", ")) msg_pair("IPv6", server.iplist.select{|i| i["version"] == 6}.collect{|i| i["ipaddress"]}.join(", ")) puts "\n" msg_pair("CPU Cores", server.cpucores) msg_pair("Memory", "#{server.memorysize} MB") msg_pair("Disk", "#{server.disksize} GB") puts "\n" msg_pair("Template", server.templatename) msg_pair("Platform", server.platform) msg_pair("Datacenter", server.datacenter) puts "\n" msg_pair("Transfer", "#{server.transfer['usage']} of #{server.transfer['max']} #{server.transfer['unit']}") msg_pair("Cost", "#{server.cost['amount']} #{server.cost['currency']} per #{server.cost['timeperiod']}") puts "\n" ui.confirm("Do you wan't to delete this server?") if config[:keepip] server.keepip = config[:keepip] end server.destroy ui.warn("Deleted server #{server_id}") if config[:purge] thing_to_delete = config[:chef_node_name] || server_id 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_id} server were not deleted and remain registered with the Chef Server") end end rescue NoMethodError ui.error("Could not locate server '#{server_id}'.") end |