Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/chef/knife/softlayer_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class SoftlayerServerCreate < Knife

option :use_private_network,
:long => '--use-private-network',
:description => 'Flag to be passwed when bootstrap is preferred over the private network.',
:description => 'Flag to be passed when bootstrap is preferred over the private network.',
:boolean => true

option :from_file,
Expand Down Expand Up @@ -454,5 +454,3 @@ def apply_tags(instance)
end
end
end


50 changes: 37 additions & 13 deletions lib/chef/knife/softlayer_server_destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class SoftlayerServerDestroy < Knife
:short => "-I",
:description => "Find the VM and node to destroy by its public IP address."

option :use_private_network,
:long => '--use-private-network',
:description => 'Look for private IP',
:boolean => true

##
# Run the procedure to destroy a SoftLayer VM and clean up its Chef node and client.
# @return [nil]
Expand All @@ -40,47 +45,68 @@ def run
puts ui.color("Decommissioning SoftLayer VM, this may take a few minutes.", :green)
connection.servers.each do |server|
if config[:ip_address]
if server.public_ip_address == config[:ip_address]
if server.public_ip_address == config[:ip_address] || server.private_ip_address == config[:ip_address]
@instance = server
break
end
elsif config[:chef_node_name]
if server.name == config[:chef_node_name]
config[:ip_address] = server.public_ip_address
if server.fqdn == config[:chef_node_name]
config[:ip_address] = if config[:use_private_network]
server.private_ip_address
else
server.public_ip_address
end
@instance = server
break
end
elsif arg = name_args[0]
if arg =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/ # ipv4
if server.public_ip_address == arg
if server.public_ip_address == arg || server.private_ip_address == arg
@instance = server
break
end
elsif arg =~ /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/ # ipv6
if server.public_ip_address == arg
if server.public_ip_address == arg || server.private_ip_address == arg
@instance = server
break
end
else
if server.name == arg
config[:ip_address] = server.public_ip_address
if server.fqdn == arg
config[:ip_address] = if config[:use_private_network]
server.private_ip_address
else
server.public_ip_address
end
@instance = server
break
end
end
end
end
end
@instance.nil? and raise "#{ui.color('VM instance with IP: ' + (config[:ip_address].to_s) +' not found!', :red)}"
@chef = Chef::Search::Query.new
@chef.search('node', "name:#{@instance.name}") do |node|
@chef.search('node', "name:#{@instance.fqdn}") do |node|
begin
@node = node
rescue
end
end

begin
if @node
puts "#{ui.color("ID:", :green)} #{@instance.id}"
puts "#{ui.color("Name:", :green)} #{@instance.fqdn}"
puts "#{ui.color("CPU:", :green)} #{@instance.cpu}"
puts "#{ui.color("RAM:", :green)} #{@instance.ram}"
puts "#{ui.color("Datacenter:", :green)} #{@instance.datacenter}"
puts "#{ui.color("Public IP:", :green)} #{@instance.public_ip_address}"
puts "#{ui.color("Public Speed:", :green)} #{@instance.network_components[0].speed}"
puts "#{ui.color("Private IP:", :green)} #{@instance.private_ip_address}"
puts "#{ui.color("Private Speed:", :green)} #{@instance.network_components[1].speed}"
puts "#{ui.color("Status:", :green)} #{@instance.state}"
puts "\n"
confirm("Do you really want to destroy this server")

if !@node.nil?
begin
destroy_item(Chef::Node, @node.name, "node")
puts ui.color("Chef node successfully deleted.", :green)
Expand All @@ -99,7 +125,7 @@ def run
err_msg ui.color(e.backtrace.join("\n"), :yellow)
end
else
"#{ui.color('Chef node: ' + config[:chef_node_name] +' not found! will destroy instance.', :red)}"
"#{ui.color("Chef node: #{config[:chef_node_name]} not found! will destroy instance.", :red)}"
end

begin
Expand Down Expand Up @@ -142,5 +168,3 @@ def err_msg(msg=nil)
end
end
end