Class: Fission::Action::VM::Cloner

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

Instance Method Summary collapse

Constructor Details

#initialize(source_vm, target_vm) ⇒ Cloner

Internal: Creates a new VMCloner object. This accepts a source and target VM object.

source_vm - An instance of VM target_vm - An instance of VM

Examples:

Fission::Action::VMCloner.new @my_source_vm, @my_target_vm

Returns a new VMCloner object.



18
19
20
21
# File 'lib/fission/action/vm/cloner.rb', line 18

def initialize(source_vm, target_vm)
  @source_vm = source_vm
  @target_vm = target_vm
end

Instance Method Details

#cloneObject

Public: Creates a new VM which is a clone of an existing VM. As Fusion doesn’t provide a native cloning mechanism, this is a best effort. This essentially is a directory copy with updates to relevant files. It’s recommended to clone VMs which are not running.

Examples

@cloner.clone

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.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fission/action/vm/cloner.rb', line 35

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

  if @target_vm.exists?
    return Response.new :code => 1, :message => 'VM already exists'
  end

  FileUtils.cp_r @source_vm.path, @target_vm.path

  rename_vm_files @source_vm.name, @target_vm.name
  update_config @source_vm.name, @target_vm.name

  Response.new :code => 0
end