Skip to content

Commit f8370a5

Browse files
committed
Merge pull request #100 from isoutham/master
Expunge destroyed server
2 parents 13a2dee + eb1fd53 commit f8370a5

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

lib/chef/knife/cs_server_delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def run
5858
if result
5959
print "#{ui.color("Waiting for deletion", :magenta)}"
6060
disassociate_virtual_ip_address server
61-
connection.delete_server hostname
61+
connection.delete_server(hostname, false)
6262
puts "\n"
6363
ui.msg("Deleted server #{hostname}")
6464

lib/chef/knife/cs_server_list.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ class CsServerList < Chef::Knife
4545
:short => "-a ACTION",
4646
:long => "--action ACTION",
4747
:description => "start, stop or destroy the instances in your result"
48-
48+
49+
option :expunge,
50+
:long => "--expunge",
51+
:description => "If used with --action destroy, will cause the server to be expunged"
4952
option :public_ip,
5053
:long => "--[no-]public-ip",
5154
:description => "Show or don't show the public IP for server in your result",
@@ -70,7 +73,9 @@ def run
7073
params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
7174
params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
7275
params['name'] = locate_config_value(:name) if locate_config_value(:name)
73-
76+
params['expunge'] = locate_config_value(:expunge) if locate_config_value(:expunge)
77+
params['expunge'] = false if params['expunge'].nil?
78+
7479
##
7580
# Get the public IP address if possible, except when the option --no-public-ip is given.
7681

@@ -89,7 +94,7 @@ def run
8994
# Executing actions against the list results that are returned.
9095

9196
if locate_config_value(:action)
92-
connection_result.each do |r|
97+
result.each do |r|
9398
hostname = r['name']
9499
case locate_config_value(:action).downcase
95100
when "start" then
@@ -115,7 +120,7 @@ def run
115120
result = confirm_action("Do you really want to destroy this server ")
116121
if result then
117122
print "#{ui.color("Waiting for demolition", :magenta)}"
118-
connection.delete_server(hostname)
123+
connection.delete_server(hostname, params['expunge'])
119124
puts "\n"
120125
ui.msg("Destroyed server #{hostname}")
121126
end

lib/chef/knife/cs_stack_delete.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def delete_stack(stack)
7070
def delete_server(server_name)
7171
cmd = KnifeCloudstack::CsServerDelete.new([server_name])
7272
cmd.config[:yes] = true
73+
cmd.config[:expunge] = true
7374
cmd.run_with_pretty_exceptions
7475
end
7576

lib/knife-cloudstack/connection.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def create_server(host_name, service_name, template_name, disk_name=nil, zone_na
264264
# Deletes the server with the specified name.
265265
#
266266

267-
def delete_server(name)
267+
def delete_server(name, expunge)
268268
server = get_server(name)
269269
if !server || !server['id'] then
270270
puts "\nError: Virtual machine '#{name}' does not exist"
@@ -273,7 +273,8 @@ def delete_server(name)
273273

274274
params = {
275275
'command' => 'destroyVirtualMachine',
276-
'id' => server['id']
276+
'id' => server['id'],
277+
'expunge' => expunge
277278
}
278279

279280
json = send_async_request(params)

0 commit comments

Comments
 (0)