1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

(#9241) Add destroy API request and model action

Without this patch we have no way to completely destroy
a server instance.  This patch adds a vm_destroy API request
and implements the destroy method on the server model.

The vSphere API requires the server to be in a poweredOff state.
The model action and the request do not verify this is the case
before issuing the command.
This commit is contained in:
Jeff McCune 2011-09-06 16:41:37 -07:00
parent cb4e9701b5
commit 4264b1f99c
3 changed files with 34 additions and 0 deletions

View file

@ -18,6 +18,7 @@ module Fog
request :vm_power_off
request :vm_power_on
request :vm_reboot
request :vm_destroy
request :find_all_by_uuid
request :find_all_by_instance_uuid

View file

@ -70,6 +70,11 @@ module Fog
connection.vm_reboot(:instance_uuid => instance_uuid, :force => params[:force])
end
def destroy(params = {})
requires :instance_uuid
connection.vm_destroy(:instance_uuid => instance_uuid)
end
end
end

View file

@ -0,0 +1,28 @@
module Fog
module Compute
class Vsphere
class Real
def vm_destroy(params = {})
raise ArgumentError ":instance_uuid is a required parameter" unless params.has_key? :instance_uuid
vm = find_all_by_instance_uuid(params[:instance_uuid]).first
unless vm.kind_of? RbVmomi::VIM::VirtualMachine
raise Fog::Vsphere::Errors::NotFound, "Could not find VirtualMachine with instance uuid #{params[:instance_uuid]}"
end
task = vm.Destroy_Task
task.wait_for_completion
task.info.state
end
end
class Mock
def vm_destroy(params = {})
"success"
end
end
end
end
end