Class: Fission::Action::VM::Deleter

Inherits:
Object
  • Object
show all
Defined in:
lib/fission/action/vm/deleter.rb

Instance Method Summary collapse

Constructor Details

#initialize(vm) ⇒ Deleter

Internal: Creates a new VMDeleter object. This accepts a VM object.

vm - An instance of VM

Examples:

Fission::Action::VMDeleter.new @my_vm

Returns a new VMDeleter object



16
17
18
# File 'lib/fission/action/vm/deleter.rb', line 16

def initialize(vm)
  @vm = vm
end

Instance Method Details

#deleteObject

Public: Deletes a VM. The VM must not be running in order to delete it. As there are a number issues with the Fusion command line tool for deleting VMs, this is a best effort. The VM must not be running when this method is called. This essentially deletes the VM directory and attempts to remove the relevant entries from the Fusion plist file. It’s highly recommended to delete VMs without the Fusion GUI running. If the Fusion GUI is running this method should succeed, but it’s been observed that Fusion will recreate the plist data which is deleted. This leads to ‘missing’ VMs in the Fusion GUI.

Examples

@deleter.delete

Returns a Response with the result. If successful, the Response’s data attribute will be nil. If there is an error, an unsuccessful Response will be returned.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fission/action/vm/deleter.rb', line 37

def delete
  unless @vm.exists?
    return Response.new :code => 1, :message => 'VM does not exist'
  end

  running_response = @vm.running?
  return running_response unless running_response.successful?

  if running_response.data
    message = 'The VM must not be running in order to delete it.'
    return Response.new :code => 1, :message => message
  end

  FileUtils.rm_rf @vm.path
  Metadata.delete_vm_info @vm.path

  Response.new :code => 0
end