Class: Chef::Knife::SoftlayerServerDestroy
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::SoftlayerServerDestroy
- Includes:
- SoftlayerBase
- Defined in:
- lib/chef/knife/softlayer_server_destroy.rb
Constant Summary
Constants included from SoftlayerBase
Chef::Knife::SoftlayerBase::USER_AGENT
Instance Attribute Summary collapse
-
#cci ⇒ Object
Returns the value of attribute cci.
-
#node ⇒ Object
Returns the value of attribute node.
Instance Method Summary collapse
- #destroy_item(klass, name, type_name) ⇒ nil
- #err_msg(msg = nil) ⇒ Object
-
#run ⇒ nil
Run the procedure to destroy a SoftLayer VM and clean up its Chef node and client.
Methods included from SoftlayerBase
#compute, #connection, included, #locate_config_value, #msg_pair, #network
Instance Attribute Details
#cci ⇒ Object
Returns the value of attribute cci.
17 18 19 |
# File 'lib/chef/knife/softlayer_server_destroy.rb', line 17 def cci @cci end |
#node ⇒ Object
Returns the value of attribute node.
16 17 18 |
# File 'lib/chef/knife/softlayer_server_destroy.rb', line 16 def node @node end |
Instance Method Details
#destroy_item(klass, name, type_name) ⇒ nil
115 116 117 118 119 120 121 122 123 |
# File 'lib/chef/knife/softlayer_server_destroy.rb', line 115 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 |
#err_msg(msg = nil) ⇒ Object
125 126 127 128 |
# File 'lib/chef/knife/softlayer_server_destroy.rb', line 125 def err_msg(msg=nil) @msgs ||= [] @msgs.push(msg).compact end |
#run ⇒ nil
Run the procedure to destroy a SoftLayer VM and clean up its Chef node and client.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 107 108 109 |
# File 'lib/chef/knife/softlayer_server_destroy.rb', line 36 def run $stdout.sync = true puts ui.color("Decommissioning SoftLayer VM, this may take a few minutes.", :green) @chef = Chef::Search::Query.new if config[:chef_node_name] @chef.search('node', "name:#{config[:chef_node_name]}") do |node| config[:ip_address] = node.ipaddress @node = node end elsif config[:ip_address] @chef.search('node', "ipaddress:#{config[:ip_address]}") do |node| @node = node end elsif arg = name_args[0] if arg =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/ # ipv4 query = "ipaddress:#{arg}" elsif arg =~ /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/ # ipv6 query = "ipaddress:#{arg}" else query = "name:#{arg}" end @chef.search('node', query) do |node| @node = node end else raise "#{ui.color("FATAL: Please supply the node name or IP address.", :red)}" end @slid = @node..select { |s| s =~ /^slid=/ }.reduce.gsub('slid=', '').to_i @instance = connection.servers.get(@slid) @node.nil? and raise "#{ui.color('Chef node not found!', :red)}" @instance.nil? and raise "#{ui.color('VM instance with IP: ' + config[:ip_address] +' not found!', :red)}" begin begin destroy_item(Chef::Node, @node.name, "node") puts ui.color("Chef node successfully deleted.", :green) rescue Exception => e err_msg ui.color("ERROR DELETING CHEF NODE", :red) err_msg ui.color(e., :yellow) err_msg ui.color(e.backtrace, :yellow) end begin destroy_item(Chef::ApiClient, @node.name, "client") puts ui.color("Chef client successfully deleted.", :green) rescue Exception => e err_msg ui.color("ERROR DELETING CHEF CLIENT", :red) err_msg ui.color(e., :yellow) err_msg ui.color(e.backtrace, :yellow) end begin @instance.destroy puts ui.color("SoftLayer VM successfully deleted. You are no longer being billed for this instance.", :green) rescue Exception => e err_msg ui.color("ERROR DELETING SOFTLAYER VM. IT'S POSSIBLE YOU ARE STILL BEING BILLED FOR THIS INSTANCE. PLEASE CONTACT SUPPORT FOR FURTHER ASSISTANCE", :red) err_msg ui.color(e., :yellow) err_msg ui.color(e.backtrace, :yellow) end ensure unless err_msg.empty? err_msg.each do |msg| puts msg end end end end |